ATLAS Offline Software
Loading...
Searching...
No Matches
TrackRecordAnalysis.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// Section of includes for TrackRecord tests
9#include "CLHEP/Vector/LorentzVector.h"
11
12
14 ATH_MSG_DEBUG( "Initializing TrackRecordAnalysis" );
15
16 std::string detName ="CaloEntry";
17 std::string ntupName = "TrackRecordCaloEntry";
18 ATH_CHECK(m_readKey.initialize());
19 if (m_readKey.key() == "CaloEntryLayer") {
20 detName="CaloEntry";
21 ntupName="TrackRecordCaloEntry";
22 }
23 else if (m_readKey.key( )== "MuonEntryLayer") {
24 detName="MuonEntry";
25 ntupName="TrackRecordMuonEntry";
26 }
27 else if (m_readKey.key() == "MuonExitLayer") {
28 detName="MuonExit";
29 ntupName="TrackRecordMuonExit";
30 }
31 else {
32 ATH_MSG_ERROR("TrackRecordAnalysis for "<< name() << "not supported !!! \n");
33 return StatusCode::FAILURE;
34 }
35
36
37 float x_down = -5000;
38 float x_up = 5000;
39 float radius = 4500;
40 float eta_down = -5.8;
41 float eta_up = 5.8;
42 float z_down = -7000;
43 float z_up = 7000;
44 if (detName == "CaloEntry") {
45 x_down = -1180;
46 x_up = 1180;
47 radius = 1200;
48 eta_down = - 5.6;
49 eta_up = 5.6;
50 z_down = -3700;
51 z_up = 3700;
52 }
53
55 m_h_hits_x = new TH1D((detName+"_x").c_str(),"hits_x", 100,x_down, x_up);
56 m_h_hits_x->StatOverflows();
57 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_x->GetName(), m_h_hits_x));
58
59 m_h_hits_y = new TH1D((detName+"_y").c_str(), "hits_y", 100,x_down,x_up);
60 m_h_hits_y->StatOverflows();
61 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_y->GetName(), m_h_hits_y));
62
63 m_h_hits_z = new TH1D((detName+"_z").c_str(), "hits_z", 100,z_down,z_up);
64 m_h_hits_z->StatOverflows();
65 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_z->GetName(), m_h_hits_z));
66
67 m_h_hits_r = new TH1D((detName+"_r").c_str(), "hits_r", 100,0,radius);
68 m_h_hits_r->StatOverflows();
69 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_r->GetName(), m_h_hits_r));
70
71 m_h_xy = new TH2D((detName+"_xy").c_str(), "xy", 100,x_down,x_up,100, x_down, x_up);
72 m_h_xy->StatOverflows();
73 ATH_CHECK(histSvc()->regHist( m_path+m_h_xy->GetName(), m_h_xy));
74
75 m_h_zr = new TH2D((detName+"_zr").c_str(), "zr", 100,z_down,z_up,100, 0., radius);
76 m_h_zr->StatOverflows();
77 ATH_CHECK(histSvc()->regHist( m_path+m_h_zr->GetName(), m_h_zr));
78
79 m_h_hits_eta = new TH1D((detName+"_eta").c_str(), "hits_eta", 100,eta_down,eta_up);
80 m_h_hits_eta->StatOverflows();
81 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_eta->GetName(), m_h_hits_eta));
82
83 m_h_hits_phi = new TH1D((detName+"_phi").c_str(), "hits_phi", 100,-3.1416,3.1416);
84 m_h_hits_phi->StatOverflows();
85 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_phi->GetName(), m_h_hits_phi));
86
87 m_h_hits_px = new TH1D((detName+"_px").c_str(),"Px", 100, -1500, 1500);
88 m_h_hits_px->StatOverflows();
89 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_px->GetName(), m_h_hits_px));
90
91 m_h_hits_py = new TH1D((detName+"_py").c_str(), "Py", 100,-1500,1500);
92 m_h_hits_py->StatOverflows();
93 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_py->GetName(), m_h_hits_py));
94
95 m_h_hits_pz = new TH1D((detName+"_pz").c_str(), "Pz", 100,-1500,1500);
96 m_h_hits_pz->StatOverflows();
97 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_pz->GetName(), m_h_hits_pz));
98
99 m_h_hits_pt = new TH1D((detName+"_pt").c_str(), "hits_pt", 100,0,2500);
100 m_h_hits_pt->StatOverflows();
101 ATH_CHECK(histSvc()->regHist(m_path + m_h_hits_pt->GetName(), m_h_hits_pt));
102
103 m_h_time = new TH1D((detName+"_time").c_str(),"time", 100,0, 250);
104 m_h_time->StatOverflows();
105 ATH_CHECK(histSvc()->regHist(m_path + m_h_time->GetName(), m_h_time));
106
107 m_h_edep = new TH1D((detName+"_edep").c_str(), "energy", 100,0,7500);
108 m_h_edep->StatOverflows();
109 ATH_CHECK(histSvc()->regHist(m_path + m_h_edep->GetName(), m_h_edep));
110
111 m_h_pdg = new TH1D((detName+"_pdg").c_str(), "pdg", 100,-1000,1000);
112 m_h_pdg->StatOverflows();
113 ATH_CHECK(histSvc()->regHist(m_path + m_h_pdg->GetName(), m_h_pdg));
114
116 m_tree = new TTree(ntupName.c_str(), ntupName.c_str());
117 std::string fullNtupleName = "/" + m_ntupleFileName + "/" + detName;
118 ATH_CHECK(histSvc()->regTree(fullNtupleName,m_tree));
119
120 m_tree->Branch("x", &m_x);
121 m_tree->Branch("y", &m_y);
122 m_tree->Branch("z", &m_z);
123 m_tree->Branch("r", &m_r);
124 m_tree->Branch("eta", &m_eta);
125 m_tree->Branch("phi", &m_phi);
126 m_tree->Branch("px", &m_px);
127 m_tree->Branch("py", &m_py);
128 m_tree->Branch("pz", &m_pz);
129 m_tree->Branch("pt", &m_pt);
130 m_tree->Branch("time", &m_time);
131 m_tree->Branch("energy", &m_edep);
132 m_tree->Branch("pdg", &m_pdg);
133
134 return StatusCode::SUCCESS;
135}
136
137
139 ATH_MSG_DEBUG( "In TrackRecordAnalysis::execute()" );
140
141 m_x->clear();
142 m_y->clear();
143 m_z->clear();
144 m_r->clear();
145 m_eta->clear();
146 m_phi->clear();
147 m_px->clear();
148 m_py->clear();
149 m_pz->clear();
150 m_pt->clear();
151 m_time->clear();
152 m_edep->clear();
153 m_pdg->clear();
154
155 const EventContext& ctx{Gaudi::Hive::currentContext()};
156 const TrackRecordCollection* TRcoll{nullptr};
157 ATH_CHECK(SG::get(TRcoll,m_readKey ,ctx));
158 for (TrackRecordCollection::const_iterator track = TRcoll->begin(); track != TRcoll->end(); ++track) {
159 //TrackRecordCollection::const_iterator track;
160 //for(auto track : *TRcoll){
161 //std::cout<<"Entra en el loop"<<std::endl;
162
163 CLHEP::Hep3Vector p =(*track).GetPosition();
164 m_h_hits_x->Fill(p.x());
165 m_h_hits_y->Fill(p.y());
166 m_h_hits_z->Fill(p.z());
167 m_h_hits_r->Fill(p.perp());
168 m_h_xy->Fill(p.x(), p.y());
169 m_h_zr->Fill(p.z(),p.perp());
170 m_h_hits_eta->Fill(p.eta());
171 m_h_hits_phi->Fill(p.phi());
172
173 CLHEP::Hep3Vector mom = (*track).GetMomentum();
174 m_h_hits_px->Fill(mom.x());
175 m_h_hits_py->Fill(mom.y());
176 m_h_hits_pz->Fill(mom.z());
177 m_h_hits_pt->Fill(mom.perp());
178 m_h_edep->Fill((*track).GetEnergy());
179 m_h_time->Fill((*track).GetTime());
180 m_h_pdg->Fill((*track).GetPDGCode());
181
182 m_x->push_back(p.x());
183 m_y->push_back(p.y());
184 m_z->push_back(p.z());
185 m_r->push_back(p.perp());
186 m_eta->push_back(p.eta());
187 m_phi->push_back(p.phi());
188 m_px->push_back(mom.x());
189 m_py->push_back(mom.y());
190 m_pz->push_back(mom.z());
191 m_pt->push_back(mom.perp());
192 m_edep->push_back((*track).GetEnergy());
193 m_time->push_back((*track).GetTime());
194 m_pdg->push_back((*track).GetPDGCode());
195 } // End while hits
196
197 m_tree->Fill();
198
199 return StatusCode::SUCCESS;
200}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
AtlasHitsVector< TrackRecord > TrackRecordCollection
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
CONT::const_iterator const_iterator
const_iterator begin() const
const_iterator end() const
Gaudi::Property< std::string > m_path
std::vector< float > * m_pdg
std::vector< float > * m_edep
std::vector< float > * m_y
Gaudi::Property< std::string > m_ntupleFileName
std::vector< float > * m_x
std::vector< float > * m_pt
std::vector< float > * m_px
std::vector< float > * m_time
TH1 * m_h_hits_x
Some variables.
std::vector< float > * m_eta
std::vector< float > * m_r
SG::ReadHandleKey< TrackRecordCollection > m_readKey
virtual StatusCode execute() override
std::vector< float > * m_z
std::vector< float > * m_py
virtual StatusCode initialize() override
std::vector< float > * m_phi
std::vector< float > * m_pz
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.