ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::TruthHelpers Namespace Reference

Dedicated namespace for the helper functions. More...

Functions

const xAOD::TruthParticlegetTruthParticle (const xAOD::IParticle &p)
 Return the truthParticle associated to the given IParticle (if any)
const xAOD::TruthParticlegetFinalCopy (const xAOD::TruthParticle &particle)
 Return the final copy of the truth particle (or same particle if no copies done)
int getParticleTruthType (const xAOD::IParticle &p)
 Return the particle's truth type (as defined by the MC Truth Classifier)
int getParticleTruthOrigin (const xAOD::IParticle &p)
 Return the particle's truth origin (as defined by the MC Truth Classifier)

Detailed Description

Dedicated namespace for the helper functions.

Function Documentation

◆ getFinalCopy()

const TruthParticle * xAOD::TruthHelpers::getFinalCopy ( const xAOD::TruthParticle & particle)

Return the final copy of the truth particle (or same particle if no copies done)

Parameters
particleThe truth particle we want to get the final copy of
Returns
A pointer to the final truth particle copy if available, or pointer to the same particle if no copies done.

Definition at line 69 of file xAODTruthHelpers.cxx.

69 {
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 }
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
const xAOD::TruthParticle * getFinalCopy(const xAOD::TruthParticle &particle)
Return the final copy of the truth particle (or same particle if no copies done)

◆ getParticleTruthOrigin()

int xAOD::TruthHelpers::getParticleTruthOrigin ( const xAOD::IParticle & p)

Return the particle's truth origin (as defined by the MC Truth Classifier)

Parameters
pThe particle that we want to find the truth origin of
Returns
0 if the truth origin is not available, or the truth origin determined by MCTruthClassifier, if it is

A static accessor for the information

Definition at line 109 of file xAODTruthHelpers.cxx.

109 {
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 }
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.

◆ getParticleTruthType()

int xAOD::TruthHelpers::getParticleTruthType ( const xAOD::IParticle & p)

Return the particle's truth type (as defined by the MC Truth Classifier)

Parameters
pThe particle that we want to find the truth type of
Returns
0 if the truth type is not available, or the truth type determined by MCTruthClassifier, if it is

A static accessor for the information

Definition at line 91 of file xAODTruthHelpers.cxx.

91 {
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 }

◆ getTruthParticle()

const TruthParticle * xAOD::TruthHelpers::getTruthParticle ( const xAOD::IParticle & p)

Return the truthParticle associated to the given IParticle (if any)

Parameters
pThe particle that we find the associated truth particle for
Returns
A pointer to the associated truth particle if available, or a null pointer if not

A convenience type declaration

A static accessor for the information

Alternative name - this may work in case of TRUTH3 / small truth collections

Definition at line 25 of file xAODTruthHelpers.cxx.

25 {
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 }