ATLAS Offline Software
egammaTruthAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
12 #include "egammaTruthAlg.h"
18 #include "StoreGate/ReadHandle.h"
19 #include "StoreGate/WriteHandle.h"
20 #include "GaudiKernel/SystemOfUnits.h"
21 
24 
25 using Gaudi::Units::GeV;
26 using Gaudi::Units::MeV;
27 
28 
29 
30 
31 
32 
33 namespace D3PD {
34 
35 
42  ISvcLocator* svcloc)
43  : AthReentrantAlgorithm (name, svcloc)
44 {
45  declareProperty ("AuxPrefix", m_auxPrefix,
46  "Prefix to add to aux data items.");
47 
48  declareProperty ("ElectronPtMin", m_electronPtMin = 2*GeV,
49  "Minimum pt for electrons.");
50  declareProperty ("PhotonPtMin", m_photonPtMin = 2*GeV,
51  "Minimum pt for photons.");
52  declareProperty ("EtaMax", m_etaMax = 2.5,
53  "Maximum eta.");
54  declareProperty ("IsoCone", m_isoCone = 0.2,
55  "Isolation cone width.");
56  declareProperty ("PhotonEtIsoMax", m_photonEtIsoMax = 2*MeV,
57  "Maximum isolation cone energy allowed to keep a photon.");
58 }
59 
60 
65 {
67  CHECK( m_exten.retrieve() );
69  CHECK( m_outputKey.initialize() );
70 
71  return StatusCode::SUCCESS;
72 }
73 
74 
78 StatusCode egammaTruthAlg::execute (const EventContext& ctx) const
79 {
81 
82  auto pout = std::make_unique<xAOD::TruthParticleContainer>();
83  auto pout_aux = std::make_unique<xAOD::TruthParticleAuxContainer>();
84  pout->setStore (pout_aux.get());
85 
86 #define DECOR(TYPE,N) xAOD::TruthParticle::Decorator<TYPE> N (m_auxPrefix + #N)
87  DECOR(float, etaCalo);
88  DECOR(float, phiCalo);
89  DECOR(float, depthCalo);
90  DECOR(float, Etcone20);
91 #undef DECOR
92 
93  for (const xAOD::TruthParticle* tp : *pin) {
94  float iso = -999;
95  if (isAccepted (*tp, *pin, iso)) {
96  pout->push_back (std::make_unique<xAOD::TruthParticle>());
97  *pout->back() = *tp;
98 
99  CHECK( findImpact (*tp,
100  etaCalo(*pout->back()),
101  phiCalo(*pout->back()),
102  depthCalo(*pout->back())) );
103  Etcone20(*pout->back()) = iso;
104  }
105  }
106 
108  CHECK( output.record (std::move(pout), std::move(pout_aux)) );
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 
121  const xAOD::TruthParticleContainer& cont,
122  float& iso) const
123 {
124  iso = -999;
125 
126  int id = tp.pdgId();
127  int aid = abs(id);
128  int uniqueID = HepMC::uniqueID(tp);
129 
130  if (aid != abs(MC::ELECTRON) && !MC::isPhoton(aid)) return false;
131  if (aid == abs(MC::ELECTRON) && tp.pt() < m_electronPtMin) return false;
132  if (MC::isPhoton(aid) && tp.pt() < m_photonPtMin) return false;
133 
134 
135  if (fabs(tp.eta()) > m_etaMax) return false;
137 
138  // Remove electrons/gammas decaying into themselves
139  if( tp.hasDecayVtx() ) {
140  const xAOD::TruthVertex* v = tp.decayVtx();
141  size_t sz = v->nOutgoingParticles();
142  for (size_t i = 0; i < sz; i++) {
143  const xAOD::TruthParticle* child = v->outgoingParticle(i);
144  if( child && child->pdgId()==id && HepMC::uniqueID(child) != uniqueID
145  && (HepMC::generations(child) == 0))
146  {
147  return false;
148  }
149  }
150  } // end decays into themselves
151 
152  // Isolation selection for photons.
153  iso = computeIso (tp, cont);
154  if (aid == abs(MC::PHOTON)) {
155  if (iso > m_photonEtIsoMax)
156  return false;
157  }
158 
159  return true;
160 }
161 
162 
169  const xAOD::TruthParticleContainer& cont) const
170 {
171  TLorentzVector sum;
172  for (const xAOD::TruthParticle* p : cont) {
173  if (p == &tp || HepMC::is_same_particle(p,tp)) continue;
175  if (tp.p4().DeltaR (p->p4()) < m_isoCone)
176  sum += p->p4();
177  }
178 
179  return sum.Pt();
180 }
181 
182 
192  float& etaCalo,
193  float& phiCalo,
194  float& depthCalo) const
195 {
196  etaCalo = -999;
197  phiCalo = -999;
198  depthCalo = -999;
199 
200  std::unique_ptr<Trk::CaloExtension> extension =
201  m_exten->caloExtension(Gaudi::Hive::currentContext(), tp);
202  if (!extension) {
203  REPORT_MESSAGE (MSG::ERROR) << "Extension to calorimeter failed";
204  return StatusCode::FAILURE;
205  }
206 
209  for (const auto& [sampling, entry, exit] : lvec) {
210  if (sampling == CaloSampling::EMB2) {
211  etaCalo = entry.eta();
212  phiCalo = entry.phi();
213  depthCalo = entry.perp();
214  break;
215  }
216  else if (sampling == CaloSampling::EME2) {
217  etaCalo = entry.eta();
218  phiCalo = entry.phi();
219  depthCalo = std::abs(entry.z());
220  }
221  }
222 
223  return StatusCode::SUCCESS;
224 }
225 
226 
227 } // namespace D3PD
D3PD::egammaTruthAlg::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Definition: egammaTruthAlg.cxx:64
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
calibdata.pout
def pout(output, newline=True)
Definition: calibdata.py:130
fitman.sz
sz
Definition: fitman.py:527
CaloExtensionHelpers.h
MC::isSpecialNonInteracting
bool isSpecialNonInteracting(const T &p)
Identify a special non-interacting particles.
Definition: HepMCHelpers.h:83
D3PD::egammaTruthAlg::m_exten
ToolHandle< Trk::IParticleCaloExtensionTool > m_exten
Property: Extrapolation tool to calorimeter.
Definition: egammaTruthAlg.h:118
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
D3PD::egammaTruthAlg::m_auxPrefix
std::string m_auxPrefix
Property: Prefix to add to aux data items.
Definition: egammaTruthAlg.h:91
initialize
void initialize()
Definition: run_EoverP.cxx:894
TruthParticleContainer.h
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
CaloExtension.h
ParticleTest.tp
tp
Definition: ParticleTest.py:25
D3PD::egammaTruthAlg::isAccepted
bool isAccepted(const xAOD::TruthParticle &tp, const xAOD::TruthParticleContainer &cont, float &iso) const
Test to see if we accept a particle.
Definition: egammaTruthAlg.cxx:120
D3PD::egammaTruthAlg::m_etaMax
float m_etaMax
Property: Maximum eta.
Definition: egammaTruthAlg.h:108
DECOR
#define DECOR(TYPE, N)
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:354
D3PD::egammaTruthAlg::m_photonEtIsoMax
float m_photonEtIsoMax
Property: Maximum isolation cone energy allowed to keep a photon.
Definition: egammaTruthAlg.h:114
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
D3PD::egammaTruthAlg::m_outputKey
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_outputKey
Property: Name of the output container.
Definition: egammaTruthAlg.h:99
TruthParticleAuxContainer.h
WriteHandle.h
Handle class for recording to StoreGate.
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
D3PD::egammaTruthAlg::m_photonPtMin
float m_photonPtMin
Property: Minimum pt for photons.
Definition: egammaTruthAlg.h:105
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition: MagicNumbers.h:342
egammaTruthAlg.h
Select egtruth particles.
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
D3PD::egammaTruthAlg::egammaTruthAlg
egammaTruthAlg(const std::string &name, ISvcLocator *svcloc)
Standard Gaudi algorithm constructor.
Definition: egammaTruthAlg.cxx:41
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:109
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::egammaTruthAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Standard Gaudi execute method.
Definition: egammaTruthAlg.cxx:78
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CaloExtensionHelpers::EntryExitPerLayerVector
std::vector< std::tuple< CaloSampling::CaloSample, Amg::Vector3D, Amg::Vector3D > > EntryExitPerLayerVector
Definition: CaloExtensionHelpers.h:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
calibdata.exit
exit
Definition: calibdata.py:236
merge.output
output
Definition: merge.py:17
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MagicNumbers.h
D3PD::egammaTruthAlg::m_isoCone
float m_isoCone
Property: Isolation cone width.
Definition: egammaTruthAlg.h:111
CaloExtensionHelpers::entryExitPerLayerVector
void entryExitPerLayerVector(const Trk::CaloExtension &extension, EntryExitPerLayerVector &result, const LayersToSelect *selection=nullptr)
Definition: CaloExtensionHelpers.h:178
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
IParticleCaloExtensionTool.h
MC::isStableOrSimDecayed
bool isStableOrSimDecayed(const T &p)
Identify if particle is satble or decayed in simulation.
Definition: HepMCHelpers.h:65
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
D3PD::egammaTruthAlg::m_inputKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_inputKey
Property: Name of the input container.
Definition: egammaTruthAlg.h:95
ReadHandle.h
Handle class for reading from StoreGate.
MC::isZeroEnergyPhoton
bool isZeroEnergyPhoton(const T &p)
Identify a photon with zero energy. Probably a workaround for a generator bug.
Definition: HepMCHelpers.h:71
HepMC::generations
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
Definition: MagicNumbers.h:345
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
D3PD::egammaTruthAlg::computeIso
float computeIso(const xAOD::TruthParticle &tp, const xAOD::TruthParticleContainer &cont) const
Compute isolation around a particle.
Definition: egammaTruthAlg.cxx:168
D3PD::egammaTruthAlg::m_electronPtMin
float m_electronPtMin
Property: Minimum pt for electrons.
Definition: egammaTruthAlg.h:102
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
HepMCHelpers.h
D3PD::egammaTruthAlg::findImpact
StatusCode findImpact(const xAOD::TruthParticle &tp, float &etaCalo, float &phiCalo, float &depthCalo) const
Find the impact of a particle in the calorimeter.
Definition: egammaTruthAlg.cxx:191