ATLAS Offline Software
Loading...
Searching...
No Matches
LArFCalSamplingFraction.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// C++ stdlib
8#include <algorithm>
9#include <functional>
10#include <iostream>
11#include <cmath>
12
13// Root
14#include "TTree.h"
15
16// ATLAS Software
17#include "GaudiKernel/IToolSvc.h"
18#include "GaudiKernel/ITHistSvc.h"
19
20// ID classes
21#include "CaloDetDescr/CaloDetDescrElement.h"
25#include "Identifier/Identifier.h"
26
27// Hits and hit collections
28#include "LArSimEvent/LArHit.h"
34
35// For Cryostat Positions
37
38// Other useful tools for particle/event/beam info
40#include "AtlasHepMC/GenEvent.h"
44#include "CLHEP/Vector/LorentzVector.h"
45#include "CLHEP/Vector/ThreeVector.h"
46#include "CLHEP/Geometry/Point3D.h"
47
48
51
52LArFCalSamplingFraction::LArFCalSamplingFraction(const std::string &name, ISvcLocator *pSvcLocator)
53 : AthAlgorithm(name, pSvcLocator),
54 m_calibrationRun(false),
55 m_cx1(0.0), m_cx2(0.0), m_cx3(0.0),
56 m_cy1(0.0), m_cy2(0.0), m_cy3(0.0)
57{
58 declareProperty("Calibration", m_calibrationRun);
59}
60
61
64
66
67
72
74{
75 ATH_MSG_INFO("Initializing LArFCalSamplingFraction");
76
77 // Get a handle on the NTuple and histogramming service
78 ServiceHandle<ITHistSvc> histSvc("THistSvc", name());
79 CHECK(histSvc.retrieve());
80 ATH_MSG_DEBUG(" retrieved THistSvc");
81
82 const CaloIdManager *caloIdManager = nullptr;
83 ATH_CHECK(detStore()->retrieve(caloIdManager));
84
85 // Use just for now for Calibration... change later to GeoCalibHit
86 m_larFCalID = caloIdManager->getFCAL_ID();
87
88 if (m_larFCalID == 0)
89 throw GaudiException("Invalid LAr FCAL ID helper", "LArHitAnalysis", StatusCode::FAILURE);
90
91 // Use for now... soon change to GeoCalibHit
92 m_caloCellID = caloIdManager->getCaloCell_ID();
93
94 if (m_caloCellID == 0)
95 throw GaudiException("Invalid Calo Cell ID helper", "LArHitAnalysis", StatusCode::FAILURE);
96
97 ATH_CHECK(m_caloMgrKey.initialize());
98 ATH_CHECK(m_eventInfoKey.initialize());
99
100 m_pdg_id = new std::vector<int>; // particle id
101
102 m_hit_x1 = new std::vector<double>; // hit positions of cells
103 m_hit_y1 = new std::vector<double>;
104
105 m_hit_x2 = new std::vector<double>;
106 m_hit_y2 = new std::vector<double>;
107
108 m_hit_x3 = new std::vector<double>;
109 m_hit_y3 = new std::vector<double>;
110
111 m_hit_ieta1 = new std::vector<double>; // hit indices of cells
112 m_hit_iphi1 = new std::vector<double>;
113 m_hit_ieta2 = new std::vector<double>;
114 m_hit_iphi2 = new std::vector<double>;
115 m_hit_ieta3 = new std::vector<double>;
116 m_hit_iphi3 = new std::vector<double>;
117
118 m_cell1_E = new std::vector<double>; // Energy in cells
119 m_cell2_E = new std::vector<double>;
120 m_cell3_E = new std::vector<double>;
121
122 // Now add branches and leaves to the AAN tree
123 m_tree_AS = new TTree("tree_AS", "TTree of AnalysisSkleton");
124
125 // Event info
126 m_tree_AS->Branch("Run", &m_runNumber, "Run/I"); // run number
127 m_tree_AS->Branch("Event", &m_eventNumber, "Event/I"); // event number
128 m_tree_AS->Branch("Time", &m_eventTime, "Time/I"); // time stamp
129 m_tree_AS->Branch("LumiBlock", &m_lumiBlock, "LumiBlock/I"); // lumi block num
130 m_tree_AS->Branch("BCID", &m_bCID, "BCID/I"); // bunch crossing ID
131 m_tree_AS->Branch("Weight", &m_eventWeight, "Weight/D"); // weight
132
133 // FCal-specific and other variables
134 m_tree_AS->Branch("EFCal", &m_totalFCalEnergy, "EFCal/D");
135 m_tree_AS->Branch("NHitsFCal", &m_numHitsFCal, "NhitsFCal/I");
136
137 m_tree_AS->Branch("Vertex_Eta", &m_vertex_eta, "Vertex_Eta/D");
138 m_tree_AS->Branch("Vertex_Phi", &m_vertex_phi, "Vertex_Phi/D");
139
140 m_tree_AS->Branch("Pt", &m_pt, "Pt/D");
141 m_tree_AS->Branch("px", &m_px, "px/D");
142 m_tree_AS->Branch("py", &m_py, "py/D");
143 m_tree_AS->Branch("pz", &m_pz, "pz/D");
144 m_tree_AS->Branch("E", &m_E, "E/D");
145
146 m_tree_AS->Branch("VertexX", &m_vertx, "VertexX/D");
147 m_tree_AS->Branch("VertexY", &m_verty, "VertexY/D");
148 m_tree_AS->Branch("VertexZ", &m_vertz, "VertexZ/D");
149
150 m_tree_AS->Branch("MC_CCX1", &m_x_mc_cc1, "MC_CCX1/D");
151 m_tree_AS->Branch("MC_CCY1", &m_y_mc_cc1, "MC_CCY1/D");
152
153 m_tree_AS->Branch("MC_CCX2", &m_x_mc_cc2, "MC_CCX2/D");
154 m_tree_AS->Branch("MC_CCY2", &m_y_mc_cc2, "MC_CCY2/D");
155
156 m_tree_AS->Branch("MC_CCX3", &m_x_mc_cc3, "MC_CCX3/D");
157 m_tree_AS->Branch("MC_CCY3", &m_y_mc_cc3, "MC_CCY3/D");
158
159 m_tree_AS->Branch("CCX1", &m_x_cc1, "CCX1/D");
160 m_tree_AS->Branch("CCY1", &m_y_cc1, "CCY1/D");
161
162 m_tree_AS->Branch("CCX2", &m_x_cc2, "CCX2/D");
163 m_tree_AS->Branch("CCY2", &m_y_cc2, "CCY2/D");
164
165 m_tree_AS->Branch("CCX3", &m_x_cc3, "CCX3/D");
166 m_tree_AS->Branch("CCY3", &m_y_cc3, "CCY3/D");
167
168 m_tree_AS->Branch("NCell_1", &m_NCell1, "NCell1_1/I");
169 m_tree_AS->Branch("NCell_2", &m_NCell2, "NCell1_2/I");
170 m_tree_AS->Branch("NCell_3", &m_NCell3, "NCell1_3/I");
171
172 m_tree_AS->Branch("ParticleID", &m_pdg_id);
173
174 m_tree_AS->Branch("Hit_X1", &m_hit_x1);
175 m_tree_AS->Branch("Hit_Y1", &m_hit_y1);
176
177 m_tree_AS->Branch("Hit_X2", &m_hit_x2);
178 m_tree_AS->Branch("Hit_Y2", &m_hit_y2);
179
180 m_tree_AS->Branch("Hit_X3", &m_hit_x3);
181 m_tree_AS->Branch("Hit_Y3", &m_hit_y3);
182
183 m_tree_AS->Branch("Hit_eta1", &m_hit_ieta1);
184 m_tree_AS->Branch("Hit_phi1", &m_hit_iphi1);
185 m_tree_AS->Branch("Hit_eta2", &m_hit_ieta2);
186 m_tree_AS->Branch("Hit_phi2", &m_hit_iphi2);
187 m_tree_AS->Branch("Hit_eta3", &m_hit_ieta3);
188 m_tree_AS->Branch("Hit_phi3", &m_hit_iphi3);
189
190 m_tree_AS->Branch("Cell1_E", &m_cell1_E);
191 m_tree_AS->Branch("Cell2_E", &m_cell2_E);
192 m_tree_AS->Branch("Cell3_E", &m_cell3_E);
193
194 m_tree_AS->Branch("FCal1_E", &m_FCal1_SumE, "FCal1_E/D");
195 m_tree_AS->Branch("FCal2_E", &m_FCal2_SumE, "FCal2_E/D");
196 m_tree_AS->Branch("FCal3_E", &m_FCal3_SumE, "FCal3_E/D");
197
198 if (m_calibrationRun) {
199 m_caloDmID = caloIdManager->getDM_ID();
200
201 if (m_caloDmID == 0)
202 throw GaudiException("Invalid Calo DM ID helper", "LArFCalTB_MC_CBNT_AA", StatusCode::FAILURE);
203
204 // Define the hit containers that we'll analyze in this program.
205 // For now, initialize the pointers to the containers to NULL (zero).
206 m_calibHitMap["LArCalibrationHitActive"] = 0;
207 m_calibHitMap["LArCalibrationHitInactive"] = 0;
208 m_calibHitMap["LArCalibrationHitDeadMaterial"] = 0;
209
210 m_tree_AS->Branch("Calib_TotalEnergy", &m_totalCalibrationEnergy, "Calib_TotalEnergy/D");
211 m_tree_AS->Branch("Calib_TotalEm", &m_totalEmEnergy, "Calib_TotalEm/D");
212 m_tree_AS->Branch("Calib_TotalNonEm", &m_totalNonEmEnergy, "Calib_TotalNonEm/D");
213 m_tree_AS->Branch("Calib_TotalInvisible", &m_totalInvisibleEnergy, "Calib_TotalInvisible/D");
214 m_tree_AS->Branch("Calib_TotalEscaped", &m_totalEscapedEnergy, "Calib_TotalEscaped/D");
215 m_tree_AS->Branch("Calib_FCalEnergy", &m_totalFCalCalibrationEnergy, "Calib_FCalEnergy/D");
216 m_tree_AS->Branch("Calib_TotalActive", &m_totalActiveEnergy, "Calib_TotalActive/D");
217 m_tree_AS->Branch("Calib_TotalInactive", &m_totalInactiveEnergy, "Calib_TotalInactive/D");
218 m_tree_AS->Branch("Calib_DeadEnergy", &m_totalDeadMaterialEnergy, "Calib_DeadEnergy/D");
219 m_tree_AS->Branch("Calib_NHitsInactive", &m_numHitsInactive, "Calib_NHitsInactive/I");
220 m_tree_AS->Branch("Calib_NHitsDead", &m_numHitsDead, "Calib_NHitsDead/I");
221 m_tree_AS->Branch("Calib_FCal1Energy", &m_totalFCal1CalibrationEnergy, "Calib_FCal1Energy/D");
222 m_tree_AS->Branch("Calib_FCal2Energy", &m_totalFCal2CalibrationEnergy, "Calib_FCal2Energy/D");
223 m_tree_AS->Branch("Calib_FCal3Energy", &m_totalFCal3CalibrationEnergy, "Calib_FCal3Energy/D");
224
225 m_tree_AS->Branch("Calib_FCalActive", &m_FCalActive, "Calib_FCalActive/D");
226 m_tree_AS->Branch("Calib_FCalInactive", &m_FCalInactive, "Calib_FCalInactive/D");
227 m_tree_AS->Branch("Calib_FCalDead", &m_FCalDead, "Calib_FCalDead/D");
228 m_tree_AS->Branch("Calib_FCalEm", &m_FCalEm, "Calib_FCalEm/D");
229 m_tree_AS->Branch("Calib_FCal1Em", &m_FCal1Em, "Calib_FCal1Em/D");
230 m_tree_AS->Branch("Calib_FCal2Em", &m_FCal2Em, "Calib_FCal2Em/D");
231 m_tree_AS->Branch("Calib_FCal3Em", &m_FCal3Em, "Calib_FCal3Em/D");
232 m_tree_AS->Branch("Calib_FCalNonEm", &m_FCalNonEm, "Calib_FCalNonEm/D");
233 m_tree_AS->Branch("Calib_FCal1NonEm", &m_FCal1NonEm, "Calib_FCal1NonEm/D");
234 m_tree_AS->Branch("Calib_FCal2NonEm", &m_FCal2NonEm, "Calib_FCal2NonEm/D");
235 m_tree_AS->Branch("Calib_FCal3NonEm", &m_FCal3NonEm, "Calib_FCal3NonEm/D");
236 m_tree_AS->Branch("Calib_FCalInvisible", &m_FCalInvisible, "Calib_FCalInvisible/D");
237 m_tree_AS->Branch("Calib_FCal1Invisible", &m_FCal1Invisible, "Calib_FCal1Invisible/D");
238 m_tree_AS->Branch("Calib_FCal2Invisible", &m_FCal2Invisible, "Calib_FCal2Invisible/D");
239 m_tree_AS->Branch("Calib_FCal3Invisible", &m_FCal3Invisible, "Calib_FCal3Invisible/D");
240 m_tree_AS->Branch("Calib_FCalEscaped", &m_FCalEscaped, "Calib_FCalEscaped/D");
241 m_tree_AS->Branch("Calib_FCal1Escaped", &m_FCal1Escaped, "Calib_FCal1Escaped/D");
242 m_tree_AS->Branch("Calib_FCal2Escaped", &m_FCal2Escaped, "Calib_FCal2Escaped/D");
243 m_tree_AS->Branch("Calib_FCal3Escaped", &m_FCal3Escaped, "Calib_FCal3Escaped/D");
244 m_tree_AS->Branch("Calib_FCal1Active", &m_FCal1Active, "Calib_FCal1Active/D");
245 m_tree_AS->Branch("Calib_FCal2Active", &m_FCal2Active, "Calib_FCal2Active/D");
246 m_tree_AS->Branch("Calib_FCal3Active", &m_FCal3Active, "Calib_FCal3Active/D");
247 m_tree_AS->Branch("Calib_FCal1Inactive", &m_FCal1Inactive, "Calib_FCal1Inactive/D");
248 m_tree_AS->Branch("Calib_FCal2Inactive", &m_FCal2Inactive, "Calib_FCal2Inactive/D");
249 m_tree_AS->Branch("Calib_FCal3Inactive", &m_FCal3Inactive, "Calib_FCal3Inactive/D");
250 m_tree_AS->Branch("Calib_FCalActiveEm", &m_FCalActiveEm, "Calib_FCalActiveEm/D");
251 m_tree_AS->Branch("Calib_FCalActiveNonEm", &m_FCalActiveNonEm, "Calib_FCalActiveNonEm/D");
252 m_tree_AS->Branch("Calib_FCalActiveInvisible", &m_FCalActiveInvisible, "Calib_FCalActiveInvisible/D");
253 m_tree_AS->Branch("Calib_FCalActiveEscaped", &m_FCalActiveEscaped, "Calib_FCalActiveEscaped/D");
254 }
255
256 CHECK(histSvc->regTree("/AANT/tree_AS", m_tree_AS));
257
258 m_eventNumber = 0;
259
260 return StatusCode::SUCCESS;
261}
262
263
267
269{
270 return StatusCode::SUCCESS;
271}
272
273
277
279{
281
282 ATH_MSG_INFO("Initializing event, clearing variables");
283
284 m_vertx = 0; // x-position for vertex generated particle (beam)
285 m_verty = 0;
286 m_vertz = 0;
287
288 m_vertex_eta = 0; // eta value of generated particle
289 m_vertex_phi = 0;
290
291 m_pt = 0; // Momentum of generated particle
292 m_px = 0;
293 m_py = 0;
294 m_pz = 0;
295
296 m_E = 0; // Energy of generated particle
297
298 m_NCell1 = 0; // Number of cells hit
299 m_NCell2 = 0;
300 m_NCell3 = 0;
301
302 m_x_mc_cc1 = 0; // Center of cluster in x (FCal1, extrapolated)
303 m_y_mc_cc1 = 0;
304
305 m_x_mc_cc2 = 0; // Center of cluster in x (FCal2, extrapolated)
306 m_y_mc_cc2 = 0;
307
308 m_x_mc_cc3 = 0; // Center of cluster in x (FCal3, extrapolated)
309 m_y_mc_cc3 = 0;
310
311 m_x_cc1 = 0; // Center of cluster in x (FCal1, c of g)
312 m_y_cc1 = 0;
313
314 m_x_cc2 = 0; // Center of cluster in x (FCal2, c of g)
315 m_y_cc2 = 0;
316
317 m_x_cc3 = 0; // Center of cluster in x (FCal3, c of g)
318 m_y_cc3 = 0;
319
320 m_pdg_id->clear(); // particle id
321
322 m_hit_x1->clear(); // hit positions of cells
323 m_hit_y1->clear();
324
325 m_hit_x2->clear();
326 m_hit_y2->clear();
327
328 m_hit_x3->clear();
329 m_hit_y3->clear();
330
331 m_hit_ieta1->clear(); // hit indices of cells
332 m_hit_iphi1->clear();
333 m_hit_ieta2->clear();
334 m_hit_iphi2->clear();
335 m_hit_ieta3->clear();
336 m_hit_iphi3->clear();
337
338 m_cell1_E->clear(); // Energy in cells
339 m_cell2_E->clear();
340 m_cell3_E->clear();
341
342 m_FCal1_SumE = 0; // Energy in individual FCal modules
343 m_FCal2_SumE = 0;
344 m_FCal3_SumE = 0;
345 m_TCScint_E = 0;
346 m_TCIron_E = 0;
347
349 m_numHitsFCal = 0;
350
351 m_totalCalibrationEnergy = 0; // Total energy
352
353 // Physic Processes
354 m_totalEmEnergy = 0;
358
359 // Energy deposited in different material categories
363
364 // Number of hits in different material categories
365 m_numHitsActive = 0;
367 m_numHitsDead = 0;
368
369 // Total energy deposited in the different FCal Modules
370 m_totalFCalCalibrationEnergy = 0; // Energy in all FCal
374
375 m_FCalActive = 0;
376 m_FCalInactive = 0;
377 m_FCalDead = 0;
378 m_FCalActiveEm = 0;
382 m_FCalEm = 0;
383 m_FCal1Em = 0;
384 m_FCal2Em = 0;
385 m_FCal3Em = 0;
386 m_FCalNonEm = 0;
387 m_FCal1NonEm = 0;
388 m_FCal2NonEm = 0;
389 m_FCal3NonEm = 0;
390 m_FCalInvisible = 0;
394 m_FCalEscaped = 0;
395 m_FCal1Escaped = 0;
396 m_FCal2Escaped = 0;
397 m_FCal3Escaped = 0;
398 m_PhysTotE = 0;
399 m_FCal1Active = 0;
400 m_FCal2Active = 0;
401 m_FCal3Active = 0;
402 m_FCal1Inactive = 0;
403 m_FCal2Inactive = 0;
404 m_FCal3Inactive = 0;
405
406 return StatusCode::SUCCESS;
407}
408
409
412
414 , const CaloDetDescrManager* caloMgr)
415{
416 double max1 = 0.0;
417 double max2 = 0.0;
418 double max3 = 0.0;
419
420 // Loop over hits in container
421 for (const LArHit* hit : *container) {
422
423 const CaloDetDescrElement* caloDDE = caloMgr->get_element(hit->cellID());
424 if(!caloDDE->is_lar_fcal()) {
425 ATH_MSG_WARNING("Hit in LarHitContainer does not belong to FCAL");
426 continue;
427 }
428
429 double energy = hit->energy();
430
431 int module_index = caloDDE->getLayer();
432
433 double x = caloDDE->x();
434 double y = caloDDE->y();
435
436 // Determine the center of the cluster for each FCal module
437 if (module_index == 1) {
438 // FCal1
439 if (max1 < energy) {
440 max1 = energy;
441 m_cx1 = x;
442 m_cy1 = y;
443 }
444 }
445 else if (module_index == 2) {
446 // FCal2
447 if (max2 < energy) {
448 max2 = energy;
449 m_cx2 = x;
450 m_cy2 = y;
451 }
452 }
453 else if (module_index == 3) {
454 // FCal3
455 if (max3 < energy) {
456 max3 = energy;
457 m_cx3 = x;
458 m_cy3 = y;
459 }
460 }
461
462 } // End loop over hits in container
463}
464
465
468
470 , const CaloDetDescrManager* caloMgr)
471{
472 float xNumer1 = 0.0, xNumer2 = 0.0, xNumer3 = 0.0;
473 float yNumer1 = 0.0, yNumer2 = 0.0, yNumer3 = 0.0;
474 float Denom1 = 0.0, Denom2 = 0.0, Denom3 = 0.0;
475
476 double subClusterSize = 30.0; // [mm]
477 double thisCG_R = 0.0;
478
479 // Loop over hits in container
480 for (const LArHit* hit : *container) {
481
482 const CaloDetDescrElement* caloDDE = caloMgr->get_element(hit->cellID());
483 if(!caloDDE->is_lar_fcal()) {
484 ATH_MSG_WARNING("Hit in LarHitContainer is not a GeoFCalHit");
485 continue;
486 }
487
488 double energy = hit->energy();
489
490 int module_index = caloDDE->getLayer();
491
492 double x = caloDDE->x();
493 double y = caloDDE->y();
494
495
496 // Determine center of cluster
497 if (module_index == 1) {
498 // FCal1
499 double x_subcheck1 = m_cx1 - x;
500 double y_subcheck1 = m_cy1 - y;
501 thisCG_R = sqrt(x_subcheck1 * x_subcheck1 + y_subcheck1 * y_subcheck1);
502
503 if (thisCG_R <= subClusterSize) {
504 xNumer1 += x * energy;
505 yNumer1 += y * energy;
506 Denom1 += energy;
507 }
508 }
509 else if (module_index == 2) {
510 // FCal2
511 double x_subcheck2 = m_cx2 - x;
512 double y_subcheck2 = m_cy2 - y;
513 thisCG_R = sqrt(x_subcheck2 * x_subcheck2 + y_subcheck2 * y_subcheck2);
514
515 if (thisCG_R <= subClusterSize) {
516 xNumer2 += x * energy;
517 yNumer2 += y * energy;
518 Denom2 += energy;
519 }
520 }
521 else if (module_index == 3) {
522 // FCal3
523 double x_subcheck3 = m_cx3 - x;
524 double y_subcheck3 = m_cy3 - y;
525 thisCG_R = sqrt(x_subcheck3 * x_subcheck3 + y_subcheck3 * y_subcheck3);
526
527 if (thisCG_R <= subClusterSize) {
528 xNumer3 += x * energy;
529 yNumer3 += y * energy;
530 Denom3 += energy;
531 }
532 }
533
534 } // End loop over hits in container
535
536 if (fabs(Denom1) > 0.0) {
537 m_x_cc1 = xNumer1 / Denom1;
538 m_y_cc1 = yNumer1 / Denom1;
539 }
540
541 if (fabs(Denom2) > 0.0) {
542 m_x_cc2 = xNumer2 / Denom2;
543 m_y_cc2 = yNumer2 / Denom2;
544 }
545
546 if (fabs(Denom3) > 0.0) {
547 m_x_cc3 = xNumer3 / Denom3;
548 m_y_cc3 = yNumer3 / Denom3;
549 }
550}
551
552
555
557{
558 StatusCode sc;
559
560 ATH_MSG_DEBUG("Starting FCal Calibration Analysis");
561
562 // Get the calibration hit containers (if any)
563 for (auto& kv : m_calibHitMap)
564 {
565 std::string name = kv.first;
567 sc = evtStore()->retrieve(container, name);
568
569 if (sc.isFailure() || container == 0) {
570 ATH_MSG_ERROR("CaloCalibrationHit container was not found");
571 m_numHitsActive = 0;
573 m_numHitsDead = 0;
574 kv.second = 0;
575
576 return StatusCode::FAILURE;
577 }
578
579 ATH_MSG_DEBUG("CaloCalibrationHit container successfully retrieved");
580
581 kv.second = container;
582 }
583
584 // Get the number of hits in each container
585 // (The braces let us re-use the name 'container')
586 {
587 const CaloCalibrationHitContainer *container = m_calibHitMap["LArCalibrationHitActive"];
588
589 if (container != 0)
590 m_numHitsActive = container->Size();
591 else
592 m_numHitsActive = 0;
593 }
594 {
595 const CaloCalibrationHitContainer *container = m_calibHitMap["LArCalibrationHitInactive"];
596
597 if (container != 0)
599 else
601 }
602 {
603 const CaloCalibrationHitContainer *container = m_calibHitMap["LArCalibrationHitDeadMaterial"];
604
605 if (container != 0)
606 m_numHitsDead = container->Size();
607 else
608 m_numHitsDead = 0;
609 }
610
611 // Loop over all the hit containers, inspecting each hit within the collection
612 for (const auto& kv : m_calibHitMap)
613 {
614 std::string name = kv.first;
615 const CaloCalibrationHitContainer *container = kv.second;
616
617 // Skip rest of loop if it's a null container.
618 if (container == 0)
619 continue;
620
621 // Loop over calibration hits in container
622 for (const CaloCalibrationHit* calibhit : *container) {
623
624 Identifier identifier = calibhit->cellID();
625 double energy = calibhit->energyTotal();
626
627 // Accumulate energy sums. Use the ID helpers to determine in which
628 // detector the hit took place.
629
630 m_totalCalibrationEnergy += energy;
631 m_totalEmEnergy += calibhit->energyEM();
632 m_totalNonEmEnergy += calibhit->energyNonEM();
633 m_totalInvisibleEnergy += calibhit->energyInvisible();
634 m_totalEscapedEnergy += calibhit->energyEscaped();
635
636 if (name == "LArCalibrationHitActive")
637 m_totalActiveEnergy += energy;
638
639 if (name == "LArCalibrationHitInactive")
640 m_totalInactiveEnergy += energy;
641
642 if (name == "LArCalibrationHitDeadMaterial") {
644
645 if (m_caloDmID->is_lar(identifier) && (m_caloDmID->sampling(identifier) == 3) && (m_caloDmID->dmat(identifier) == 1))
646 m_FCalDead += energy;
647 }
648
649 if (m_caloCellID->is_lar_fcal(identifier))
650 FCalCalibAnalysis(name, calibhit);
651
652 } // End loop over calibration hits in container
653 } // End loop over containers
654
655 // Execution completed
656
657 ATH_MSG_DEBUG("doCalib() completed successfully");
658 return sc;
659}
660
661
665
666void LArFCalSamplingFraction::FCalCalibAnalysis(const std::string& name, const CaloCalibrationHit *CalibHit)
667{
668 Identifier id = CalibHit->cellID();
669 double energy = CalibHit->energyTotal();
670
673 m_FCalEm += CalibHit->energyEM();
674 m_FCalNonEm += CalibHit->energyNonEM();
675 m_FCalInvisible += CalibHit->energyInvisible();
676 m_FCalEscaped += CalibHit->energyEscaped();
677
678 if (m_larFCalID->module(id) == 1) {
679 // FCal1
681 m_FCal1Em += CalibHit->energyEM();
682 m_FCal1NonEm += CalibHit->energyNonEM();
683 m_FCal1Invisible += CalibHit->energyInvisible();
684 m_FCal1Escaped += CalibHit->energyEscaped();
685 }
686 else if (m_larFCalID->module(id) == 2) {
687 // FCal2
689 m_FCal2Em += CalibHit->energyEM();
690 m_FCal2NonEm += CalibHit->energyNonEM();
691 m_FCal2Invisible += CalibHit->energyInvisible();
692 m_FCal2Escaped += CalibHit->energyEscaped();
693 }
694 else if (m_larFCalID->module(id) == 3) {
695 // FCal3
697 m_FCal3Em += CalibHit->energyEM();
698 m_FCal3NonEm += CalibHit->energyNonEM();
699 m_FCal3Invisible += CalibHit->energyInvisible();
700 m_FCal3Escaped += CalibHit->energyEscaped();
701 }
702
703 if (name == "LArCalibrationHitActive") {
704 m_FCalActive += energy;
705 m_FCalActiveEm += CalibHit->energyEM();
706 m_FCalActiveNonEm += CalibHit->energyNonEM();
708 m_FCalActiveEscaped += CalibHit->energyEscaped();
709
710 if (m_larFCalID->module(id) == 1)
711 m_FCal1Active += energy;
712
713 if (m_larFCalID->module(id) == 2)
714 m_FCal2Active += energy;
715
716 if (m_larFCalID->module(id) == 3)
717 m_FCal3Active += energy;
718 }
719
720 if (name == "LArCalibrationHitInactive") {
721 m_FCalInactive += energy;
722
723 if (m_larFCalID->module(id) == 1)
724 m_FCal1Inactive += energy;
725
726 if (m_larFCalID->module(id) == 2)
727 m_FCal2Inactive += energy;
728
729 if (m_larFCalID->module(id) == 3)
730 m_FCal3Inactive += energy;
731 }
732}
733
734
737
739{
740 for (const auto& theParticle: *e)
741 {
742 // Note: old GenParticles used HepLorentzVectors, now they use HepMC::FourVectors
743
744 // Get the kinematic variables
745 const HepMC::FourVector& HMCmom = theParticle->momentum();
746 CLHEP::HepLorentzVector momentum(CLHEP::Hep3Vector(HMCmom.px(), HMCmom.py(), HMCmom.pz()), HMCmom.e());
747
748 HepMC::FourVector HMC3vec(0.0,0.0,0.0,0.0);
749 if (theParticle->production_vertex()) HMC3vec = theParticle->production_vertex()->position();
750 HepGeom::Point3D<double> origin = HepGeom::Point3D<double>(HMC3vec.x(), HMC3vec.y(), HMC3vec.z());
751
752 // Put VEta and VPhi into the Ntuple
753 m_vertex_phi = momentum.vect().phi();
754 m_vertex_eta = -log(tan(momentum.vect().theta() / 2));
755
756 if (!finite(m_vertex_eta))
757 m_vertex_eta = 0;
758
759 m_pt = momentum.vect().perp();
760
761 m_px = momentum.px();
762 m_py = momentum.py();
763 m_pz = momentum.pz();
764
765 m_E = momentum.e();
766
767 m_vertx = theParticle->production_vertex()->position().x();
768 m_verty = theParticle->production_vertex()->position().y();
769 m_vertz = theParticle->production_vertex()->position().z();
770
771 // Must get x-offset depending on TB position. The 90.0 mm is from the
772 // initial x-offset of FCal in cryostat. The -15.0 mm is from the
773 // initial y-offset of FCal in cryostat. The second number changes
774 // between different positions (these numbers will be in database soon)
775
776 std::string nickname;
777 double xoffset = 0;
778 double sinangle = 0;
779 double yoffset = 0;
780 const double z1 = -32668.5 * CLHEP::mm; // This is 4668.5 (z=0 to FCal1 Face) + 28000 (B9 to z=0)
781 const double z2 = -33128.3 * CLHEP::mm; // This is 5128.3 (z=0 to FCal1 Face) + 28000 (B9 to z=0)
782 const double z3 = -33602.8 * CLHEP::mm; // This is 5602.8 (z=0 to FCal1 Face) + 28000 (B9 to z=0)
783
784 double shift2 = sinangle * (5128.3 - 4668.5) * CLHEP::mm;
785 double shift3 = sinangle * (5602.8 - 4668.5) * CLHEP::mm;
786
787 // Accounts for rotation of Fcal + cryostat.
788 m_x_mc_cc1 = origin.x() + m_px * z1 / m_pz + xoffset;
789 m_y_mc_cc1 = origin.y() + m_py * z1 / m_pz + yoffset;
790
791 m_x_mc_cc2 = origin.x() + m_px * z2 / m_pz + shift2 + xoffset;
792 m_y_mc_cc2 = origin.y() + m_py * z2 / m_pz + yoffset;
793
794 m_x_mc_cc3 = origin.x() + m_px * z3 / m_pz + shift3 + xoffset;
795 m_y_mc_cc3 = origin.y() + m_py * z3 / m_pz + yoffset;
796
797 } // particles
798}
799
800
803
805{
806 ATH_MSG_INFO("Starting main FCal analysis");
807
808 ATH_MSG_DEBUG("LArFCalSamplingFraction parameters are:");
809 ATH_MSG_DEBUG("Calibration: " << m_calibrationRun);
810
811 StatusCode sc;
812
813 // ACCESSING EVENT INFORMATION
814 // Get the basic event information (run number, event number).
815 SG::ReadHandle<xAOD::EventInfo> eventInfo(m_eventInfoKey,getContext());
816 ATH_CHECK(eventInfo.isValid());
817 m_runNumber = eventInfo->runNumber();
818 m_eventNumber = eventInfo->eventNumber();
819
820 ATH_MSG_INFO("Run " << m_runNumber << ", event " << m_eventNumber);
821
822 // How to access MC Truth information:
823 const McEventCollection *mcEventCollection{};
824 sc = evtStore()->retrieve(mcEventCollection, "TruthEvent");
825
826 if (sc.isSuccess()) {
827 // There can potentially be more than one MC event in the collection.
829 for (const HepMC::GenEvent * mcEvent : *mcEventCollection) {
830 TruthImpactPosition(mcEvent);
831 }
832 } // retrieved MC event collection
833 else {
834 ATH_MSG_DEBUG("Run " << m_runNumber << ", event " << m_eventNumber
835 << ": could not fetch MC event collection");
836 }
837
838 // Accessing Hits
839 // Regular hits
840 std::string FCalContainerName = "LArHitFCAL";
841 const LArHitContainer *container = 0;
842 sc = evtStore()->retrieve(container, FCalContainerName);
843
844 if (sc.isFailure() || container == 0) {
845 ATH_MSG_ERROR("LArHitFCAL container was not found");
846 m_numHitsFCal = 0;
847 return StatusCode::FAILURE;
848 }
849
850 ATH_MSG_DEBUG("LArHitFCAL container successfully retrieved");
851
853 ATH_CHECK(caloMgrHandle.isValid());
854 const CaloDetDescrManager* caloMgr = *caloMgrHandle;
855
856
857 // Get the number of hits in the LArHitFCAL container
858 m_numHitsFCal = container->size();
859 ATH_MSG_INFO("NumHitsFCal = " << m_numHitsFCal);
860
861 if (m_numHitsFCal > 0) {
862 // Calculate the center of gravity
863 FCalHitCenter(container,caloMgr);
865 }
866
867 // Loop over hits in container
868 for (const LArHit* hit : *container) {
869
870 // Added by JPA to get particle id for each hit
871 const McEventCollection *mcEventCollection{};
872 sc = evtStore()->retrieve(mcEventCollection, "TruthEvent");
873
874 if (sc.isSuccess()) {
875 // There can potentially be more than one MC event in the collection
877
878 for (const HepMC::GenEvent * mcEvent : *mcEventCollection)
879 {
880 // There may be many particles per event
881 for (auto theParticle: *mcEvent)
882 {
883 m_pdg_id->push_back(theParticle->pdg_id());
884 }
885 }
886 } // retrieved MC event collection
887
888 // End JPA particle id
889
890 const CaloDetDescrElement* caloDDE = caloMgr->get_element(hit->cellID());
891 if(!caloDDE->is_lar_fcal()) {
892 ATH_MSG_ERROR("LArHit does not belong to FCAL");
893 }
894
895 double energy = hit->energy();
896 int module_index = caloDDE->getLayer();
897 m_totalFCalEnergy += energy;
898
899 if (module_index == 1) {
900 m_FCal1_SumE += energy;
902 }
903 else if (module_index == 2) {
904 m_FCal2_SumE += energy;
906 }
907 else if (module_index == 3) {
908 m_FCal3_SumE += energy;
910 }
911 } // End loop over hits in container
912
913 // Calibration hit analysis.
915 CHECK(doCalib());
916
917 ATH_MSG_DEBUG("doFCal() completed successfully");
918
919 return StatusCode::SUCCESS;
920}
921
922
925
926void LArFCalSamplingFraction::FillCellInfo(const CaloDetDescrElement* caloDDE, double energy, std::vector<double> *cell_E,
927 std::vector<double> *hit_x, std::vector<double> *hit_y,
928 std::vector<double> *hit_ieta, std::vector<double> *hit_iphi,
929 int &NCell)
930{
931 const double hitx = caloDDE->x(); //tile->getX();
932 const double hity = caloDDE->y(); //tile->getY();
933 const double hiteta = 7; //tile->getIndexI();
934 const double hitphi = 7; //tile->getIndexJ();
935
936 bool cellHit = true;
937
938 if (NCell != 0) {
939 for (int icell = 0; icell < NCell; icell++) {
940 if ((hitx == hit_x->at(icell)) && (hity == hit_y->at(icell))) {
941 cellHit = false;
942 cell_E->at(icell) += energy;
943 break;
944 }
945 }
946 }
947
948 if (cellHit) {
949 cell_E->push_back(energy);
950 hit_x->push_back(hitx);
951 hit_y->push_back(hity);
952 hit_ieta->push_back(hiteta);
953 hit_iphi->push_back(hitphi);
954 NCell += 1;
955 }
956}
957
958
961
963{
964 ATH_MSG_DEBUG(" in execute()");
965
967
968 // Initialize first before processing each event
969 StatusCode sc = initEvent();
970
971 if (sc.isFailure())
972 ATH_MSG_WARNING("initEvent failed. Continue");
973
974 sc = doFCal();
975
976 sc = addEventInfo();
977
978 if (sc.isFailure()) {
979 ATH_MSG_WARNING("Failure in getEventInfo() ");
980 return StatusCode::SUCCESS;
981 }
982
983 m_tree_AS->Fill();
984
985 return StatusCode::SUCCESS;
986}
987
988
990{
991 ATH_MSG_DEBUG("in addEventInfo()");
992
993 // This code has been taken from AnalysisExamples/VFitZmmOnAOD
994 // I have the actual EventNumber, but skipped the sequential count of event #
995
996 // Get EventInfo for run and event number
997 SG::ReadHandle<xAOD::EventInfo> eventInfo(m_eventInfoKey,getContext());
998 ATH_CHECK(eventInfo.isValid());
999 m_runNumber = eventInfo->runNumber();
1000 m_eventNumber = eventInfo->eventNumber();
1001
1002 ATH_MSG_DEBUG("event " << m_eventNumber);
1003
1004 m_eventTime = eventInfo->timeStamp();
1005 m_lumiBlock = eventInfo->lumiBlock();
1006 m_bCID = eventInfo->bcid();
1007 m_eventWeight = eventInfo->mcEventWeight();
1008
1009 return StatusCode::SUCCESS;
1010}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
#define y
#define x
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Class to store calorimeter calibration hit.
double energyNonEM() const
Identifier cellID() const
double energyEscaped() const
double energyInvisible() const
double energyTotal() const
This class groups all DetDescr information related to a CaloCell.
virtual int getLayer() const
cell layer
bool is_lar_fcal() const
cell belongs to FCAL
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...
This class initializes the Calo (LAr and Tile) offline identifiers.
const CaloDM_ID * getDM_ID(void) const
const CaloCell_ID * getCaloCell_ID(void) const
Access to IdHelper.
const LArFCAL_ID * getFCAL_ID(void) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
virtual StatusCode initEvent()
Init event.
LArFCalSamplingFraction(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
std::vector< double > * m_hit_x1
StatusCode doFCal()
The main FCal analysis method.
StatusCode addEventInfo()
methods called by execute()
virtual StatusCode execute() override
Execute (event by event)
std::vector< double > * m_hit_iphi2
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
TTree * m_tree_AS
Athena-Aware Ntuple (AAN) variables - branches of the AAN TTree.
std::vector< double > * m_cell2_E
std::vector< double > * m_hit_y2
std::vector< double > * m_hit_ieta1
void FCalCalibAnalysis(const std::string &name, const CaloCalibrationHit *CalibHit)
FCal Analysis with Calibration Hits on Added by JPA, June 2005.
void FCalHitCenter(const LArHitContainer *container, const CaloDetDescrManager *caloMgr)
Calculate FCal hit center.
std::vector< double > * m_hit_ieta2
StatusCode doCalib()
Calibration hit analysis.
std::vector< double > * m_cell3_E
std::vector< double > * m_hit_iphi3
std::vector< double > * m_hit_ieta3
std::vector< double > * m_cell1_E
virtual StatusCode finalize() override
Finalize.
void FillCellInfo(const CaloDetDescrElement *caloDDE, double energy, std::vector< double > *cell_E, std::vector< double > *hit_x, std::vector< double > *hit_y, std::vector< double > *hit_ieta, std::vector< double > *hit_iphi, int &NCell)
Fill FCal cell information.
void FCalClusterCenter(const LArHitContainer *container, const CaloDetDescrManager *caloMgr)
Calculate FCal cluster center.
void TruthImpactPosition(const HepMC::GenEvent *e)
Calculate truth impact position.
std::vector< double > * m_hit_iphi1
virtual StatusCode initialize() override
Initialize.
std::vector< double > * m_hit_y1
std::vector< double > * m_hit_x3
std::vector< double > * m_hit_x2
std::vector< double > * m_hit_y3
Hit collection.
Class to store hit energy and time in LAr cell from G4 simulation.
Definition LArHit.h:25
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual bool isValid() override final
Can the handle be successfully dereferenced?