Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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$
14 #include "PhotonTruthTool.h"
15 #include "xAODEgamma/Photon.h"
18 #include <vector>
19 #include <cmath>
20 
21 namespace 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 {
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 
75 bool
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 
204 bool
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 
232 const xAOD::TruthVertex*
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 
252 const xAOD::TruthParticle*
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 
267 std::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
grepfile.info
info
Definition: grepfile.py:38
D3PD::PhotonTruthTool::getMothers
std::vector< const xAOD::TruthParticle * > getMothers(const xAOD::TruthParticle *p) const
Return list of mother particles of p.
Definition: PhotonTruthTool.cxx:268
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
D3PD::PhotonTruthTool::getMotherVert
const xAOD::TruthVertex * getMotherVert(const xAOD::TruthParticle *p) const
Get the mother vertex for p.
Definition: PhotonTruthTool.cxx:233
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
D3PD::PhotonTruthTool::isQuarkBremMC
bool isQuarkBremMC(const xAOD::TruthParticle *truePart) const
Test for a brem.
Definition: PhotonTruthTool.cxx:180
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
D3PD::PhotonTruthTool::isPromptParticleMC
bool isPromptParticleMC(const xAOD::TruthParticle *truePart) const
Test for a prompt particle.
Definition: PhotonTruthTool.cxx:144
D3PD::PhotonTruthTool::getMother
const xAOD::TruthParticle * getMother(const xAOD::TruthParticle *p) const
Get the (first) mother particle of p.
Definition: PhotonTruthTool.cxx:253
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
PhotonTruthTool.h
Helpers to categorize photon TruthParticle's.
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:355
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
Photon.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
D3PD::PhotonTruthTool::getMCConv
bool getMCConv(const xAOD::TruthParticle *truePart, float &RconvMC, float &ZconvMC) const
Check a truth particle for a conversion.
Definition: PhotonTruthTool.cxx:76
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::TruthParticle_v1::decayVtx
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
D3PD::PhotonTruthTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: PhotonTruthTool.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
D3PD::PhotonTruthTool::isFinalState
bool isFinalState(const xAOD::TruthParticle *truePart) const
Test for a final-state particle.
Definition: PhotonTruthTool.cxx:205
python.PyAthena.v
v
Definition: PyAthena.py:154
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
xAOD::Photon_v1
Definition: Photon_v1.h:37
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
D3PD::PhotonTruthTool::m_useG4Particles
bool m_useG4Particles
Property.
Definition: PhotonTruthTool.h:119
D3PD::PhotonTruthTool::m_zTruthConv
float m_zTruthConv
Property: Conversion vertex z cut.
Definition: PhotonTruthTool.h:113
D3PD::PhotonTruthTool::isFinalStatePhotonMC
bool isFinalStatePhotonMC(const xAOD::TruthParticle *truePart) const
Test for a final-state photon.
Definition: PhotonTruthTool.cxx:195
D3PD::PhotonTruthTool::m_classifier
ToolHandle< IMCTruthClassifier > m_classifier
Property: classifier tool.
Definition: PhotonTruthTool.h:110
D3PD::PhotonTruthTool::PhotonTruthTool
PhotonTruthTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: PhotonTruthTool.cxx:30
AthAlgTool
Definition: AthAlgTool.h:26
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49
D3PD::PhotonTruthTool::toTruthParticle
const xAOD::TruthParticle * toTruthParticle(const xAOD::Photon &g) const
Go from a photon to a matching TruthParticle.
Definition: PhotonTruthTool.cxx:60
D3PD::PhotonTruthTool::m_rTruthConv
float m_rTruthConv
Property: Conversion vertex r cut.
Definition: PhotonTruthTool.h:116
HepMCHelpers.h
D3PD::PhotonTruthTool::isPromptPhotonMC
bool isPromptPhotonMC(const xAOD::TruthParticle *truePart) const
Test for a prompt photon.
Definition: PhotonTruthTool.cxx:134