ATLAS Offline Software
Loading...
Searching...
No Matches
CaloHitAnalysis.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Base class
6#include "CaloHitAnalysis.h"
7
8// Section of includes for LAr calo tests
9#include "CaloDetDescr/CaloDetDescrElement.h"
11
12// Section of includes for tile calo tests
16
17//Section of includes for Calibrated Calo hits
19
20#include "TString.h"
21#include "TH1.h"
22#include "TH2.h"
23#include "TTree.h"
24
25#include <algorithm>
26#include <math.h>
27#include <functional>
28#include <iostream>
29
30
31
33 ATH_MSG_DEBUG( "Initializing CaloHitAnalysis" );
34 if (m_useTile) {
35
36 ATH_CHECK( detStore()->retrieve(m_tileMgr) );
37 ATH_CHECK( detStore()->retrieve(m_tileID) );
38 }
39 ATH_CHECK(m_tileKey.initialize(m_useTile));
40 ATH_CHECK(m_caloMgrKey.initialize());
41 ATH_CHECK(m_caloKeys.initialize(m_useLAr));
43
44
45 m_h_cell_e = new TH1D("h_Calo_cell_e", "cell_e", 100,0.,500.);
46 m_h_cell_e->StatOverflows();
47 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_e->GetName(), m_h_cell_e));
48
49 m_h_cell_eta = new TH1D("h_Calo_cell_eta", "cell_eta", 50,-5.,5.);
50 m_h_cell_eta->StatOverflows();
51 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_eta->GetName(), m_h_cell_eta));
52
53 m_h_cell_phi = new TH1D("h_Calo_cell_phi", "cell_phi", 50,-3.1416,3.1416);
54 m_h_cell_phi->StatOverflows();
55 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_phi->GetName(), m_h_cell_phi));
56
57 m_h_cell_radius = new TH1D("h_Calo_cell_radius", "cell_radius", 100, 0., 6000.);
58 m_h_cell_radius->StatOverflows();
59 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_radius->GetName(), m_h_cell_radius));
60
61 m_h_cell_layer = new TH1D("h_Calo_cell_layer", "cell_layer", 24, -0.5, 23.5);
62 m_h_cell_layer->StatOverflows();
63 CHECK(histSvc()->regHist( m_path+m_h_cell_layer->GetName(), m_h_cell_layer));
64
65 m_h_cell_eta_Eweight = new TH1D("h_Calo_cell_eta_Eweight", "cell_eta_Eweight", 50,-5.,5.);
66 m_h_cell_eta_Eweight->StatOverflows();
68
69 m_h_cell_phi_Eweight = new TH1D("h_Calo_cell_phi_Eweight", "cell_phi_Eweight", 50,-3.1416,3.1416);
70 m_h_cell_phi_Eweight->StatOverflows();
72
73 m_h_cell_radius_Eweight = new TH1D("h_Calo_cell_radius_Eweight", "cell_radius_Eweight", 100, 0., 6000.);
74 m_h_cell_radius_Eweight->StatOverflows();
76
77 m_h_cell_layer_Eweight = new TH1D("h_Calo_cell_layer_Eweight", "cell_layer_Eweight", 24, -0.5, 23.5);
78 m_h_cell_layer_Eweight->StatOverflows();
80
81 m_h_xy = new TH2F("h_Calo_xy", "xy", 100,-4000,4000,100, -4000, 4000);
82 m_h_xy->StatOverflows();
83 ATH_CHECK(histSvc()->regHist( m_path+m_h_xy->GetName(), m_h_xy));
84
85 m_h_zr = new TH2D("h_Calo_zr", "zr", 100,-7000.,7000.,100, 0., 6000.);
86 m_h_zr->StatOverflows();
87 ATH_CHECK(histSvc()->regHist( m_path+m_h_zr->GetName(), m_h_zr));
88
89 m_h_etaphi = new TH2D("h_Calo_etaphi", "eta_phi", 50,-5.,5.,50, -3.1416, 3.1416);
90 m_h_etaphi->StatOverflows();
91 ATH_CHECK(histSvc()->regHist( m_path+m_h_etaphi->GetName(), m_h_etaphi));
92
93 //These histograms will be filled only if expert mode is set on
94 m_h_time_e = new TH2D("h_Calo_time_e", "energy vs time", 100, 0,50, 100,0,500);
95 m_h_time_e->StatOverflows();
96
97 m_h_eta_e = new TH2D("h_Calo_eta_e", "energy vs eta", 50, -5,5, 100,0,500);
98 m_h_eta_e->StatOverflows();
99
100 m_h_phi_e = new TH2D("h_Calo_phi_e", "energy vs phi", 50, -3.1416,3.1416, 100,0,500);
101 m_h_phi_e->StatOverflows();
102
103 m_h_r_e = new TH2D("h_Calo_r_e", "energy vs radius", 100, 0,6000, 100,0,500);
104 m_h_r_e->StatOverflows();
105
106 if (m_expert) {
107 ATH_CHECK(histSvc()->regHist(m_path + m_h_time_e->GetName(), m_h_time_e));
108 ATH_CHECK(histSvc()->regHist(m_path + m_h_eta_e->GetName(), m_h_eta_e));
109 ATH_CHECK(histSvc()->regHist(m_path + m_h_phi_e->GetName(), m_h_phi_e));
110 ATH_CHECK(histSvc()->regHist(m_path + m_h_r_e->GetName(), m_h_r_e));
111 }
112
113 //Histograms for calibrated hits
114 m_h_calib_eta = new TH1D("h_calib_eta", "calib. hits eta", 50,-5,5);
115 m_h_calib_eta->StatOverflows();
116
117 m_h_calib_phi = new TH1D("h_calib_phi", "calib. hits phi", 50,-3.1416,3.1416);
118 m_h_calib_phi->StatOverflows();
119
120 m_h_calib_zr = new TH2D("h_calib_zr", "calib. hits z vs r", 100,-7000,7000,1000, 0,6000);
121 m_h_calib_zr->StatOverflows();
122
123 m_h_calib_etaphi = new TH2D("h_calib_etaphi", "calib. hits eta vs phi",50,-5.,5., 50,-3.1416,3.1416);
124 m_h_calib_etaphi->StatOverflows();
125
126 m_h_calib_eEM = new TH1D("h_calib_eEM", "calib. hits EM energy", 100,0,100);
127 m_h_calib_eEM->StatOverflows();
128
129 m_h_calib_eNonEM = new TH1D("h_calib_nonEM", "calib. hits non EM energy", 100,0,100);
130 m_h_calib_eNonEM->StatOverflows();
131
132 m_h_calib_eInv = new TH1D("h_calib_eInv", "calib. hits invisible energy", 100,0,100);
133 m_h_calib_eInv->StatOverflows();
134
135 m_h_calib_eEsc = new TH1D("h_calib_eEsc", "calib. hits escaped energy", 100,0,100);
136 m_h_calib_eEsc->StatOverflows();
137
138 m_h_calib_eTot = new TH1D("h_calib_eTot", "calib. hits energy", 100,0,100);
139 m_h_calib_eTot->StatOverflows();
140
141 m_h_calib_eTotpartID = new TH1D("h_calib_eTotpartID", "calib. hits partID weighted with energy",600,0,300000);
142 m_h_calib_eTotpartID->StatOverflows();
143
144 if (m_calib) {
145 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eta->GetName(), m_h_calib_eta));
146 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_phi->GetName(), m_h_calib_phi));
147 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_zr->GetName(), m_h_calib_zr));
148 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_etaphi->GetName(), m_h_calib_etaphi));
149 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eEM->GetName(), m_h_calib_eEM));
150 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eNonEM->GetName(), m_h_calib_eNonEM));
151 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eInv->GetName(), m_h_calib_eInv));
152 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eEsc->GetName(), m_h_calib_eEsc));
153 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eTot->GetName(), m_h_calib_eTot));
155 }
156
158 m_tree = new TTree("Calo", "Calo");
159 std::string fullNtupleName = "/" + m_ntupleFileName + "/";
160 ATH_CHECK( histSvc()->regTree(fullNtupleName, m_tree) );
161
162 m_tree->Branch("CellEta", &m_cell_eta);
163 m_tree->Branch("CellPhi", &m_cell_phi);
164 m_tree->Branch("CellX", &m_cell_x);
165 m_tree->Branch("CellY", &m_cell_y);
166 m_tree->Branch("CellZ", &m_cell_z);
167 m_tree->Branch("CellE", &m_cell_e);
168 m_tree->Branch("CellRadius", &m_cell_radius);
169 m_tree->Branch("CellLayer", &m_cell_layer);
170 m_tree->Branch("Time", &m_time);
171 m_tree->Branch("CalibEta", &m_calib_eta);
172 m_tree->Branch("CalibPhi", &m_calib_phi);
173 m_tree->Branch("CalibRadius", &m_calib_radius);
174 m_tree->Branch("CalibZ", &m_calib_z);
175 m_tree->Branch("Calib_eEM", &m_calib_eEM);
176 m_tree->Branch("Calib_eNonEM", &m_calib_eNonEM);
177 m_tree->Branch("Calib_eInv", &m_calib_eInv);
178 m_tree->Branch("Calib_eEsc", &m_calib_eEsc);
179 m_tree->Branch("Calib_eTot", &m_calib_eTot);
180 m_tree->Branch("Calib_partID", &m_calib_partID);
181
182 return StatusCode::SUCCESS;
183}
184
185
187 ATH_MSG_DEBUG( "In CaloHitAnalysis::execute()" );
188
189 m_cell_eta->clear();
190 m_cell_phi->clear();
191 m_cell_e->clear();
192 m_cell_x->clear();
193 m_cell_y->clear();
194 m_cell_z->clear();
195 m_cell_radius->clear();
196 m_cell_layer->clear();
197 m_time->clear();
198 m_calib_eta->clear();
199 m_calib_phi->clear();
200 m_calib_radius->clear();
201 m_calib_z->clear();
202 m_calib_eEM->clear();
203 m_calib_eNonEM->clear();
204 m_calib_eInv->clear();
205 m_calib_eEsc->clear();
206 m_calib_eTot->clear();
207 m_calib_partID->clear();
208
209 const EventContext& ctx{Gaudi::Hive::currentContext()};
210 const TileHitVector* hitVec{nullptr};
211 ATH_CHECK(SG::get(hitVec, m_tileKey, ctx));
212
213 if (hitVec) {
214 for (const auto& i_hit : *hitVec) {
215 Identifier pmt_id = (i_hit).identify();
216 Identifier cell_id = m_tileID->cell_id(pmt_id);
217 const CaloDetDescrElement* ddElement = (m_tileID->is_tile_aux(cell_id)) ? 0 : m_tileMgr->get_cell_element(cell_id);
218 if (ddElement) {
219 double tot_e = 0.;
220 double tot_time = 0.;
221 for (int t=0; t<(i_hit).size(); ++t) tot_e += (i_hit).energy(t);
222 for (int t=0; t<(i_hit).size(); ++t) tot_time += (i_hit).time(t);
223 m_h_cell_e->Fill(tot_e);
224 m_h_cell_eta->Fill(ddElement->eta());
225 m_h_cell_phi->Fill(ddElement->phi()) ;
226 m_h_cell_radius->Fill(ddElement->r());
227 m_h_cell_layer->Fill(ddElement->getSampling());
228 m_h_cell_eta_Eweight->Fill(ddElement->eta(),tot_e);
229 m_h_cell_phi_Eweight->Fill(ddElement->phi(),tot_e) ;
230 m_h_cell_radius_Eweight->Fill(ddElement->r(),tot_e);
231 m_h_cell_layer_Eweight->Fill(ddElement->getSampling(),tot_e);
232 m_h_xy->Fill(ddElement->x(), ddElement->y());
233 m_h_zr->Fill(ddElement->z(), ddElement->r());
234 m_h_etaphi->Fill(ddElement->eta(), ddElement->phi());
235
236 if (m_expert) {
237 m_h_time_e->Fill(tot_time, tot_e);
238 m_h_eta_e->Fill(ddElement->eta(), tot_e);
239 m_h_phi_e->Fill(ddElement->phi(), tot_e);
240 m_h_r_e->Fill(ddElement->r(), tot_e);
241 }
242 m_cell_eta->push_back(ddElement->eta());
243 m_cell_phi->push_back(ddElement->phi());
244 m_cell_e->push_back(tot_e);
245 m_cell_x->push_back(ddElement->x());
246 m_cell_y->push_back(ddElement->y());
247 m_cell_z->push_back(ddElement->z());
248 m_cell_radius->push_back(ddElement->r());
249 m_cell_layer->push_back(ddElement->getSampling());
250 m_time->push_back(tot_time);
251 }
252 }
253 } // DoTile
254
255 if (m_useLAr) {
256
257 const CaloDetDescrManager* caloMgr{nullptr};
258 ATH_CHECK(SG::get(caloMgr, m_caloMgrKey, ctx));
259
260 for (const auto& key : m_caloKeys) {
261 const LArHitContainer* iter{nullptr};
262 ATH_CHECK(SG::get(iter, key, ctx));
263 for (auto hi : *iter ) {
264 const CaloDetDescrElement *hitElement = caloMgr->get_element(hi->cellID());
265 double energy = hi->energy();
266 double time = hi->time();
267 double eta = hitElement->eta();
268 double phi = hitElement->phi();
269 double radius = hitElement->r();
270 int layer = hitElement->getSampling();
271 float x = hitElement->x();
272 float y = hitElement->y();
273 double z = hitElement->z();
274
275 m_h_cell_e->Fill( energy );
276 m_h_cell_eta->Fill( eta );
277 m_h_cell_phi->Fill( phi );
278 m_h_cell_radius->Fill( radius );
279 m_h_cell_layer->Fill( layer );
280 m_h_cell_eta_Eweight->Fill( eta , energy );
281 m_h_cell_phi_Eweight->Fill( phi , energy );
282 m_h_cell_radius_Eweight->Fill( radius , energy );
283 m_h_cell_layer_Eweight->Fill( layer , energy );
284 m_h_xy->Fill(x,y);
285 m_h_zr->Fill(z,radius);
286 m_h_etaphi->Fill(eta, phi);
287 if (m_expert) {
288 m_h_time_e->Fill(time, energy);
289 m_h_eta_e->Fill(eta, energy);
290 m_h_phi_e->Fill(phi, energy);
291 m_h_r_e->Fill(radius, energy);
292 }
293 m_cell_eta->push_back(eta);
294 m_cell_phi->push_back(phi);
295 m_cell_e->push_back(energy);
296 m_cell_x->push_back(x);
297 m_cell_y->push_back(y);
298 m_cell_z->push_back(z);
299 m_cell_radius->push_back(radius);
300 m_cell_layer->push_back(layer);
301 m_time->push_back(time);
302 } // End while hits
303 } // End detector type loop
304
305 //For calibrated hits
306 for (const auto& calibKey : m_caloCalibKeys){
308 ATH_CHECK(SG::get(iterator,calibKey, ctx));
309 //Not tested
310 for (auto hit_i : *iterator) {
311 GeoCaloCalibHit geoHit(*hit_i, calibKey.key(), caloMgr);
312 if (!geoHit) continue;
313 const CaloDetDescrElement* Element = geoHit.getDetDescrElement();
314 if (Element) {
315 double eta = Element->eta();
316 double phi = Element->phi();
317 double radius = Element->r();
318 double z = Element->z();
319 double emEnergy = geoHit.energyEM();
320 double nonEmEnergy = geoHit.energyNonEM();
321 double invEnergy = geoHit.energyInvisible();
322 double escEnergy = geoHit.energyEscaped();
323 double totEnergy = geoHit.energyTotal();
324 double particleID = HepMC::barcode(*hit_i);
325
326 m_h_calib_eta->Fill(eta);
327 m_h_calib_phi->Fill(phi);
328 m_h_calib_zr->Fill(z, radius);
329 m_h_calib_etaphi->Fill(eta,phi);
330 m_h_calib_eEM->Fill(emEnergy);
331 m_h_calib_eNonEM->Fill(nonEmEnergy);
332 m_h_calib_eInv->Fill(invEnergy);
333 m_h_calib_eEsc->Fill(escEnergy);
334 m_h_calib_eTot->Fill(totEnergy);
335 m_h_calib_eTotpartID->Fill(particleID, totEnergy);
336
337 m_calib_eta->push_back(eta);
338 m_calib_phi->push_back(phi);
339 m_calib_radius->push_back(radius);
340 m_calib_z->push_back(z);
341 m_calib_eEM->push_back(emEnergy);
342 m_calib_eNonEM->push_back(nonEmEnergy);
343 m_calib_eInv->push_back(invEnergy);
344 m_calib_eEsc->push_back(escEnergy);
345 m_calib_eTot->push_back(totEnergy);
346 m_calib_partID->push_back(particleID);
347 }
348 else {
349 ATH_MSG_WARNING("CaloDetDescrElement is NULL");
350 }
351 }
352 }
353 } // DoLAr
354
355
356 if (m_tree) m_tree->Fill();
357
358 return StatusCode::SUCCESS;
359}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
#define CHECK(...)
Evaluate an expression and check for errors.
AtlasHitsVector< TileHit > TileHitVector
#define y
#define x
#define z
const ServiceHandle< StoreGateSvc > & detStore() const
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
std::vector< float > * m_calib_eTot
std::vector< float > * m_cell_y
std::vector< float > * m_cell_z
SG::ReadHandleKeyArray< LArHitContainer > m_caloKeys
StringProperty m_path
std::vector< float > * m_cell_x
BooleanProperty m_calib
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
BooleanProperty m_expert
std::vector< float > * m_cell_phi
std::vector< float > * m_calib_z
std::vector< float > * m_calib_phi
std::vector< float > * m_calib_eInv
TH1 * m_h_cell_eta
Simple variables by Ketevi.
BooleanProperty m_useTile
std::vector< float > * m_calib_eEM
std::vector< float > * m_calib_eEsc
virtual StatusCode execute() override
const TileDetDescrManager * m_tileMgr
SG::ReadHandleKeyArray< CaloCalibrationHitContainer > m_caloCalibKeys
SG::ReadHandleKey< TileHitVector > m_tileKey
std::vector< float > * m_calib_radius
std::vector< int > * m_cell_layer
std::vector< float > * m_cell_radius
const TileID * m_tileID
std::vector< float > * m_calib_partID
TH1 * m_h_cell_radius_Eweight
std::vector< float > * m_calib_eta
std::vector< float > * m_cell_e
virtual StatusCode initialize() override
std::vector< float > * m_time
std::vector< float > * m_cell_eta
StringProperty m_ntupleFileName
std::vector< float > * m_calib_eNonEM
BooleanProperty m_useLAr
Adaptor for CaloCalibHits.
double energyTotal() const
const CaloDetDescrElement * getDetDescrElement() const
double energyNonEM() const
double energyEM() const
double energyEscaped() const
double energyInvisible() const
Hit collection.
int barcode(const T *p)
Definition Barcode.h:16
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.