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 <cmath>
28#include <numbers>
29#include <functional>
30#include <iostream>
31
32using namespace std::numbers;
33
35 ATH_MSG_DEBUG( "Initializing CaloHitAnalysis" );
36 if (m_useTile) {
37
38 ATH_CHECK( detStore()->retrieve(m_tileMgr) );
39 ATH_CHECK( detStore()->retrieve(m_tileID) );
40 }
41 ATH_CHECK(m_tileKey.initialize(m_useTile));
42 ATH_CHECK(m_caloMgrKey.initialize());
43 ATH_CHECK(m_caloKeys.initialize(m_useLAr));
45
46
47 m_h_cell_e = new TH1D("h_Calo_cell_e", "cell_e", 100,0.,500.);
48 m_h_cell_e->StatOverflows();
49 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_e->GetName(), m_h_cell_e));
50
51
52 m_h_cell_log_e = new TH1D("h_Calo_cell_log_e", "cell_log_e", 100,0.,std::log10(500.));
53 m_h_cell_log_e->StatOverflows();
54 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_log_e->GetName(), m_h_cell_log_e));
55
56 m_h_cell_eta = new TH1D("h_Calo_cell_eta", "cell_eta", 100,-5.,5.);
57 m_h_cell_eta->StatOverflows();
58 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_eta->GetName(), m_h_cell_eta));
59
60 m_h_cell_phi = new TH1D("h_Calo_cell_phi", "cell_phi", 64,-pi,pi);
61 m_h_cell_phi->StatOverflows();
62 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_phi->GetName(), m_h_cell_phi));
63
64 m_h_cell_radius = new TH1D("h_Calo_cell_radius", "cell_radius", 100, 0., 6000.);
65 m_h_cell_radius->StatOverflows();
66 ATH_CHECK(histSvc()->regHist( m_path+m_h_cell_radius->GetName(), m_h_cell_radius));
67
68 m_h_cell_layer = new TH1D("h_Calo_cell_layer", "cell_layer", 24, -0.5, 23.5);
69 m_h_cell_layer->StatOverflows();
70 CHECK(histSvc()->regHist( m_path+m_h_cell_layer->GetName(), m_h_cell_layer));
71
72 m_h_cell_eta_Eweight = new TH1D("h_Calo_cell_eta_Eweight", "cell_eta_Eweight", 100,-5.,5.);
73 m_h_cell_eta_Eweight->StatOverflows();
75
76 m_h_cell_phi_Eweight = new TH1D("h_Calo_cell_phi_Eweight", "cell_phi_Eweight", 64,-pi,pi);
77 m_h_cell_phi_Eweight->StatOverflows();
79
80 m_h_cell_radius_Eweight = new TH1D("h_Calo_cell_radius_Eweight", "cell_radius_Eweight", 100, 0., 6000.);
81 m_h_cell_radius_Eweight->StatOverflows();
83
84 m_h_cell_layer_Eweight = new TH1D("h_Calo_cell_layer_Eweight", "cell_layer_Eweight", 24, -0.5, 23.5);
85 m_h_cell_layer_Eweight->StatOverflows();
87
88 m_h_xy = new TH2F("h_Calo_xy", "xy", 100,-4000,4000,100, -4000, 4000);
89 m_h_xy->StatOverflows();
90 ATH_CHECK(histSvc()->regHist( m_path+m_h_xy->GetName(), m_h_xy));
91
92 m_h_zr = new TH2D("h_Calo_zr", "zr", 100,-7000.,7000.,100, 0., 6000.);
93 m_h_zr->StatOverflows();
94 ATH_CHECK(histSvc()->regHist( m_path+m_h_zr->GetName(), m_h_zr));
95
96 m_h_etaphi = new TH2D("h_Calo_etaphi", "eta_phi", 50,-5.,5.,50, -pi, pi);
97 m_h_etaphi->StatOverflows();
98 ATH_CHECK(histSvc()->regHist( m_path+m_h_etaphi->GetName(), m_h_etaphi));
99
100 //These histograms will be filled only if expert mode is set on
101 m_h_time_e = new TH2D("h_Calo_time_e", "energy vs time", 100, 0,50, 100,0,500);
102 m_h_time_e->StatOverflows();
103
104 m_h_eta_e = new TH2D("h_Calo_eta_e", "energy vs eta", 50, -5,5, 100,0,500);
105 m_h_eta_e->StatOverflows();
106
107 m_h_phi_e = new TH2D("h_Calo_phi_e", "energy vs phi", 50, -pi,pi, 100,0,500);
108 m_h_phi_e->StatOverflows();
109
110 m_h_r_e = new TH2D("h_Calo_r_e", "energy vs radius", 100, 0,6000, 100,0,500);
111 m_h_r_e->StatOverflows();
112
113 if (m_expert) {
114 ATH_CHECK(histSvc()->regHist(m_path + m_h_time_e->GetName(), m_h_time_e));
115 ATH_CHECK(histSvc()->regHist(m_path + m_h_eta_e->GetName(), m_h_eta_e));
116 ATH_CHECK(histSvc()->regHist(m_path + m_h_phi_e->GetName(), m_h_phi_e));
117 ATH_CHECK(histSvc()->regHist(m_path + m_h_r_e->GetName(), m_h_r_e));
118 }
119
120 //Histograms for calibrated hits
121 m_h_calib_eta = new TH1D("h_calib_eta", "calib. hits eta", 50,-5,5);
122 m_h_calib_eta->StatOverflows();
123
124 m_h_calib_phi = new TH1D("h_calib_phi", "calib. hits phi", 50,-pi,pi);
125 m_h_calib_phi->StatOverflows();
126
127 m_h_calib_zr = new TH2D("h_calib_zr", "calib. hits z vs r", 100,-7000,7000,1000, 0,6000);
128 m_h_calib_zr->StatOverflows();
129
130 m_h_calib_etaphi = new TH2D("h_calib_etaphi", "calib. hits eta vs phi",50,-5.,5., 50,-pi,pi);
131 m_h_calib_etaphi->StatOverflows();
132
133 m_h_calib_eEM = new TH1D("h_calib_eEM", "calib. hits EM energy", 100,0,100);
134 m_h_calib_eEM->StatOverflows();
135
136 m_h_calib_eNonEM = new TH1D("h_calib_nonEM", "calib. hits non EM energy", 100,0,100);
137 m_h_calib_eNonEM->StatOverflows();
138
139 m_h_calib_eInv = new TH1D("h_calib_eInv", "calib. hits invisible energy", 100,0,100);
140 m_h_calib_eInv->StatOverflows();
141
142 m_h_calib_eEsc = new TH1D("h_calib_eEsc", "calib. hits escaped energy", 100,0,100);
143 m_h_calib_eEsc->StatOverflows();
144
145 m_h_calib_eTot = new TH1D("h_calib_eTot", "calib. hits energy", 100,0,100);
146 m_h_calib_eTot->StatOverflows();
147
148 m_h_calib_eTotpartID = new TH1D("h_calib_eTotpartID", "calib. hits partID weighted with energy",600,0,300000);
149 m_h_calib_eTotpartID->StatOverflows();
150
151 if (m_calib) {
152 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eta->GetName(), m_h_calib_eta));
153 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_phi->GetName(), m_h_calib_phi));
154 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_zr->GetName(), m_h_calib_zr));
155 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_etaphi->GetName(), m_h_calib_etaphi));
156 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eEM->GetName(), m_h_calib_eEM));
157 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eNonEM->GetName(), m_h_calib_eNonEM));
158 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eInv->GetName(), m_h_calib_eInv));
159 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eEsc->GetName(), m_h_calib_eEsc));
160 ATH_CHECK(histSvc()->regHist(m_path + m_h_calib_eTot->GetName(), m_h_calib_eTot));
162 }
163
165 m_tree = new TTree("Calo", "Calo");
166 std::string fullNtupleName = "/" + m_ntupleFileName + "/";
167 ATH_CHECK( histSvc()->regTree(fullNtupleName, m_tree) );
168
169 m_tree->Branch("CellEta", &m_cell_eta);
170 m_tree->Branch("CellPhi", &m_cell_phi);
171 m_tree->Branch("CellX", &m_cell_x);
172 m_tree->Branch("CellY", &m_cell_y);
173 m_tree->Branch("CellZ", &m_cell_z);
174 m_tree->Branch("CellE", &m_cell_e);
175 m_tree->Branch("CellLogE", &m_cell_log_e);
176 m_tree->Branch("CellRadius", &m_cell_radius);
177 m_tree->Branch("CellLayer", &m_cell_layer);
178 m_tree->Branch("Time", &m_time);
179 m_tree->Branch("CalibEta", &m_calib_eta);
180 m_tree->Branch("CalibPhi", &m_calib_phi);
181 m_tree->Branch("CalibRadius", &m_calib_radius);
182 m_tree->Branch("CalibZ", &m_calib_z);
183 m_tree->Branch("Calib_eEM", &m_calib_eEM);
184 m_tree->Branch("Calib_eNonEM", &m_calib_eNonEM);
185 m_tree->Branch("Calib_eInv", &m_calib_eInv);
186 m_tree->Branch("Calib_eEsc", &m_calib_eEsc);
187 m_tree->Branch("Calib_eTot", &m_calib_eTot);
188 m_tree->Branch("Calib_partID", &m_calib_partID);
189
190 return StatusCode::SUCCESS;
191}
192
193
194StatusCode CaloHitAnalysis::execute(const EventContext& ctx) {
195 ATH_MSG_DEBUG( "In CaloHitAnalysis::execute()" );
196
197 m_cell_eta->clear();
198 m_cell_phi->clear();
199 m_cell_e->clear();
200 m_cell_log_e->clear();
201 m_cell_x->clear();
202 m_cell_y->clear();
203 m_cell_z->clear();
204 m_cell_radius->clear();
205 m_cell_layer->clear();
206 m_time->clear();
207 m_calib_eta->clear();
208 m_calib_phi->clear();
209 m_calib_radius->clear();
210 m_calib_z->clear();
211 m_calib_eEM->clear();
212 m_calib_eNonEM->clear();
213 m_calib_eInv->clear();
214 m_calib_eEsc->clear();
215 m_calib_eTot->clear();
216 m_calib_partID->clear();
217
218 const TileHitVector* hitVec{nullptr};
219 ATH_CHECK(SG::get(hitVec, m_tileKey, ctx));
220
221 if (hitVec) {
222 for (const auto& i_hit : *hitVec) {
223 Identifier pmt_id = (i_hit).identify();
224 Identifier cell_id = m_tileID->cell_id(pmt_id);
225 const CaloDetDescrElement* ddElement = (m_tileID->is_tile_aux(cell_id)) ? 0 : m_tileMgr->get_cell_element(cell_id);
226 if (ddElement) {
227 double tot_e = 0.;
228 double tot_time = 0.;
229 for (int t=0; t<(i_hit).size(); ++t) tot_e += (i_hit).energy(t);
230 for (int t=0; t<(i_hit).size(); ++t) tot_time += (i_hit).time(t);
231 m_h_cell_e->Fill(tot_e);
232 m_h_cell_log_e->Fill(std::log10(tot_e));
233 m_h_cell_eta->Fill(ddElement->eta());
234 m_h_cell_phi->Fill(ddElement->phi()) ;
235 m_h_cell_radius->Fill(ddElement->r());
236 m_h_cell_layer->Fill(ddElement->getSampling());
237 m_h_cell_eta_Eweight->Fill(ddElement->eta(),tot_e);
238 m_h_cell_phi_Eweight->Fill(ddElement->phi(),tot_e) ;
239 m_h_cell_radius_Eweight->Fill(ddElement->r(),tot_e);
240 m_h_cell_layer_Eweight->Fill(ddElement->getSampling(),tot_e);
241 m_h_xy->Fill(ddElement->x(), ddElement->y());
242 m_h_zr->Fill(ddElement->z(), ddElement->r());
243 m_h_etaphi->Fill(ddElement->eta(), ddElement->phi());
244
245 if (m_expert) {
246 m_h_time_e->Fill(tot_time, tot_e);
247 m_h_eta_e->Fill(ddElement->eta(), tot_e);
248 m_h_phi_e->Fill(ddElement->phi(), tot_e);
249 m_h_r_e->Fill(ddElement->r(), tot_e);
250 }
251 m_cell_eta->push_back(ddElement->eta());
252 m_cell_phi->push_back(ddElement->phi());
253 m_cell_e->push_back(tot_e);
254 m_cell_log_e->push_back(std::log10(tot_e));
255 m_cell_x->push_back(ddElement->x());
256 m_cell_y->push_back(ddElement->y());
257 m_cell_z->push_back(ddElement->z());
258 m_cell_radius->push_back(ddElement->r());
259 m_cell_layer->push_back(ddElement->getSampling());
260 m_time->push_back(tot_time);
261 }
262 }
263 } // DoTile
264
265 if (m_useLAr) {
266
267 const CaloDetDescrManager* caloMgr{nullptr};
268 ATH_CHECK(SG::get(caloMgr, m_caloMgrKey, ctx));
269
270 for (const auto& key : m_caloKeys) {
271 const LArHitContainer* iter{nullptr};
272 ATH_CHECK(SG::get(iter, key, ctx));
273 for (auto hi : *iter ) {
274 const CaloDetDescrElement *hitElement = caloMgr->get_element(hi->cellID());
275 double energy = hi->energy();
276 double time = hi->time();
277 double eta = hitElement->eta();
278 double phi = hitElement->phi();
279 double radius = hitElement->r();
280 int layer = hitElement->getSampling();
281 float x = hitElement->x();
282 float y = hitElement->y();
283 double z = hitElement->z();
284
285 m_h_cell_e->Fill( energy );
286 m_h_cell_log_e->Fill( std::log10(energy) );
287 m_h_cell_eta->Fill( eta );
288 m_h_cell_phi->Fill( phi );
289 m_h_cell_radius->Fill( radius );
290 m_h_cell_layer->Fill( layer );
291 m_h_cell_eta_Eweight->Fill( eta , energy );
292 m_h_cell_phi_Eweight->Fill( phi , energy );
293 m_h_cell_radius_Eweight->Fill( radius , energy );
294 m_h_cell_layer_Eweight->Fill( layer , energy );
295 m_h_xy->Fill(x,y);
296 m_h_zr->Fill(z,radius);
297 m_h_etaphi->Fill(eta, phi);
298 if (m_expert) {
299 m_h_time_e->Fill(time, energy);
300 m_h_eta_e->Fill(eta, energy);
301 m_h_phi_e->Fill(phi, energy);
302 m_h_r_e->Fill(radius, energy);
303 }
304 m_cell_eta->push_back(eta);
305 m_cell_phi->push_back(phi);
306 m_cell_e->push_back(energy);
307 m_cell_log_e->push_back(std::log10(energy));
308 m_cell_x->push_back(x);
309 m_cell_y->push_back(y);
310 m_cell_z->push_back(z);
311 m_cell_radius->push_back(radius);
312 m_cell_layer->push_back(layer);
313 m_time->push_back(time);
314 } // End while hits
315 } // End detector type loop
316
317 //For calibrated hits
318 for (const auto& calibKey : m_caloCalibKeys){
320 ATH_CHECK(SG::get(iterator,calibKey, ctx));
321 //Not tested
322 for (auto hit_i : *iterator) {
323 GeoCaloCalibHit geoHit(*hit_i, calibKey.key(), caloMgr);
324 if (!geoHit) continue;
325 const CaloDetDescrElement* Element = geoHit.getDetDescrElement();
326 if (Element) {
327 double eta = Element->eta();
328 double phi = Element->phi();
329 double radius = Element->r();
330 double z = Element->z();
331 double emEnergy = geoHit.energyEM();
332 double nonEmEnergy = geoHit.energyNonEM();
333 double invEnergy = geoHit.energyInvisible();
334 double escEnergy = geoHit.energyEscaped();
335 double totEnergy = geoHit.energyTotal();
336 double particleID = HepMC::barcode(*hit_i);
337
338 m_h_calib_eta->Fill(eta);
339 m_h_calib_phi->Fill(phi);
340 m_h_calib_zr->Fill(z, radius);
341 m_h_calib_etaphi->Fill(eta,phi);
342 m_h_calib_eEM->Fill(emEnergy);
343 m_h_calib_eNonEM->Fill(nonEmEnergy);
344 m_h_calib_eInv->Fill(invEnergy);
345 m_h_calib_eEsc->Fill(escEnergy);
346 m_h_calib_eTot->Fill(totEnergy);
347 m_h_calib_eTotpartID->Fill(particleID, totEnergy);
348
349 m_calib_eta->push_back(eta);
350 m_calib_phi->push_back(phi);
351 m_calib_radius->push_back(radius);
352 m_calib_z->push_back(z);
353 m_calib_eEM->push_back(emEnergy);
354 m_calib_eNonEM->push_back(nonEmEnergy);
355 m_calib_eInv->push_back(invEnergy);
356 m_calib_eEsc->push_back(escEnergy);
357 m_calib_eTot->push_back(totEnergy);
358 m_calib_partID->push_back(particleID);
359 }
360 else {
361 ATH_MSG_WARNING("CaloDetDescrElement is NULL");
362 }
363 }
364 }
365 } // DoLAr
366
367
368 if (m_tree) m_tree->Fill();
369
370 return StatusCode::SUCCESS;
371}
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 pi
#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
std::vector< float > * m_cell_log_e
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.
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
BooleanProperty m_useTile
std::vector< float > * m_calib_eEM
std::vector< float > * m_calib_eEsc
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:15
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.