ATLAS Offline Software
Loading...
Searching...
No Matches
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
17namespace 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
Base class for elements of a container that can have aux data.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Class providing the definition of the 4-vector interface.
Dedicated namespace for the helper functions.
const xAOD::TruthParticle * getFinalCopy(const xAOD::TruthParticle &particle)
Return the final copy of the truth particle (or same particle if no copies done)
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any)
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)
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TruthParticle_v1 TruthParticle
Typedef to implementation.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.