ATLAS Offline Software
TGCHitAnalysis.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 "TGCHitAnalysis.h"
6 
7 // Section of includes for TGC of the Muon Spectrometer tests
9 
11 #include "MuonSimEvent/TGCSimHit.h"
12 #include "CLHEP/Vector/LorentzVector.h"
13 
14 #include "TH1.h"
15 #include "TTree.h"
16 #include "TString.h"
17 
18 #include <algorithm>
19 #include <math.h>
20 #include <functional>
21 #include <iostream>
22 #include <stdio.h>
23 
24 TGCHitAnalysis::TGCHitAnalysis(const std::string& name, ISvcLocator* pSvcLocator)
25  : AthAlgorithm(name, pSvcLocator)
26  , m_h_hits_x(0)
27  , m_h_hits_y(0)
28  , m_h_hits_z(0)
29  , m_h_hits_r(0)
30  , m_h_xy(0)
31  , m_h_rz(0)
32  , m_h_hits_eta(0)
33  , m_h_hits_phi(0)
34  , m_h_hits_lx(0)
35  , m_h_hits_ly(0)
36  , m_h_hits_lz(0)
37  , m_h_hits_dcx(0)
38  , m_h_hits_dcy(0)
39  , m_h_hits_dcz(0)
40  , m_h_hits_time(0)
41  , m_h_hits_edep(0)
42  , m_h_hits_kine(0)
43  , m_h_hits_step(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)
50  , m_hits_lx(0)
51  , m_hits_ly(0)
52  , m_hits_lz(0)
53  , m_hits_dcx(0)
54  , m_hits_dcy(0)
55  , m_hits_dcz(0)
56  , m_hits_time(0)
57  , m_hits_edep(0)
58  , m_hits_kine(0)
59  , m_hits_step(0)
60 
61  , m_tree(0)
62  , m_ntupleFileName("/TGCHitAnalysis/")
63  , m_path("/TGCHitAnalysis/")
64  , m_thistSvc("THistSvc", name)
65 {
66  declareProperty("NtupleFileName", m_ntupleFileName);
67  declareProperty("HistPath", m_path);
68 }
69 
71  ATH_MSG_DEBUG( "Initializing TGCHitAnalysis" );
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_hits_tgc_x","hits_x", 100,-5000, 5000);
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_hits_tgc_y", "hits_y", 100,-5000,5000);
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_hits_tgc_z", "hits_z", 100,-12000,12000);
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_hits_tgc_r", "hits_r", 100,2000,10000);
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_tgc_xy", "xy", 100,-5000.,5000.,100, -5000., 5000.);
94  m_h_xy->StatOverflows();
95  CHECK(m_thistSvc->regHist( m_path+m_h_xy->GetName(), m_h_xy));
96 
97  m_h_rz = new TH2D("h_tgc_rz", "rz", 100,2000.,10000.,100, -12000., 12000.);
98  m_h_rz->StatOverflows();
99  CHECK(m_thistSvc->regHist( m_path+m_h_rz->GetName(), m_h_rz));
100 
101  m_h_hits_eta = new TH1D("h_hits_tgc_eta", "hits_eta", 100,-10.0,10.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_hits_tgc_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_lx = new TH1D("h_hits_tgc_lx","hits_lx", 100,-800, 800);
110  m_h_hits_lx->StatOverflows();
111  CHECK(m_thistSvc->regHist(m_path + m_h_hits_lx->GetName(), m_h_hits_lx));
112 
113  m_h_hits_ly = new TH1D("h_hits_tgc_ly", "hits_ly", 100,-800,800);
114  m_h_hits_ly->StatOverflows();
115  CHECK(m_thistSvc->regHist(m_path + m_h_hits_ly->GetName(), m_h_hits_ly));
116 
117  m_h_hits_lz = new TH1D("h_hits_tgc_lz", "hits_lz", 100,-800,800);
118  m_h_hits_lz->StatOverflows();
119  CHECK(m_thistSvc->regHist(m_path + m_h_hits_lz->GetName(), m_h_hits_lz));
120 
121  m_h_hits_dcx = new TH1D("h_hits_tgc_dcx","hits_dcx", 100,-1, 1);
122  m_h_hits_dcx->StatOverflows();
123  CHECK(m_thistSvc->regHist(m_path + m_h_hits_dcx->GetName(), m_h_hits_dcx));
124 
125  m_h_hits_dcy = new TH1D("h_hits_tgc_dcy", "hits_dcy", 100,-1,1);
126  m_h_hits_dcy->StatOverflows();
127  CHECK(m_thistSvc->regHist(m_path + m_h_hits_dcy->GetName(), m_h_hits_dcy));
128 
129  m_h_hits_dcz = new TH1D("h_hits_tgc_dcz", "hits_dcz", 100,-1,1);
130  m_h_hits_dcz->StatOverflows();
131  CHECK(m_thistSvc->regHist(m_path + m_h_hits_dcz->GetName(), m_h_hits_dcz));
132 
133  m_h_hits_time = new TH1D("h_hits_tgc_time","hits_time", 100,0, 250);
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_hits_tgc_edep", "hits_edep", 100,0,0.5);
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_hits_tgc_kine", "hits_kine", 100,0,1000);
142  m_h_hits_kine->StatOverflows();
143  CHECK(m_thistSvc->regHist(m_path + m_h_hits_kine->GetName(), m_h_hits_kine));
144 
145  m_h_hits_step = new TH1D("h_hits_tgc_step", "hits_step", 100,0,50);
146  m_h_hits_step->StatOverflows();
147  CHECK(m_thistSvc->regHist(m_path + m_h_hits_step->GetName(), m_h_hits_step));
148 
150  m_tree = new TTree("TGC", "TGC");
151  std::string fullNtupleName = "/" + m_ntupleFileName + "/";
152  CHECK(m_thistSvc->regTree(fullNtupleName,m_tree));
153 
154  if (m_tree) {
155  m_tree->Branch("x", &m_hits_x);
156  m_tree->Branch("y", &m_hits_y);
157  m_tree->Branch("z", &m_hits_z);
158  m_tree->Branch("r", &m_hits_r);
159  m_tree->Branch("eta", &m_hits_eta);
160  m_tree->Branch("phi", &m_hits_phi);
161  m_tree->Branch("lx", &m_hits_lx);
162  m_tree->Branch("ly", &m_hits_ly);
163  m_tree->Branch("lz", &m_hits_lz);
164  m_tree->Branch("dcx", &m_hits_dcx);
165  m_tree->Branch("dcy", &m_hits_dcy);
166  m_tree->Branch("dcz", &m_hits_dcz);
167  m_tree->Branch("time", &m_hits_time);
168  m_tree->Branch("edep", &m_hits_edep);
169  m_tree->Branch("kine", &m_hits_kine);
170  m_tree->Branch("step", &m_hits_step);
171  }
172  else {
173  ATH_MSG_ERROR("No tree found!");
174  }
175 
176  return StatusCode::SUCCESS;
177 }
178 
179 
181  ATH_MSG_DEBUG( "In TGCHitAnalysis::execute()" );
182 
183  m_hits_x->clear();
184  m_hits_y->clear();
185  m_hits_z->clear();
186  m_hits_r->clear();
187  m_hits_eta->clear();
188  m_hits_phi->clear();
189  m_hits_lx->clear();
190  m_hits_ly->clear();
191  m_hits_lz->clear();
192  m_hits_dcx->clear();
193  m_hits_dcy->clear();
194  m_hits_dcz->clear();
195  m_hits_time->clear();
196  m_hits_edep->clear();
197  m_hits_kine->clear();
198  m_hits_step->clear();
199 
200  const TGCSimHitCollection* tgc_container;
201  if (evtStore()->retrieve(tgc_container, "TGC_Hits" ) == StatusCode::SUCCESS) {
202  for (TGCSimHitCollection::const_iterator i_hit = tgc_container->begin(); i_hit != tgc_container->end(); ++i_hit) {
203  //TGCSimHitCollection::const_iterator i_hit;
204  //for(auto i_hit : *tgc_container){
205  GeoTGCHit ghit(*i_hit);
206  if (!ghit) continue;
207 
209  m_h_hits_x->Fill(p.x());
210  m_h_hits_y->Fill(p.y());
211  m_h_hits_z->Fill(p.z());
212  m_h_hits_r->Fill(p.perp());
213  m_h_xy->Fill(p.x(), p.y());
214  m_h_rz->Fill(p.perp(), p.z());
215  m_h_hits_eta->Fill(p.eta());
216  m_h_hits_phi->Fill(p.phi());
217  m_h_hits_lx->Fill((*i_hit).localPosition().x());
218  m_h_hits_ly->Fill((*i_hit).localPosition().y());
219  m_h_hits_lz->Fill((*i_hit).localPosition().z());
220  m_h_hits_dcx->Fill((*i_hit).localDireCos().x());
221  m_h_hits_dcy->Fill((*i_hit).localDireCos().y());
222  m_h_hits_dcz->Fill((*i_hit).localDireCos().z());
223  m_h_hits_edep->Fill((*i_hit).energyDeposit());
224  m_h_hits_time->Fill((*i_hit).globalTime());
225  m_h_hits_step->Fill((*i_hit).stepLength());
226  m_h_hits_kine->Fill((*i_hit).kineticEnergy());
227 
228  m_hits_x->push_back(p.x());
229  m_hits_y->push_back(p.y());
230  m_hits_z->push_back(p.z());
231  m_hits_r->push_back(p.perp());
232  m_hits_eta->push_back(p.eta());
233  m_hits_phi->push_back(p.phi());
234  m_hits_lx->push_back((*i_hit).localPosition().x());
235  m_hits_ly->push_back((*i_hit).localPosition().y());
236  m_hits_lz->push_back((*i_hit).localPosition().z());
237  m_hits_dcx->push_back((*i_hit).localDireCos().x());
238  m_hits_dcy->push_back((*i_hit).localDireCos().y());
239  m_hits_dcz->push_back((*i_hit).localDireCos().z());
240  m_hits_edep->push_back((*i_hit).energyDeposit());
241  m_hits_time->push_back((*i_hit).globalTime());
242  m_hits_step->push_back((*i_hit).stepLength());
243  m_hits_kine->push_back((*i_hit).kineticEnergy());
244  }
245  } // End while hits
246 
247  if (m_tree) m_tree->Fill();
248 
249  return StatusCode::SUCCESS;
250 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TGCHitAnalysis::m_hits_y
std::vector< float > * m_hits_y
Definition: TGCHitAnalysis.h:57
TH2::Fill
int Fill(double, double)
Definition: rootspy.cxx:382
TGCHitAnalysis::m_h_xy
TH2 * m_h_xy
Definition: TGCHitAnalysis.h:41
TGCHitAnalysis::execute
virtual StatusCode execute() override
Definition: TGCHitAnalysis.cxx:180
TGCHitAnalysis::m_h_hits_y
TH1 * m_h_hits_y
Definition: TGCHitAnalysis.h:38
TGCHitAnalysis::m_ntupleFileName
std::string m_ntupleFileName
Definition: TGCHitAnalysis.h:74
GeoTGCHit::getGlobalPosition
Amg::Vector3D getGlobalPosition() const
TGCHitAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: TGCHitAnalysis.h:76
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TGCHitAnalysis::m_h_rz
TH2 * m_h_rz
Definition: TGCHitAnalysis.h:42
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TGCHitAnalysis::m_h_hits_z
TH1 * m_h_hits_z
Definition: TGCHitAnalysis.h:39
TGCHitAnalysis::m_tree
TTree * m_tree
Definition: TGCHitAnalysis.h:73
AtlasHitsVector
Definition: AtlasHitsVector.h:33
TH1D
Definition: rootspy.cxx:342
TGCHitAnalysis::m_h_hits_dcy
TH1 * m_h_hits_dcy
Definition: TGCHitAnalysis.h:49
GeoMuonHits.h
TGCHitAnalysis::TGCHitAnalysis
TGCHitAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TGCHitAnalysis.cxx:24
AtlasHitsVector::begin
const_iterator begin() const
Definition: AtlasHitsVector.h:131
TGCHitAnalysis::m_hits_kine
std::vector< float > * m_hits_kine
Definition: TGCHitAnalysis.h:70
AtlasHitsVector::const_iterator
CONT::const_iterator const_iterator
Definition: AtlasHitsVector.h:43
TGCHitAnalysis::m_path
std::string m_path
Definition: TGCHitAnalysis.h:75
TGCHitAnalysis::m_h_hits_kine
TH1 * m_h_hits_kine
Definition: TGCHitAnalysis.h:53
TGCHitAnalysis.h
TGCHitAnalysis::m_h_hits_phi
TH1 * m_h_hits_phi
Definition: TGCHitAnalysis.h:44
TGCHitAnalysis::m_h_hits_lz
TH1 * m_h_hits_lz
Definition: TGCHitAnalysis.h:47
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TGCHitAnalysis::m_h_hits_time
TH1 * m_h_hits_time
Definition: TGCHitAnalysis.h:51
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
GeoTGCHit
Definition: GeoMuonHits.h:106
TGCHitAnalysis::m_h_hits_step
TH1 * m_h_hits_step
Definition: TGCHitAnalysis.h:54
TGCHitAnalysis::m_h_hits_edep
TH1 * m_h_hits_edep
Definition: TGCHitAnalysis.h:52
TGCHitAnalysis::m_h_hits_dcx
TH1 * m_h_hits_dcx
Definition: TGCHitAnalysis.h:48
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TGCHitAnalysis::m_hits_dcy
std::vector< float > * m_hits_dcy
Definition: TGCHitAnalysis.h:66
TGCHitAnalysis::m_h_hits_lx
TH1 * m_h_hits_lx
Definition: TGCHitAnalysis.h:45
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
TGCHitAnalysis::m_hits_time
std::vector< float > * m_hits_time
Definition: TGCHitAnalysis.h:68
TGCHitAnalysis::m_hits_phi
std::vector< float > * m_hits_phi
Definition: TGCHitAnalysis.h:61
TGCHitAnalysis::m_h_hits_dcz
TH1 * m_h_hits_dcz
Definition: TGCHitAnalysis.h:50
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TGCHitAnalysis::m_hits_ly
std::vector< float > * m_hits_ly
Definition: TGCHitAnalysis.h:63
TH2D
Definition: rootspy.cxx:430
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
AthAlgorithm
Definition: AthAlgorithm.h:47
TGCHitAnalysis::m_hits_dcz
std::vector< float > * m_hits_dcz
Definition: TGCHitAnalysis.h:67
TGCHitAnalysis::m_hits_dcx
std::vector< float > * m_hits_dcx
Definition: TGCHitAnalysis.h:65
TGCHitAnalysis::m_h_hits_x
TH1 * m_h_hits_x
Some variables.
Definition: TGCHitAnalysis.h:37
TGCHitAnalysis::m_hits_step
std::vector< float > * m_hits_step
Definition: TGCHitAnalysis.h:71
TGCHitAnalysis::m_hits_eta
std::vector< float > * m_hits_eta
Definition: TGCHitAnalysis.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TGCHitAnalysis::m_hits_z
std::vector< float > * m_hits_z
Definition: TGCHitAnalysis.h:58
TGCHitAnalysis::m_h_hits_r
TH1 * m_h_hits_r
Definition: TGCHitAnalysis.h:40
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TGCSimHitCollection.h
TGCHitAnalysis::m_hits_r
std::vector< float > * m_hits_r
Definition: TGCHitAnalysis.h:59
TGCHitAnalysis::m_hits_x
std::vector< float > * m_hits_x
Definition: TGCHitAnalysis.h:56
TGCHitAnalysis::m_hits_lz
std::vector< float > * m_hits_lz
Definition: TGCHitAnalysis.h:64
TGCHitAnalysis::m_hits_lx
std::vector< float > * m_hits_lx
Definition: TGCHitAnalysis.h:62
AtlasHitsVector::end
const_iterator end() const
Definition: AtlasHitsVector.h:134
TGCHitAnalysis::m_hits_edep
std::vector< float > * m_hits_edep
Definition: TGCHitAnalysis.h:69
TGCSimHit.h
TGCHitAnalysis::m_h_hits_ly
TH1 * m_h_hits_ly
Definition: TGCHitAnalysis.h:46
TGCHitAnalysis::initialize
virtual StatusCode initialize() override
Definition: TGCHitAnalysis.cxx:70
TGCHitAnalysis::m_h_hits_eta
TH1 * m_h_hits_eta
Definition: TGCHitAnalysis.h:43