ATLAS Offline Software
xAODTruthHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Core EDM include(s):
6 #include "AthLinks/ElementLink.h"
8 
9 // xAOD include(s):
10 #include "xAODBase/IParticle.h"
11 
12 // Local include(s):
16 
17 namespace xAOD {
18 
19  namespace TruthHelpers {
20 
26 
29 
31  static const SG::AuxElement::ConstAccessor< Link_t > acc( "truthParticleLink" );
32 
33  // Check if such a link exists on the object:
34  if( acc.isAvailable( p ) ) {
35  // Get the link:
36  const Link_t& link = acc( p );
37 
38  // Check if the link is valid:
39  if( link.isValid() ) {
40  // Everything has passed, let's return the pointer:
41  return *link;
42  }
43  }
44 
46  static const SG::AuxElement::ConstAccessor< Link_t > acc_alt( "TruthLink" );
47 
48  // Check if such a link exists on the object:
49  if( acc_alt.isAvailable( p ) ) {
50  // Get the link:
51  const Link_t& link_alt = acc_alt( p );
52 
53  // Check if the link is valid:
54  if( link_alt.isValid() ) {
55  // Everything has passed, let's return the pointer:
56  return *link_alt;
57  }
58  }
59 
60  // Everything has failed, nothing to return
61  return nullptr;
62  }
63 
64 
70 
71  // Loop over the children
72  for( size_t i{}; i < particle.nChildren(); ++i ) {
73 
74  // Check if particle pointer exists and it is the same particle (same PDG ID)
75  if( particle.child( i ) != nullptr && particle.child( i )->pdgId() == particle.pdgId() ) {
76  // Recursively check again
77  // It is fine to return when we find first copy candidate as there can only be one
78  return getFinalCopy( *particle.child( i ) );
79  }
80  }
81 
82  // Return the same particle if no copies found
83  return &particle;
84  }
85 
86 
92 
94  static const SG::AuxElement::ConstAccessor< int > acc( "truthType" );
95 
96  // Check if such a variable exists on the object:
97  if( ! acc.isAvailable( p ) ) {
98  return 0;
99  }
100 
101  // Let's return the value:
102  return acc( p );
103  }
104 
110 
112  static const SG::AuxElement::ConstAccessor< int > acc( "truthOrigin" );
113 
114  // Check if such a variable exists on the object:
115  if( ! acc.isAvailable( p ) ) {
116  return 0;
117  }
118 
119  // Let's return the value:
120  return acc( p );
121  }
122 
123  } // namespace TruthHelpers
124 
125 } // namespace xAOD
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
IParticle.h
TruthParticleContainer.h
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAODTruthHelpers.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
xAOD::TruthHelpers::getFinalCopy
const xAOD::TruthParticle * getFinalCopy(const xAOD::TruthParticle &particle)
Return the final copy of the truth particle (or same particle if no copies done)
Definition: xAODTruthHelpers.cxx:69
xAOD::TruthHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any)
Definition: xAODTruthHelpers.cxx:25
xAOD::TruthHelpers::getParticleTruthOrigin
int getParticleTruthOrigin(const xAOD::IParticle &p)
Return the particle's truth origin (as defined by the MC Truth Classifier)
Definition: xAODTruthHelpers.cxx:109
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TruthHelpers::getParticleTruthType
int getParticleTruthType(const xAOD::IParticle &p)
Return the particle's truth type (as defined by the MC Truth Classifier)
Definition: xAODTruthHelpers.cxx:91
TruthParticle.h
AuxElement.h
Base class for elements of a container that can have aux data.