ATLAS Offline Software
Loading...
Searching...
No Matches
egammaTruthAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
10
11
12#include "egammaTruthAlg.h"
20#include "GaudiKernel/SystemOfUnits.h"
21
24
25using Gaudi::Units::GeV;
26using Gaudi::Units::MeV;
27
28
29
30
31
32
33namespace D3PD {
34
35
41egammaTruthAlg::egammaTruthAlg (const std::string& name,
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{
66 CHECK( AthReentrantAlgorithm::initialize() );
67 CHECK( m_exten.retrieve() );
68 CHECK( m_inputKey.initialize() );
69 CHECK( m_outputKey.initialize() );
70
71 return StatusCode::SUCCESS;
72}
73
74
78StatusCode 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
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;
136 if ( (!((HepMC::is_simulation_particle(&tp) || MC::isZeroEnergyPhoton(&tp)) || ( MC::isStable(&tp) && MC::isSpecialNonInteracting(&tp)))) && MC::isStableOrSimDecayed(&tp)) 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
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
ATLAS-specific HepMC functions.
static Double_t sz
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
float m_photonEtIsoMax
Property: Maximum isolation cone energy allowed to keep a photon.
float computeIso(const xAOD::TruthParticle &tp, const xAOD::TruthParticleContainer &cont) const
Compute isolation around a particle.
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_outputKey
Property: Name of the output container.
float m_electronPtMin
Property: Minimum pt for electrons.
float m_etaMax
Property: Maximum eta.
egammaTruthAlg(const std::string &name, ISvcLocator *svcloc)
Standard Gaudi algorithm constructor.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_inputKey
Property: Name of the input container.
float m_isoCone
Property: Isolation cone width.
std::string m_auxPrefix
Property: Prefix to add to aux data items.
StatusCode findImpact(const xAOD::TruthParticle &tp, float &etaCalo, float &phiCalo, float &depthCalo) const
Find the impact of a particle in the calorimeter.
virtual StatusCode execute(const EventContext &ctx) const override
Standard Gaudi execute method.
bool isAccepted(const xAOD::TruthParticle &tp, const xAOD::TruthParticleContainer &cont, float &iso) const
Test to see if we accept a particle.
ToolHandle< Trk::IParticleCaloExtensionTool > m_exten
Property: Extrapolation tool to calorimeter.
virtual StatusCode initialize() override
Standard Gaudi initialize method.
float m_photonPtMin
Property: Minimum pt for photons.
int pdgId() const
PDG ID code.
#define DECOR(TYPE, N)
Select egtruth particles.
void entryExitPerLayerVector(const Trk::CaloExtension &extension, EntryExitPerLayerVector &result, const LayersToSelect *selection=nullptr)
std::vector< std::tuple< CaloSampling::CaloSample, Amg::Vector3D, Amg::Vector3D > > EntryExitPerLayerVector
Block filler tool for noisy FEB information.
int uniqueID(const T &p)
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same 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...
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
bool isZeroEnergyPhoton(const T &p)
Identify a photon with zero energy. Probably a workaround for a generator bug.
bool isStableOrSimDecayed(const T &p)
Identify if particle is satble or decayed in simulation.
bool isPhoton(const T &p)
static const int PHOTON
bool isSpecialNonInteracting(const T &p)
Identify a special non-interacting particles.
static const int ELECTRON
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.