ATLAS Offline Software
LArHitsTestTool.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 "LArHitsTestTool.h"
6 
7 #include "LArSimEvent/LArHit.h"
10 #include "CaloDetDescr/CaloDetDescrElement.h"
11 #include "AtlasHepMC/GenParticle.h"
12 
13 #include <TH2D.h>
14 #include <TH1.h>
15 #include <TProfile.h>
16 
17 LArHitsTestTool::LArHitsTestTool(const std::string& type, const std::string& name, const IInterface* parent)
19  m_detname("EMB"),
20  m_lar_eta(0), m_lar_phi(0),
21  m_lar_zr(0), m_lar_etaphi(0),
22  m_lar_edep_zr(0),
23  m_eta(0), m_phi(0),
24  m_zr(0), m_etaphi(0),
25  m_time(0), m_edep(0), m_log_edep(0),
26  m_edep_zr(0),
27  m_eta_cut1(0),m_phi_cut1(0),
28  m_zr_cut1(0),m_etaphi_cut1(0),
29  m_time_cut1(0),m_edep_cut1(0),
30  m_edep_zr_cut1(0),
31  m_etot(0),
32  m_edep_eta(0), m_edep_phi(0),
33  m_edep_z(0), m_edep_r(0),
34  m_etot_eta(0), m_etot_phi(0)
35 {
36  declareProperty("EDepCut", m_edep_cut=0.1);
37  declareProperty("DetectorName", m_detname="EMB");
38 }
39 
41 {
43 
44  m_path+="LAr/";
45  // all LAr detectors
46  _TH1D(m_lar_eta,"lar_eta",25,-5.,5.);
47  _SET_TITLE(m_lar_eta, "LAr hit distribution","eta","dN/deta");
48  _TH1D(m_lar_phi,"lar_phi",25,-M_PI,M_PI);
49  _SET_TITLE(m_lar_phi, "LAr hit distribution","phi","dN/dphi");
50 
51  _TH2D(m_lar_zr,"lar_zr",100,-5200.,5200.,100,0.,3000.);
52  _SET_TITLE(m_lar_zr, "LAr hit distribution","z [mm]","r [mm]");
53  _TH2D(m_lar_etaphi,"lar_etaphi",100,-5.,5.,100,-M_PI,M_PI);
54  _SET_TITLE(m_lar_etaphi, "LAr hit distribution","eta", "phi");
55  _TH2D(m_lar_edep_zr,"lar_edep_zr",100,-5200.,5200.,100,0.,3000.);
56  _SET_TITLE(m_lar_edep_zr, "LAr energy weighted hit distribution","z [mm]", "r [mm]");
57 
58  // variables specific to sub detector (root histo names have to be unique!)
59  m_path+=m_detname+"/";
60  _TH1D(m_eta,(m_detname+"_eta").c_str(),25,-5.,5.);
61  _SET_TITLE(m_eta, "hit distribution","eta","dN/deta");
62  _TH1D(m_phi,(m_detname+"_phi").c_str(),25,-M_PI,M_PI);
63  _SET_TITLE(m_phi, "hit distribution","phi","dN/dphi");
64 
65  _TH2D(m_zr,(m_detname+"_zr").c_str(),100,-5200.,5200.,100,0.,3000.);
66  _SET_TITLE(m_zr, "hit distribution","z [mm]","r [mm]");
67  _TH2D(m_etaphi,(m_detname+"_etaphi").c_str(),100,-5.,5.,100,-M_PI,M_PI);
68  _SET_TITLE(m_etaphi, "hit distribution","eta", "phi");
69  _TH1D_WEIGHTED(m_time,(m_detname+"_time").c_str(),100,0,25);
70  _SET_TITLE(m_time, "energy weighted hit distribution","t [ns]","dE/dt");
71 
72  _TH1D(m_edep,(m_detname+"_edep").c_str(),100,0,10.);
73  _SET_TITLE(m_edep, "hit distribution","edep [MeV]","dN/dE [1/MeV]");
74  _TH1D(m_log_edep,(m_detname+"_log_edep").c_str(),100,-15.,8.);
75  _SET_TITLE(m_log_edep, "logarithm of energy deposits","log(edep [MeV])","dN/dlog(E) [1/log(MeV)]");
76  _TH2D_WEIGHTED(m_edep_zr,(m_detname+"_edep_zr").c_str(),100,-5200.,5200.,100,0.,3000.);
77  _SET_TITLE(m_edep_zr, "energy weighted hit distribution","z [mm]", "r [mm]");
78 
79  // ----------------------------------------
80  _TH1D(m_eta_cut1,(m_detname+"_eta_cut").c_str(),25,-5.,5.);
81  _SET_TITLE(m_eta, "hit distribution","eta","dN/deta");
82  _TH1D(m_phi_cut1,(m_detname+"_phi_cut").c_str(),25,-M_PI,M_PI);
83  _SET_TITLE(m_phi, "hit distribution","phi","dN/dphi");
84 
85  _TH2D(m_zr_cut1,(m_detname+"_zr_cut").c_str(),100,-5200.,5200.,100,0.,3000.);
86  _SET_TITLE(m_zr, "hit distribution","z [mm]","r [mm]");
87  _TH2D(m_etaphi_cut1,(m_detname+"_etaphi_cut").c_str(),100,-5.,5.,100,-M_PI,M_PI);
88  _SET_TITLE(m_etaphi, "hit distribution","eta", "phi");
89 
90  _TH1D_WEIGHTED(m_time_cut1,(m_detname+"_time_cut").c_str(),100,0,25);
91  _SET_TITLE(m_time, "energy weighted hit distribution","t [ns]","dE/dt");
92  _TH1D(m_edep_cut1,(m_detname+"_edep_cut").c_str(),100,0,10.);
93  _SET_TITLE(m_edep_cut1, "hit distribution","edep [MeV]","dN/dE [1/MeV]");
94  _TH2D_WEIGHTED(m_edep_zr_cut1,(m_detname+"_edep_zr_cut").c_str(),100,-5200.,5200.,100,0.,3000.);
95  _SET_TITLE(m_edep_zr, "energy weighted hit distribution","z [mm]", "r [mm]");
96 
97  // ----------------------------------------
98  _TH1D(m_etot,(m_detname+"_etot").c_str(),100,0.,500.);
99  _SET_TITLE(m_etot, "distribution total energy deposit per event","E_tot [MeV]","1/dE");
100  _TH1D_WEIGHTED(m_edep_eta,(m_detname+"_edep_eta").c_str(),25,-5.,5.);
101  _SET_TITLE(m_edep_eta, "energy weighted hit distribution","eta","dE/deta");
102  _TH1D_WEIGHTED(m_edep_phi,(m_detname+"_edep_phi").c_str(),25,-M_PI,M_PI);
103  _SET_TITLE(m_edep_phi, "energy weighted hit distribution","phi","dE/deta");
104  _TH1D_WEIGHTED(m_edep_z,(m_detname+"_edep_z").c_str(),100,-5200.,5200.);
105  _SET_TITLE(m_edep_z, "energy weighted hit distribution","z [mm]","dE/dz");
106  _TH1D_WEIGHTED(m_edep_r,(m_detname+"_edep_r").c_str(),100,0.,3000.);
107  _SET_TITLE(m_edep_r, "energy weighted hit distribution","r [mm]","dE/dr");
108  _TPROFILE(m_etot_eta,(m_detname+"_etot_eta").c_str(),25,-5.,5.);
109  _SET_TITLE(m_etot_eta, "tot energy deposited per Event vs generator truth","eta","1/N dE/deta [MeV]");
110  _TPROFILE(m_etot_phi,(m_detname+"_etot_phi").c_str(),25,-M_PI,M_PI);
111  _SET_TITLE(m_etot_phi, "tot energy deposited per Event vs generator truth","phi","1/N dE/dphi [MeV]");
112 
113  return StatusCode::SUCCESS;
114 }
115 
118  ATH_CHECK(caloMgrHandle.isValid());
119  const CaloDetDescrManager* caloMgr = *caloMgrHandle;
120 
121  std::string lArkey = "LArHit"+m_detname;
122 
123  double etot=0;
124  const LArHitContainer* hitContainer = evtStore()->tryConstRetrieve<LArHitContainer>(lArkey);
125  if(hitContainer) {
126  for(const LArHit* larHit : *hitContainer) {
127  const CaloDetDescrElement* ddElement = caloMgr->get_element(larHit->cellID());
128 
129  double eta = ddElement->eta();
130  double phi = ddElement->phi();
131  double radius = ddElement->r();
132  double z = ddElement->z();
133 
134  double energy = larHit->energy();
135 
136  m_lar_eta->Fill(eta);
137  m_lar_phi->Fill(phi);
138  m_lar_zr->Fill(z,radius);
141 
142 
143  m_eta->Fill(eta);
144  m_phi->Fill(phi);
145  m_time->Fill( larHit->time(),energy);
146  m_edep->Fill( energy);
147  m_log_edep->Fill( energy > 0 ? log(energy) : -1 );
148 
149  m_zr->Fill(z,radius);
150  m_etaphi->Fill(eta,phi);
152 
155 
156  m_edep_z->Fill(z,energy);
158 
159  etot+=energy;
160 
161  if (larHit->energy()>m_edep_cut) {
162  m_eta_cut1->Fill(eta);
163  m_phi_cut1->Fill(phi);
164  m_time_cut1->Fill( larHit->time(), larHit->energy());
165  m_edep_cut1->Fill( larHit->energy());
166 
169  m_edep_zr_cut1->Fill(z,radius,larHit->energy());
170  }
171  }
172  }
173 
174  //For FastCaloSim Container with _Fast postfix, just try to retrieve, if exist, collect information from this container, it not just skip it.
175 
177  const std::string lArkey_fast="LArHit"+m_detname+"_Fast";
178 
179  const LArHitContainer* iter_fast;
180  if( evtStore()->contains<LArHitContainer>(lArkey_fast) &&
181  (evtStore()->retrieve(iter_fast,lArkey_fast)).isSuccess())
182  {
183  ATH_MSG_DEBUG ( "Read hit info from FastCaloSim Container" );
184  for(hi_fast=(*iter_fast).begin();hi_fast!=(*iter_fast).end();++hi_fast)
185  {
186  const LArHit* larHit = *hi_fast;
187  const CaloDetDescrElement* ddElement = caloMgr->get_element(larHit->cellID());
188  double eta=ddElement->eta();
189  double phi=ddElement->phi();
190  double radius=ddElement->r();
191  double z=ddElement->z();
192  double energy=larHit->energy();
193 
194  m_lar_eta->Fill(eta);
195  m_lar_phi->Fill(phi);
196  m_lar_zr->Fill(z,radius);
199 
200  m_eta->Fill(eta);
201  m_phi->Fill(phi);
202  m_time->Fill((*hi_fast)->time(),energy);
203  m_edep->Fill(energy);
205 
206  m_zr->Fill(z,radius);
207  m_etaphi->Fill(eta,phi);
209 
212 
213  m_edep_z->Fill(z,energy);
215 
216  etot+=energy;
217 
218  if((*hi_fast)->energy() > m_edep_cut)
219  {
220  m_eta_cut1->Fill(eta);
221  m_phi_cut1->Fill(phi);
222  m_time_cut1->Fill((*hi_fast)->time(),(*hi_fast)->energy());
223  m_edep_cut1->Fill((*hi_fast)->energy());
224 
227  m_edep_zr_cut1->Fill(z,radius,(*hi_fast)->energy());
228  }
229  }
230  }
231  auto primary = getPrimary();
232  if (primary) {
233  m_etot_eta->Fill(primary->momentum().eta(),etot);
234  m_etot_phi->Fill(primary->momentum().phi(),etot);
235  }
236  m_etot->Fill(etot);
237 
238  return StatusCode::SUCCESS;
239 }
LArHitsTestTool::m_edep_z
TH1 * m_edep_z
Definition: LArHitsTestTool.h:44
TH2::Fill
int Fill(double, double)
Definition: rootspy.cxx:382
LArHitsTestTool::m_edep_cut1
TH1 * m_edep_cut1
Definition: LArHitsTestTool.h:39
LArHitsTestTool::m_log_edep
TH1 * m_log_edep
Definition: LArHitsTestTool.h:35
_TPROFILE
#define _TPROFILE(var, name, nbin, xmin, xmax)
Definition: SimTestHisto.h:39
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
LArHitsTestTool::m_edep
TH1 * m_edep
Definition: LArHitsTestTool.h:35
LArHitsTestTool::m_edep_r
TH1 * m_edep_r
Definition: LArHitsTestTool.h:44
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
LArHitsTestTool::m_etaphi_cut1
TH2 * m_etaphi_cut1
Definition: LArHitsTestTool.h:38
LArHitsTestTool::m_zr
TH2 * m_zr
Definition: LArHitsTestTool.h:34
LArHitsTestTool::m_etot_phi
TH1 * m_etot_phi
Definition: LArHitsTestTool.h:45
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
LArHitsTestTool::m_edep_zr
TH2 * m_edep_zr
Definition: LArHitsTestTool.h:36
M_PI
#define M_PI
Definition: ActiveFraction.h:11
LArHit::energy
double energy() const
Definition: LArHit.h:113
LArHitContainer
Hit collection.
Definition: LArHitContainer.h:26
_SET_TITLE
#define _SET_TITLE(var, title, xaxis, yaxis)
Definition: SimTestHisto.h:93
LArHitsTestTool::m_etot_eta
TH1 * m_etot_eta
Definition: LArHitsTestTool.h:45
GenParticle.h
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
_TH1D
#define _TH1D(var, name, nbin, xmin, xmax)
Definition: SimTestHisto.h:47
LArHitsTestTool.h
AthenaHitsVector< LArHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
LArHitsTestTool::m_edep_eta
TH1 * m_edep_eta
Definition: LArHitsTestTool.h:43
LArHitsTestTool::m_edep_zr_cut1
TH2 * m_edep_zr_cut1
Definition: LArHitsTestTool.h:40
LArHitsTestTool::m_lar_phi
TH1 * m_lar_phi
Definition: LArHitsTestTool.h:28
LArHitsTestTool::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArHitsTestTool.h:48
SimTestToolBase
Definition: SimTestToolBase.h:20
StateLessPT_NewConfig.primary
primary
Definition: StateLessPT_NewConfig.py:228
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
z
#define z
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
LArHitsTestTool::m_eta_cut1
TH1 * m_eta_cut1
Definition: LArHitsTestTool.h:37
LArHitsTestTool::m_zr_cut1
TH2 * m_zr_cut1
Definition: LArHitsTestTool.h:38
test_pyathena.parent
parent
Definition: test_pyathena.py:15
_TH2D
#define _TH2D(var, name, nbinx, xmin, xmax, nbiny, ymin, ymax)
Definition: SimTestHisto.h:81
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
_TH2D_WEIGHTED
#define _TH2D_WEIGHTED(var, name, nbinx, xmin, xmax, nbiny, ymin, ymax)
Definition: SimTestHisto.h:89
LArHitsTestTool::m_eta
TH1 * m_eta
Definition: LArHitsTestTool.h:33
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
LArHitsTestTool::m_etaphi
TH2 * m_etaphi
Definition: LArHitsTestTool.h:34
LArHit::cellID
Identifier cellID() const
Definition: LArHit.h:108
_TH1D_WEIGHTED
#define _TH1D_WEIGHTED(var, name, nbin, xmin, xmax)
Definition: SimTestHisto.h:67
LArHitsTestTool::m_phi_cut1
TH1 * m_phi_cut1
Definition: LArHitsTestTool.h:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArHitsTestTool::m_phi
TH1 * m_phi
Definition: LArHitsTestTool.h:33
SimTestToolBase::getPrimary
HepMC::ConstGenParticlePtr getPrimary()
Definition: SimTestToolBase.cxx:20
LArHitsTestTool::LArHitsTestTool
LArHitsTestTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArHitsTestTool.cxx:17
LArHitsTestTool::processEvent
virtual StatusCode processEvent() override
Definition: LArHitsTestTool.cxx:116
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition: LArHit.h:25
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
LArHitsTestTool::m_edep_phi
TH1 * m_edep_phi
Definition: LArHitsTestTool.h:43
LArHit.h
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
LArHitsTestTool::m_lar_etaphi
TH2 * m_lar_etaphi
Definition: LArHitsTestTool.h:29
LArHitContainer.h
CaloDetDescrElement::z
float z() const
cell z
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:367
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArHitsTestTool::m_time_cut1
TH1 * m_time_cut1
Definition: LArHitsTestTool.h:39
LArHitsTestTool::m_edep_cut
double m_edep_cut
Definition: LArHitsTestTool.h:25
LArHitsTestTool::m_lar_edep_zr
TH2 * m_lar_edep_zr
Definition: LArHitsTestTool.h:30
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
LArHitsTestTool::initialize
virtual StatusCode initialize() override
Definition: LArHitsTestTool.cxx:40
LArHitsTestTool::m_lar_eta
TH1 * m_lar_eta
Definition: LArHitsTestTool.h:28
CaloDetDescrElement::eta
float eta() const
cell eta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:344
CaloDetDescrElement::phi
float phi() const
cell phi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:346
CaloDetDescrElement::r
float r() const
cell r
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:348
SimTestHisto::m_path
std::string m_path
Definition: SimTestHisto.h:34
LArHitsTestTool::m_detname
std::string m_detname
Definition: LArHitsTestTool.h:24
LArHitsTestTool::m_time
TH1 * m_time
Definition: LArHitsTestTool.h:35
LArHitsTestTool::m_etot
TH1 * m_etot
Definition: LArHitsTestTool.h:42
LArHitsTestTool::m_lar_zr
TH2 * m_lar_zr
Definition: LArHitsTestTool.h:29