ATLAS Offline Software
RPCHitAnalysis.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 "RPCHitAnalysis.h"
6 
7 // Section of includes for the RPC of the Muon Spectrometer tests
9 
11 #include "MuonSimEvent/RPCSimHit.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 RPCHitAnalysis::RPCHitAnalysis(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_zr(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_time(0)
38  , m_h_hits_edep(0)
39  , m_h_hits_kine(0)
40  , m_h_hits_step(0)
41  , m_hits_x(0)
42  , m_hits_y(0)
43  , m_hits_z(0)
44  , m_hits_r(0)
45  , m_hits_eta(0)
46  , m_hits_phi(0)
47  , m_hits_lx(0)
48  , m_hits_ly(0)
49  , m_hits_lz(0)
50  , m_hits_time(0)
51  , m_hits_edep(0)
52  , m_hits_kine(0)
53  , m_hits_step(0)
54 
55  , m_tree(0)
56  , m_ntupleFileName("/RPCHitAnalysis/")
57  , m_path("/RPCHitAnalysis/")
58  , m_thistSvc("THistSvc", name)
59 {
60  declareProperty("NtupleFileName", m_ntupleFileName);
61  declareProperty("HistPath", m_path);
62 }
63 
64 
66  ATH_MSG_DEBUG( "Initializing RPCHitAnalysis" );
67 
68  // Grab the Ntuple and histogramming service for the tree
69  CHECK(m_thistSvc.retrieve());
70 
72  m_h_hits_x = new TH1D("h_hits_rpc_x","hits_x", 100,-11000, 11000);
73  m_h_hits_x->StatOverflows();
74  CHECK(m_thistSvc->regHist(m_path + m_h_hits_x->GetName(), m_h_hits_x));
75 
76  m_h_hits_y = new TH1D("h_hits_rpc_y", "hits_y", 100,-11000,11000);
77  m_h_hits_y->StatOverflows();
78  CHECK(m_thistSvc->regHist(m_path + m_h_hits_y->GetName(), m_h_hits_y));
79 
80  m_h_hits_z = new TH1D("h_hits_rpc_z", "hits_z", 100,-12500, 12500);
81  m_h_hits_z->StatOverflows();
82  CHECK(m_thistSvc->regHist(m_path + m_h_hits_z->GetName(), m_h_hits_z));
83 
84  m_h_hits_r = new TH1D("h_hits_rpc_r", "hits_r", 100,6000,14000);
85  m_h_hits_r->StatOverflows();
86  CHECK(m_thistSvc->regHist(m_path + m_h_hits_r->GetName(), m_h_hits_r));
87 
88  m_h_xy = new TH2D("h_rpc_xy", "xy", 100,-11000.,11000.,100, -11000., 11000.);
89  m_h_xy->StatOverflows();
90  CHECK(m_thistSvc->regHist( m_path+m_h_xy->GetName(), m_h_xy));
91 
92  m_h_zr = new TH2D("m_rpc_zr", "zr", 100,-12500.,12500.,100, 6000., 14000.);
93  m_h_zr->StatOverflows();
94  CHECK(m_thistSvc->regHist( m_path+m_h_zr->GetName(), m_h_zr));
95 
96  m_h_hits_eta = new TH1D("h_hits_rpc_eta", "hits_eta", 100,-1.5,1.5);
97  m_h_hits_eta->StatOverflows();
98  CHECK(m_thistSvc->regHist(m_path + m_h_hits_eta->GetName(), m_h_hits_eta));
99 
100  m_h_hits_phi = new TH1D("h_hits_rpc_phi", "hits_phi", 100,-3.2,3.2);
101  m_h_hits_phi->StatOverflows();
102  CHECK(m_thistSvc->regHist(m_path + m_h_hits_phi->GetName(), m_h_hits_phi));
103 
104  m_h_hits_lx = new TH1D("h_hits_rpc_lx","hits_lx", 100,-10, 10);
105  m_h_hits_lx->StatOverflows();
106  CHECK(m_thistSvc->regHist(m_path + m_h_hits_lx->GetName(), m_h_hits_lx));
107 
108  m_h_hits_ly = new TH1D("h_hits_rpc_ly", "hits_ly", 100,-1500,1500);
109  m_h_hits_ly->StatOverflows();
110  CHECK(m_thistSvc->regHist(m_path + m_h_hits_ly->GetName(), m_h_hits_ly));
111 
112  m_h_hits_lz = new TH1D("h_hits_rpc_lz", "hits_lz", 100,-600,600);
113  m_h_hits_lz->StatOverflows();
114  CHECK(m_thistSvc->regHist(m_path + m_h_hits_lz->GetName(), m_h_hits_lz));
115 
116  m_h_hits_time = new TH1D("h_hits_rpc_time","hits_time", 100,0, 120);
117  m_h_hits_time->StatOverflows();
118  CHECK(m_thistSvc->regHist(m_path + m_h_hits_time->GetName(), m_h_hits_time));
119 
120  m_h_hits_edep = new TH1D("h_hits_rpc_edep", "hits_edep", 100,0,0.15);
121  m_h_hits_edep->StatOverflows();
122  CHECK(m_thistSvc->regHist(m_path + m_h_hits_edep->GetName(), m_h_hits_edep));
123 
124  m_h_hits_kine = new TH1D("h_hits_rpc_kine", "hits_kine", 100,0,500);
125  m_h_hits_kine->StatOverflows();
126  CHECK(m_thistSvc->regHist(m_path + m_h_hits_kine->GetName(), m_h_hits_kine));
127 
128  m_h_hits_step = new TH1D("h_hits_rpc_step", "hits_step", 100,0,25);
129  m_h_hits_step->StatOverflows();
130  CHECK(m_thistSvc->regHist(m_path + m_h_hits_step->GetName(), m_h_hits_step));
131 
133  m_tree = new TTree("RPC","RPC");
134  std::string fullNtupleName = "/" + m_ntupleFileName + "/";
135  CHECK(m_thistSvc->regTree(fullNtupleName,m_tree));
136 
137  if (m_tree){
138  m_tree->Branch("x", &m_hits_x);
139  m_tree->Branch("y", &m_hits_y);
140  m_tree->Branch("z", &m_hits_z);
141  m_tree->Branch("r", &m_hits_r);
142  m_tree->Branch("eta", &m_hits_eta);
143  m_tree->Branch("phi", &m_hits_phi);
144  m_tree->Branch("lx", &m_hits_lx);
145  m_tree->Branch("ly", &m_hits_ly);
146  m_tree->Branch("lz", &m_hits_lz);
147  m_tree->Branch("time", &m_hits_time);
148  m_tree->Branch("edep", &m_hits_edep);
149  m_tree->Branch("kine", &m_hits_kine);
150  m_tree->Branch("step", &m_hits_step);
151  }
152  else {
153  ATH_MSG_ERROR("No tree found!");
154  }
155 
156  return StatusCode::SUCCESS;
157 }
158 
159 
161  ATH_MSG_DEBUG( "In RPCHitAnalysis::execute()" );
162 
163  m_hits_x->clear();
164  m_hits_y->clear();
165  m_hits_z->clear();
166  m_hits_r->clear();
167  m_hits_eta->clear();
168  m_hits_phi->clear();
169  m_hits_lx->clear();
170  m_hits_ly->clear();
171  m_hits_lz->clear();
172  m_hits_time->clear();
173  m_hits_edep->clear();
174  m_hits_kine->clear();
175  m_hits_step->clear();
176 
177  const RPCSimHitCollection* rpc_container;
178  if (evtStore()->retrieve(rpc_container, "RPC_Hits") == StatusCode::SUCCESS) {
179  for (RPCSimHitCollection::const_iterator i_hit = rpc_container->begin(); i_hit != rpc_container->end(); ++i_hit) {
180  //RPCSimHitCollection::const_iterator i_hit;
181  //for(auto i_hit : *rpc_container){
182  GeoRPCHit ghit(*i_hit);
183  if (!ghit) continue;
184 
186  m_h_hits_x->Fill(p.x());
187  m_h_hits_y->Fill(p.y());
188  m_h_hits_z->Fill(p.z());
189  m_h_hits_r->Fill(p.perp());
190  m_h_xy->Fill(p.x(), p.y());
191  m_h_zr->Fill(p.z(),p.perp());
192  m_h_hits_eta->Fill(p.eta());
193  m_h_hits_phi->Fill(p.phi());
194  m_h_hits_lx->Fill((*i_hit).localPosition().x());
195  m_h_hits_ly->Fill((*i_hit).localPosition().y());
196  m_h_hits_lz->Fill((*i_hit).localPosition().z());
197  m_h_hits_edep->Fill((*i_hit).energyDeposit());
198  m_h_hits_time->Fill((*i_hit).globalTime());
199  m_h_hits_step->Fill((*i_hit).stepLength());
200  m_h_hits_kine->Fill((*i_hit).kineticEnergy());
201 
202  m_hits_x->push_back(p.x());
203  m_hits_y->push_back(p.y());
204  m_hits_z->push_back(p.z());
205  m_hits_r->push_back(p.perp());
206  m_hits_eta->push_back(p.eta());
207  m_hits_phi->push_back(p.phi());
208  m_hits_lx->push_back((*i_hit).localPosition().x());
209  m_hits_ly->push_back((*i_hit).localPosition().y());
210  m_hits_lz->push_back((*i_hit).localPosition().z());
211  m_hits_edep->push_back((*i_hit).energyDeposit());
212  m_hits_time->push_back((*i_hit).globalTime());
213  m_hits_step->push_back((*i_hit).stepLength());
214  m_hits_kine->push_back((*i_hit).kineticEnergy());
215  }
216  } // End while hits
217 
218  if (m_tree) m_tree->Fill();
219 
220  return StatusCode::SUCCESS;
221 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
RPCHitAnalysis::m_h_hits_r
TH1 * m_h_hits_r
Definition: RPCHitAnalysis.h:40
TH2::Fill
int Fill(double, double)
Definition: rootspy.cxx:382
RPCHitAnalysis.h
RPCHitAnalysis::m_hits_lz
std::vector< float > * m_hits_lz
Definition: RPCHitAnalysis.h:61
RPCHitAnalysis::m_hits_ly
std::vector< float > * m_hits_ly
Definition: RPCHitAnalysis.h:60
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
RPCHitAnalysis::m_hits_edep
std::vector< float > * m_hits_edep
Definition: RPCHitAnalysis.h:63
RPCHitAnalysis::initialize
virtual StatusCode initialize()
Definition: RPCHitAnalysis.cxx:65
RPCHitAnalysis::RPCHitAnalysis
RPCHitAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RPCHitAnalysis.cxx:24
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GeoRPCHit::getGlobalPosition
Amg::Vector3D getGlobalPosition() const
AtlasHitsVector
Definition: AtlasHitsVector.h:33
RPCHitAnalysis::m_hits_step
std::vector< float > * m_hits_step
Definition: RPCHitAnalysis.h:65
RPCHitAnalysis::m_hits_y
std::vector< float > * m_hits_y
Definition: RPCHitAnalysis.h:54
TH1D
Definition: rootspy.cxx:342
GeoMuonHits.h
RPCHitAnalysis::m_h_hits_z
TH1 * m_h_hits_z
Definition: RPCHitAnalysis.h:39
RPCHitAnalysis::m_hits_r
std::vector< float > * m_hits_r
Definition: RPCHitAnalysis.h:56
AtlasHitsVector::begin
const_iterator begin() const
Definition: AtlasHitsVector.h:131
RPCHitAnalysis::m_hits_time
std::vector< float > * m_hits_time
Definition: RPCHitAnalysis.h:62
AtlasHitsVector::const_iterator
CONT::const_iterator const_iterator
Definition: AtlasHitsVector.h:43
RPCHitAnalysis::execute
virtual StatusCode execute()
Definition: RPCHitAnalysis.cxx:160
RPCHitAnalysis::m_h_hits_step
TH1 * m_h_hits_step
Definition: RPCHitAnalysis.h:51
RPCHitAnalysis::m_h_hits_lz
TH1 * m_h_hits_lz
Definition: RPCHitAnalysis.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
RPCHitAnalysis::m_hits_lx
std::vector< float > * m_hits_lx
Definition: RPCHitAnalysis.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
RPCHitAnalysis::m_h_hits_phi
TH1 * m_h_hits_phi
Definition: RPCHitAnalysis.h:44
RPCHitAnalysis::m_path
std::string m_path
Definition: RPCHitAnalysis.h:69
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
RPCHitAnalysis::m_ntupleFileName
std::string m_ntupleFileName
Definition: RPCHitAnalysis.h:68
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
RPCHitAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: RPCHitAnalysis.h:70
RPCHitAnalysis::m_h_zr
TH2 * m_h_zr
Definition: RPCHitAnalysis.h:42
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TH2D
Definition: rootspy.cxx:430
RPCSimHitCollection.h
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
RPCHitAnalysis::m_h_hits_edep
TH1 * m_h_hits_edep
Definition: RPCHitAnalysis.h:49
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
RPCHitAnalysis::m_h_xy
TH2 * m_h_xy
Definition: RPCHitAnalysis.h:41
RPCHitAnalysis::m_h_hits_x
TH1 * m_h_hits_x
Some variables.
Definition: RPCHitAnalysis.h:37
RPCHitAnalysis::m_h_hits_lx
TH1 * m_h_hits_lx
Definition: RPCHitAnalysis.h:45
AtlasHitsVector::end
const_iterator end() const
Definition: AtlasHitsVector.h:134
RPCHitAnalysis::m_h_hits_y
TH1 * m_h_hits_y
Definition: RPCHitAnalysis.h:38
RPCSimHit.h
RPCHitAnalysis::m_h_hits_eta
TH1 * m_h_hits_eta
Definition: RPCHitAnalysis.h:43
RPCHitAnalysis::m_h_hits_time
TH1 * m_h_hits_time
Definition: RPCHitAnalysis.h:48
RPCHitAnalysis::m_hits_phi
std::vector< float > * m_hits_phi
Definition: RPCHitAnalysis.h:58
RPCHitAnalysis::m_hits_z
std::vector< float > * m_hits_z
Definition: RPCHitAnalysis.h:55
RPCHitAnalysis::m_hits_x
std::vector< float > * m_hits_x
Definition: RPCHitAnalysis.h:53
GeoRPCHit
Definition: GeoMuonHits.h:85
RPCHitAnalysis::m_h_hits_ly
TH1 * m_h_hits_ly
Definition: RPCHitAnalysis.h:46
RPCHitAnalysis::m_hits_kine
std::vector< float > * m_hits_kine
Definition: RPCHitAnalysis.h:64
RPCHitAnalysis::m_tree
TTree * m_tree
Definition: RPCHitAnalysis.h:67
RPCHitAnalysis::m_h_hits_kine
TH1 * m_h_hits_kine
Definition: RPCHitAnalysis.h:50
RPCHitAnalysis::m_hits_eta
std::vector< float > * m_hits_eta
Definition: RPCHitAnalysis.h:57