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{
63 m_classifier->particleTruthClassifier (&g, &info);
64 return info.genPart;
65}
66
67
75bool
77 float& RconvMC,
78 float& ZconvMC) const
79{
80 RconvMC = +9.999e+10 ;
81 ZconvMC = +9.999e+10 ;
82 if (!truePart) return false;
83
84 const xAOD::TruthVertex* v = truePart->decayVtx();
85 if (!v || v->nOutgoingParticles() < 2)
86 return false;
87
88 int pdgId = truePart->pdgId();
89
90 RconvMC = v->perp();
91 ZconvMC = v->z();
92
93 bool OKint = ( RconvMC < m_rTruthConv ) && ( fabs(ZconvMC) < m_zTruthConv );
94
95 if ( pdgId == 22 ) { // photon
96 if ( v->nOutgoingParticles() == 2 ) {
97 int pdgChild[2] = {0};
98 for ( unsigned u=0; u<2 ; ++u) {
99 const xAOD::TruthParticle* p = v->outgoingParticle(u);
100 if (p)
101 pdgChild[u] = p->pdgId();
102 }
103 if ( pdgChild[0]+pdgChild[1]==0 && pdgChild[0]*pdgChild[1]==-121 ) {
104 // gamma -> e+e-
105 return OKint ;
106 }
107 }
108 }
109 else if ( std::abs(pdgId) == 11 ) { // e+/e-
110 v = truePart->prodVtx();
111 if ( v->nIncomingParticles()==1 && v->nOutgoingParticles()==2 ) {
112 int pdgBrother[2] = {0};
113 for ( unsigned u=0 ; u<2 ; ++u ) {
114 const xAOD::TruthParticle* p = v->outgoingParticle(u);
115 if (p)
116 pdgBrother[u] = p->pdgId();
117 }
118 if ( pdgBrother[0]+pdgBrother[1]==(22+pdgId) &&
119 pdgBrother[0]*pdgBrother[1]==(22*pdgId) )
120 {
121 // e(+/-) -> e(+/-)gamma
122 return OKint ;
123 }
124 }
125 }
126 return false ;
127}
128
129
134 (const xAOD::TruthParticle* truePart) const
135{
136 return ( isFinalStatePhotonMC(truePart) && isPromptParticleMC(truePart) ) ;
137}
138
139
144 (const xAOD::TruthParticle* truePart) const
145{
146 if ( truePart == 0 ) return false ;
147 const std::vector<const xAOD::TruthParticle*> mothers =
148 getMothers(truePart);
149 unsigned nmothers = mothers.size() ;
150 if ( nmothers == 0 ) {
151 // particles with NO mother are NEVER classified as PROMPT:
152 return false ;
153 }
154 else if ( nmothers == 1 ) {
155 // particles with ONE mother are classified as PROMPT if coming
156 // from non-QCD-boson decay:
157 // (including exotics like heavy bosons, MSSM Higgs, graviton)
158 int aPdgMother = abs(mothers[0]->pdgId());
159 return (( aPdgMother>=23 && aPdgMother<=39 ) || aPdgMother==5000039 ) ;
160 }
161 else {
162 // particles with more mothers are classified as PROMPT
163 // if they come from at least 1 parton:
164 // (is this sensible?)
165 int nParentPartons = 0 ;
166 for ( unsigned u=0 ; u<nmothers ; ++u ) {
167 int pdgMother = mothers[u]->pdgId() ;
168 if ( pdgMother==21 || ( std::abs(pdgMother)<7 && pdgMother!=0 ) )
169 ++nParentPartons ;
170 }
171 return ( nParentPartons >= 1 ) ;
172 }
173}
174
175
180 (const xAOD::TruthParticle* truePart) const
181{
182 if ( ! isFinalStatePhotonMC(truePart) ) return false ;
183 const std::vector<const xAOD::TruthParticle*> mothers =
184 getMothers(truePart) ;
185 if ( mothers.size() != 1 ) return false ;
186 int pdgMother = mothers[0]->pdgId() ;
187 return ( pdgMother==21 || ( std::abs(pdgMother)<7 && pdgMother!=0 ) ) ;
188}
189
190
195 (const xAOD::TruthParticle* truePart) const
196{
197 return ( isFinalState(truePart) && MC::isPhoton(truePart) ) ;
198}
199
200
204bool
206{
207 if ( truePart == nullptr ) return false;
208 if ( !MC::isStable(truePart)) return false;
209 if ( !m_useG4Particles ) return ( !HepMC::is_simulation_particle(truePart) );
210 // if it is a photon, keep it regardless of its Geant interaction
211 if ( MC::isPhoton(truePart) ) return true ;
212 // reject Geant electron from conversion
213 if ( MC::isElectron(truePart) && HepMC::is_simulation_particle(truePart) ) {
214 const xAOD::TruthParticle* mother = getMother(truePart) ;
215 if ( mother!=0 && MC::isPhoton(mother) ) return false ;
216 }
217
218 // reject particles interacted in detector
219 const xAOD::TruthVertex* v = truePart->decayVtx();
220 if (!v) return false;// should never happen, but just in case...
221 if ( v->nOutgoingParticles()>0 ) {
222 if ( v->perp()<m_rTruthConv
223 && fabs(v->z())<m_zTruthConv ) return false ;
224 }
225 return true ;
226}
227
228
234{
235 const xAOD::TruthVertex* v = p->prodVtx();
236
237 // if mother is a duplicate, try climbing up the tree by one step...
238 while (v && v->nIncomingParticles() == 1 &&
239 v->incomingParticle(0)->pdgId() == p->pdgId())
240 {
241 p = v->incomingParticle(0);
242 v = p->prodVtx();
243 }
244
245 return v;
246}
247
248
254{
255 const xAOD::TruthVertex* v = getMotherVert (p);
256
257 if (!v || v->nIncomingParticles() == 0)
258 return 0;
259
260 return v->incomingParticle(0);
261}
262
263
267std::vector<const xAOD::TruthParticle*>
269{
270 std::vector<const xAOD::TruthParticle*> out;
271 const xAOD::TruthVertex* v = getMotherVert (p);
272
273 if (v) {
274 int n = v->nIncomingParticles();
275 out.reserve (n);
276 for (int i = 0; i < n; i++)
277 out.push_back (v->incomingParticle(i));
278 }
279
280 return out;
281}
282
283
284} // 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".