ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
xAOD
xAODTruth
Root
xAODTruthHelpers.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Core EDM include(s):
6
#include "AthLinks/ElementLink.h"
7
#include "
AthContainers/AuxElement.h
"
8
9
// xAOD include(s):
10
#include "
xAODBase/IParticle.h
"
11
12
// Local include(s):
13
#include "
xAODTruth/xAODTruthHelpers.h
"
14
#include "
xAODTruth/TruthParticle.h
"
15
#include "
xAODTruth/TruthParticleContainer.h
"
16
17
namespace
xAOD
{
18
19
namespace
TruthHelpers
{
20
25
const
xAOD::TruthParticle
*
getTruthParticle
(
const
xAOD::IParticle
& p ) {
26
28
using
Link_t
=
ElementLink<xAOD::TruthParticleContainer>
;
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
69
const
xAOD::TruthParticle
*
getFinalCopy
(
const
xAOD::TruthParticle
& particle ) {
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
91
int
getParticleTruthType
(
const
xAOD::IParticle
& p ) {
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
109
int
getParticleTruthOrigin
(
const
xAOD::IParticle
& p ) {
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
127
int
getParticleTruthClassification
(
const
xAOD::IParticle
& p ) {
128
130
static
const
SG::AuxElement::ConstAccessor< unsigned int >
acc
(
"truthClassification"
);
131
static
const
SG::AuxElement::ConstAccessor< unsigned int > accLegacy(
"Classification"
);
132
133
// Check if such a variable exists on the object:
134
if
( !
acc
.isAvailable( p ) ) {
135
if
( ! accLegacy.isAvailable( p ) ) {
136
return
0;
137
}
138
139
// Let's return the value:
140
return
accLegacy( p );
141
}
142
143
// Let's return the value:
144
return
acc
( p );
145
}
146
147
}
// namespace TruthHelpers
148
149
}
// namespace xAOD
AuxElement.h
Base class for elements of a container that can have aux data.
IParticle.h
TruthParticleContainer.h
TruthParticle.h
Link_t
ElementLink< xAOD::TruthParticleContainer > Link_t
Definition
MuonToTruthAssocAlg.cxx:14
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
ElementLink::isValid
bool isValid() const
Check if the element can be found.
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::TruthHelpers
Dedicated namespace for the helper functions.
Definition
xAODTruthHelpers.cxx:19
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::getParticleTruthClassification
int getParticleTruthClassification(const xAOD::IParticle &p)
Return the particle's truth classification (as defined by the MC Truth Classifier).
Definition
xAODTruthHelpers.cxx:127
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
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
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition
ICaloAffectedTool.h:24
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAOD::acc
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
xAODTruthHelpers.h
Generated on
for ATLAS Offline Software by
1.17.0