ATLAS Offline Software
Loading...
Searching...
No Matches
PhotonTruthTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id$
12
13
14#include "PhotonTruthTool.h"
15#include "xAODEgamma/Photon.h"
18#include <vector>
19#include <cmath>
20
21namespace D3PD {
22
23
31 const std::string& name,
32 const IInterface* parent)
33 : AthAlgTool (type, name, parent),
34 m_classifier ("MCTruthClassifier")
35{
36 declareProperty ("Classifier", m_classifier, "Classifier tool instance.");
37 declareProperty ("ZTruthConv", m_zTruthConv = 50e3);
38 declareProperty ("RTruthConv", m_rTruthConv = 800);
39 declareProperty ("UseG4Particles", m_useG4Particles = false);
40}
41
42
47{
48 CHECK( AthAlgTool::initialize() );
49 CHECK( m_classifier.retrieve() );
50 return StatusCode::SUCCESS;
51}
52
53
61{
62 return std::get<2>(m_classifier->particleTruthClassifier_full(&g));
63}
64
65
73bool
75 float& RconvMC,
76 float& ZconvMC) const
77{
78 RconvMC = +9.999e+10 ;
79 ZconvMC = +9.999e+10 ;
80 if (!truePart) return false;
81
82 const xAOD::TruthVertex* v = truePart->decayVtx();
83 if (!v || v->nOutgoingParticles() < 2)
84 return false;
85
86 int pdgId = truePart->pdgId();
87
88 RconvMC = v->perp();
89 ZconvMC = v->z();
90
91 bool OKint = ( RconvMC < m_rTruthConv ) && ( fabs(ZconvMC) < m_zTruthConv );
92
93 if ( pdgId == 22 ) { // photon
94 if ( v->nOutgoingParticles() == 2 ) {
95 int pdgChild[2] = {0};
96 for ( unsigned u=0; u<2 ; ++u) {
97 const xAOD::TruthParticle* p = v->outgoingParticle(u);
98 if (p)
99 pdgChild[u] = p->pdgId();
100 }
101 if ( pdgChild[0]+pdgChild[1]==0 && pdgChild[0]*pdgChild[1]==-121 ) {
102 // gamma -> e+e-
103 return OKint ;
104 }
105 }
106 }
107 else if ( std::abs(pdgId) == 11 ) { // e+/e-
108 v = truePart->prodVtx();
109 if ( v->nIncomingParticles()==1 && v->nOutgoingParticles()==2 ) {
110 int pdgBrother[2] = {0};
111 for ( unsigned u=0 ; u<2 ; ++u ) {
112 const xAOD::TruthParticle* p = v->outgoingParticle(u);
113 if (p)
114 pdgBrother[u] = p->pdgId();
115 }
116 if ( pdgBrother[0]+pdgBrother[1]==(22+pdgId) &&
117 pdgBrother[0]*pdgBrother[1]==(22*pdgId) )
118 {
119 // e(+/-) -> e(+/-)gamma
120 return OKint ;
121 }
122 }
123 }
124 return false ;
125}
126
127
132 (const xAOD::TruthParticle* truePart) const
133{
134 return ( isFinalStatePhotonMC(truePart) && isPromptParticleMC(truePart) ) ;
135}
136
137
142 (const xAOD::TruthParticle* truePart) const
143{
144 if ( truePart == 0 ) return false ;
145 const std::vector<const xAOD::TruthParticle*> mothers =
146 getMothers(truePart);
147 unsigned nmothers = mothers.size() ;
148 if ( nmothers == 0 ) {
149 // particles with NO mother are NEVER classified as PROMPT:
150 return false ;
151 }
152 else if ( nmothers == 1 ) {
153 // particles with ONE mother are classified as PROMPT if coming
154 // from non-QCD-boson decay:
155 // (including exotics like heavy bosons, MSSM Higgs, graviton)
156 int aPdgMother = abs(mothers[0]->pdgId());
157 return (( aPdgMother>=23 && aPdgMother<=39 ) || aPdgMother==5000039 ) ;
158 }
159 else {
160 // particles with more mothers are classified as PROMPT
161 // if they come from at least 1 parton:
162 // (is this sensible?)
163 int nParentPartons = 0 ;
164 for ( unsigned u=0 ; u<nmothers ; ++u ) {
165 int pdgMother = mothers[u]->pdgId() ;
166 if ( pdgMother==21 || ( std::abs(pdgMother)<7 && pdgMother!=0 ) )
167 ++nParentPartons ;
168 }
169 return ( nParentPartons >= 1 ) ;
170 }
171}
172
173
178 (const xAOD::TruthParticle* truePart) const
179{
180 if ( ! isFinalStatePhotonMC(truePart) ) return false ;
181 const std::vector<const xAOD::TruthParticle*> mothers =
182 getMothers(truePart) ;
183 if ( mothers.size() != 1 ) return false ;
184 int pdgMother = mothers[0]->pdgId() ;
185 return ( pdgMother==21 || ( std::abs(pdgMother)<7 && pdgMother!=0 ) ) ;
186}
187
188
193 (const xAOD::TruthParticle* truePart) const
194{
195 return ( isFinalState(truePart) && MC::isPhoton(truePart) ) ;
196}
197
198
202bool
204{
205 if ( truePart == nullptr ) return false;
206 if ( !MC::isStable(truePart)) return false;
207 if ( !m_useG4Particles ) return ( !HepMC::is_simulation_particle(truePart) );
208 // if it is a photon, keep it regardless of its Geant interaction
209 if ( MC::isPhoton(truePart) ) return true ;
210 // reject Geant electron from conversion
211 if ( MC::isElectron(truePart) && HepMC::is_simulation_particle(truePart) ) {
212 const xAOD::TruthParticle* mother = getMother(truePart) ;
213 if ( mother!=0 && MC::isPhoton(mother) ) return false ;
214 }
215
216 // reject particles interacted in detector
217 const xAOD::TruthVertex* v = truePart->decayVtx();
218 if (!v) return false;// should never happen, but just in case...
219 if ( v->nOutgoingParticles()>0 ) {
220 if ( v->perp()<m_rTruthConv
221 && fabs(v->z())<m_zTruthConv ) return false ;
222 }
223 return true ;
224}
225
226
232{
233 const xAOD::TruthVertex* v = p->prodVtx();
234
235 // if mother is a duplicate, try climbing up the tree by one step...
236 while (v && v->nIncomingParticles() == 1 &&
237 v->incomingParticle(0)->pdgId() == p->pdgId())
238 {
239 p = v->incomingParticle(0);
240 v = p->prodVtx();
241 }
242
243 return v;
244}
245
246
252{
253 const xAOD::TruthVertex* v = getMotherVert (p);
254
255 if (!v || v->nIncomingParticles() == 0)
256 return 0;
257
258 return v->incomingParticle(0);
259}
260
261
265std::vector<const xAOD::TruthParticle*>
267{
268 std::vector<const xAOD::TruthParticle*> out;
269 const xAOD::TruthVertex* v = getMotherVert (p);
270
271 if (v) {
272 int n = v->nIncomingParticles();
273 out.reserve (n);
274 for (int i = 0; i < n; i++)
275 out.push_back (v->incomingParticle(i));
276 }
277
278 return out;
279}
280
281
282} // namespace D3PD
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
ATLAS-specific HepMC functions.
Helpers to categorize photon TruthParticle's.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
PhotonTruthTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
ToolHandle< IMCTruthClassifier > m_classifier
Property: classifier tool.
bool isPromptPhotonMC(const xAOD::TruthParticle *truePart) const
Test for a prompt photon.
bool isQuarkBremMC(const xAOD::TruthParticle *truePart) const
Test for a brem.
bool getMCConv(const xAOD::TruthParticle *truePart, float &RconvMC, float &ZconvMC) const
Check a truth particle for a conversion.
const xAOD::TruthVertex * getMotherVert(const xAOD::TruthParticle *p) const
Get the mother vertex for p.
virtual StatusCode initialize()
Standard Gaudi initialize method.
bool isFinalStatePhotonMC(const xAOD::TruthParticle *truePart) const
Test for a final-state photon.
const xAOD::TruthParticle * getMother(const xAOD::TruthParticle *p) const
Get the (first) mother particle of p.
bool isPromptParticleMC(const xAOD::TruthParticle *truePart) const
Test for a prompt particle.
bool isFinalState(const xAOD::TruthParticle *truePart) const
Test for a final-state particle.
std::vector< const xAOD::TruthParticle * > getMothers(const xAOD::TruthParticle *p) const
Return list of mother particles of p.
bool m_useG4Particles
Property.
float m_zTruthConv
Property: Conversion vertex z cut.
float m_rTruthConv
Property: Conversion vertex r cut.
const xAOD::TruthParticle * toTruthParticle(const xAOD::Photon &g) const
Go from a photon to a matching TruthParticle.
int pdgId() const
PDG ID code.
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Block filler tool for noisy FEB information.
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...
bool isPhoton(const T &p)
bool isElectron(const T &p)
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.
Photon_v1 Photon
Definition of the current "egamma version".