ATLAS Offline Software
Loading...
Searching...
No Matches
CSCHitAnalysis.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "CSCHitAnalysis.h"
6
7// Section of includes for CSC of the Muon Spectrometer tests
9
12#include "CLHEP/Vector/LorentzVector.h"
13
14#include "TH1.h"
15#include "TH2.h"
16#include "TTree.h"
17#include "TString.h"
18
19#include <algorithm>
20#include <math.h>
21#include <functional>
22#include <iostream>
23#include <stdio.h>
24
25CSCHitAnalysis::CSCHitAnalysis(const std::string& name, ISvcLocator* pSvcLocator)
26 : AthAlgorithm(name, pSvcLocator)
27 , m_h_hits_x(0)
28 , m_h_hits_y(0)
29 , m_h_hits_z(0)
30 , m_h_hits_r(0)
31 , m_h_xy(0)
32 , m_h_zr(0)
33 , m_h_hits_eta(0)
34 , m_h_hits_phi(0)
35 , m_h_hits_sx(0)
36 , m_h_hits_sy(0)
37 , m_h_hits_sz(0)
38 , m_h_hits_ex(0)
39 , m_h_hits_ey(0)
40 , m_h_hits_ez(0)
41 , m_h_hits_time(0)
42 , m_h_hits_edep(0)
43 , m_h_hits_kine(0)
44 , m_hits_x(0)
45 , m_hits_y(0)
46 , m_hits_z(0)
47 , m_hits_r(0)
48 , m_hits_eta(0)
49 , m_hits_phi(0)
53 , m_hits_end_x(0)
54 , m_hits_end_y(0)
55 , m_hits_end_z(0)
56 , m_hits_time(0)
57 , m_hits_edep(0)
58 , m_hits_kine(0)
59
60 , m_tree(0)
61 , m_ntupleFileName("/CSCHitAnalysis/")
62 , m_path("/CSCHitAnalysis/")
63 , m_thistSvc("THistSvc", name)
64{
65 declareProperty("NtupleFileName", m_ntupleFileName);
66 declareProperty("HistPath", m_path);
67}
68
69
71 ATH_MSG_DEBUG( "Initializing CSCHitAnalysis" );
72
73 // Grab the Ntuple and histogramming service for the tree
74 CHECK(m_thistSvc.retrieve());
75
77 m_h_hits_x = new TH1D("h_csc_hits_x","hits_x", 100,-2000, 2000);
78 m_h_hits_x->StatOverflows();
79 CHECK(m_thistSvc->regHist(m_path + m_h_hits_x->GetName(), m_h_hits_x));
80
81 m_h_hits_y = new TH1D("h_csc_hits_y", "hits_y", 100,-2000,2000);
82 m_h_hits_y->StatOverflows();
83 CHECK(m_thistSvc->regHist(m_path + m_h_hits_y->GetName(), m_h_hits_y));
84
85 m_h_hits_z = new TH1D("h_csc_hits_z", "hits_z", 100,-10000,10000);
86 m_h_hits_z->StatOverflows();
87 CHECK(m_thistSvc->regHist(m_path + m_h_hits_z->GetName(), m_h_hits_z));
88
89 m_h_hits_r = new TH1D("h_csc_hits_r", "hits_r", 100,500,2500);
90 m_h_hits_r->StatOverflows();
91 CHECK(m_thistSvc->regHist(m_path + m_h_hits_r->GetName(), m_h_hits_r));
92
93 m_h_xy = new TH2D("h_csc_xy", "xy", 100,-2000.,2000.,100, -2000., 2000.);
94 m_h_xy->StatOverflows();
95 CHECK(m_thistSvc->regHist( m_path+m_h_xy->GetName(), m_h_xy));
96
97 m_h_zr = new TH2D("h_csc_zr", "zr", 100,-10000.,10000.,100, 500., 2500.);
98 m_h_zr->StatOverflows();
99 CHECK(m_thistSvc->regHist( m_path+m_h_zr->GetName(), m_h_zr));
100
101 m_h_hits_eta = new TH1D("h_csc_hits_eta", "hits_eta", 100,-3.0,3.0);
102 m_h_hits_eta->StatOverflows();
103 CHECK(m_thistSvc->regHist(m_path + m_h_hits_eta->GetName(), m_h_hits_eta));
104
105 m_h_hits_phi = new TH1D("h_csc_hits_phi", "hits_phi", 100,-3.2,3.2);
106 m_h_hits_phi->StatOverflows();
107 CHECK(m_thistSvc->regHist(m_path + m_h_hits_phi->GetName(), m_h_hits_phi));
108
109 m_h_hits_sx = new TH1D("h_csc_hits_sx","hits_sx", 100,-10, 10);
110 m_h_hits_sx->StatOverflows();
111 CHECK(m_thistSvc->regHist(m_path + m_h_hits_sx->GetName(), m_h_hits_sx));
112
113 m_h_hits_sy = new TH1D("h_csc_hits_sy", "hits_sy", 100,-500,500);
114 m_h_hits_sy->StatOverflows();
115 CHECK(m_thistSvc->regHist(m_path + m_h_hits_sy->GetName(), m_h_hits_sy));
116
117 m_h_hits_sz = new TH1D("h_csc_hits_sz", "hits_sz", 100,-1000,1000);
118 m_h_hits_sz->StatOverflows();
119 CHECK(m_thistSvc->regHist(m_path + m_h_hits_sz->GetName(), m_h_hits_sz));
120
121 m_h_hits_ex = new TH1D("h_csc_hits_ex","hits_ex", 100,-10, 10);
122 m_h_hits_ex->StatOverflows();
123 CHECK(m_thistSvc->regHist(m_path + m_h_hits_ex->GetName(), m_h_hits_ex));
124
125 m_h_hits_ey = new TH1D("h_csc_hits_ey", "hits_ey", 100,-500,500);
126 m_h_hits_ey->StatOverflows();
127 CHECK(m_thistSvc->regHist(m_path + m_h_hits_ey->GetName(), m_h_hits_ey));
128
129 m_h_hits_ez = new TH1D("h_csc_hits_ez", "hits_ez", 100,-1000,1000);
130 m_h_hits_ez->StatOverflows();
131 CHECK(m_thistSvc->regHist(m_path + m_h_hits_ez->GetName(), m_h_hits_ez));
132
133 m_h_hits_time = new TH1D("h_csc_hits_time","hits_time", 100,20, 40);
134 m_h_hits_time->StatOverflows();
135 CHECK(m_thistSvc->regHist(m_path + m_h_hits_time->GetName(), m_h_hits_time));
136
137 m_h_hits_edep = new TH1D("h_csc_hits_edep", "hits_edep", 100,0,0.1);
138 m_h_hits_edep->StatOverflows();
139 CHECK(m_thistSvc->regHist(m_path + m_h_hits_edep->GetName(), m_h_hits_edep));
140
141 m_h_hits_kine = new TH1D("h_csc_hits_kine", "hits_kine", 100,0,3000);
142 m_h_hits_kine->StatOverflows();
143 CHECK(m_thistSvc->regHist(m_path + m_h_hits_kine->GetName(), m_h_hits_kine));
144
146 m_tree = new TTree("CSC", "CSC");
147 std::string fullNtupleName = "/" + m_ntupleFileName + "/";
148 CHECK(m_thistSvc->regTree(fullNtupleName, m_tree));
149
150 if (m_tree){
151 m_tree->Branch("x", &m_hits_x);
152 m_tree->Branch("y", &m_hits_y);
153 m_tree->Branch("z", &m_hits_z);
154 m_tree->Branch("r", &m_hits_r);
155 m_tree->Branch("eta", &m_hits_eta);
156 m_tree->Branch("phi", &m_hits_phi);
157 m_tree->Branch("startX", &m_hits_start_x);
158 m_tree->Branch("startY", &m_hits_start_y);
159 m_tree->Branch("startZ", &m_hits_start_z);
160 m_tree->Branch("endX", &m_hits_end_x);
161 m_tree->Branch("endY", &m_hits_end_y);
162 m_tree->Branch("endZ", &m_hits_end_z);
163 m_tree->Branch("time", &m_hits_time);
164 m_tree->Branch("edep", &m_hits_edep);
165 m_tree->Branch("kine", &m_hits_kine);
166 }
167 else {
168 ATH_MSG_ERROR("No tree found!");
169 }
170
171 return StatusCode::SUCCESS;
172}
173
174
176 ATH_MSG_DEBUG( "In CSCHitAnalysis::execute()" );
177
178 m_hits_x->clear();
179 m_hits_y->clear();
180 m_hits_z->clear();
181 m_hits_r->clear();
182 m_hits_eta->clear();
183 m_hits_phi->clear();
184 m_hits_start_x->clear();
185 m_hits_start_y->clear();
186 m_hits_start_z->clear();
187 m_hits_end_x->clear();
188 m_hits_end_y->clear();
189 m_hits_end_z->clear();
190 m_hits_time->clear();
191 m_hits_edep->clear();
192 m_hits_kine->clear();
193
194 const CSCSimHitCollection* csc_container;
195 if (evtStore()->retrieve(csc_container, "CSC_Hits") == StatusCode::SUCCESS) {
196 for (CSCSimHitCollection::const_iterator i_hit = csc_container->begin();
197 i_hit != csc_container->end(); ++i_hit) {
198 //CSCSimHitCollection::const_iterator i_hit;
199 //for(auto i_hit : *csc_container){
200 GeoCSCHit ghit(*i_hit);
201 if (!ghit) continue;
202
204 m_h_hits_x->Fill(p.x());
205 m_h_hits_y->Fill(p.y());
206 m_h_hits_z->Fill(p.z());
207 m_h_hits_r->Fill(p.perp());
208 m_h_xy->Fill(p.x(), p.y());
209 m_h_zr->Fill(p.z(), p.perp());
210 m_h_hits_eta->Fill(p.eta());
211 m_h_hits_phi->Fill(p.phi());
212 m_h_hits_sx->Fill((*i_hit).getHitStart().x());
213 m_h_hits_sy->Fill((*i_hit).getHitStart().y());
214 m_h_hits_sz->Fill((*i_hit).getHitStart().z());
215 m_h_hits_ex->Fill((*i_hit).getHitEnd().x());
216 m_h_hits_ey->Fill((*i_hit).getHitEnd().y());
217 m_h_hits_ez->Fill((*i_hit).getHitEnd().z());
218 m_h_hits_edep->Fill((*i_hit).energyDeposit());
219 m_h_hits_time->Fill((*i_hit).globalTime());
220 m_h_hits_kine->Fill((*i_hit).kineticEnergy());
221
222 m_hits_x->push_back(p.x());
223 m_hits_y->push_back(p.y());
224 m_hits_z->push_back(p.z());
225 m_hits_r->push_back(p.perp());
226 m_hits_eta->push_back(p.eta());
227 m_hits_phi->push_back(p.phi());
228 m_hits_start_x->push_back((*i_hit).getHitStart().x());
229 m_hits_start_y->push_back((*i_hit).getHitStart().y());
230 m_hits_start_z->push_back((*i_hit).getHitStart().z());
231 m_hits_end_x->push_back((*i_hit).getHitEnd().x());
232 m_hits_end_y->push_back((*i_hit).getHitEnd().y());
233 m_hits_end_z->push_back((*i_hit).getHitEnd().z());
234 m_hits_edep->push_back((*i_hit).energyDeposit());
235 m_hits_time->push_back((*i_hit).globalTime());
236 m_hits_kine->push_back((*i_hit).kineticEnergy());
237 }
238 } // End while hits
239
240 if (m_tree) m_tree->Fill();
241
242 return StatusCode::SUCCESS;
243
244}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
AtlasHitsVector< CSCSimHit > CSCSimHitCollection
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
CONT::const_iterator const_iterator
const_iterator begin() const
const_iterator end() const
std::vector< float > * m_hits_end_y
std::vector< float > * m_hits_end_z
std::vector< float > * m_hits_phi
std::vector< float > * m_hits_start_y
std::vector< float > * m_hits_eta
std::vector< float > * m_hits_x
std::vector< float > * m_hits_end_x
std::vector< float > * m_hits_y
std::vector< float > * m_hits_edep
virtual StatusCode initialize()
std::vector< float > * m_hits_r
TH1 * m_h_hits_x
Some variables.
std::string m_path
std::vector< float > * m_hits_kine
std::vector< float > * m_hits_start_x
ServiceHandle< ITHistSvc > m_thistSvc
std::vector< float > * m_hits_start_z
virtual StatusCode execute()
std::vector< float > * m_hits_z
std::vector< float > * m_hits_time
std::string m_ntupleFileName
CSCHitAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Amg::Vector3D getGlobalPosition() const
Eigen::Matrix< double, 3, 1 > Vector3D