ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagDiscriminants
src
SoftElectronTruthDecoratorAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include "
FlavorTagDiscriminants/SoftElectronTruthDecoratorAlg.h
"
7
#include "
FlavorTagDiscriminants/TruthDecoratorHelpers.h
"
8
9
#include "
StoreGate/WriteDecorHandle.h
"
10
#include "
StoreGate/ReadDecorHandle.h
"
11
12
#include "
InDetTrackSystematicsTools/InDetTrackTruthOriginDefs.h
"
13
14
#include "
xAODEgamma/ElectronContainer.h
"
15
#include "
xAODEgamma/EgammaxAODHelpers.h
"
16
17
#include "
xAODTruth/TruthVertex.h
"
18
#include "
xAODTruth/TruthVertexContainer.h
"
19
20
#include "
TruthUtils/MagicNumbers.h
"
21
22
namespace
FlavorTagDiscriminants
{
23
24
SoftElectronTruthDecoratorAlg::SoftElectronTruthDecoratorAlg
(
25
const
std::string& name, ISvcLocator* loc )
26
:
AthReentrantAlgorithm
(name, loc) {}
27
28
StatusCode
SoftElectronTruthDecoratorAlg::initialize
() {
29
ATH_MSG_DEBUG
(
"Initializing "
<< name() <<
"... "
);
30
31
// Initialize Container keys
32
ATH_MSG_DEBUG
(
"Initializing containers:"
);
33
ATH_MSG_DEBUG
(
" ** "
<<
m_ElectronContainerKey
);
34
35
ATH_CHECK
(
m_ElectronContainerKey
.initialize() );
36
ATH_CHECK
(
m_truthParticleContainerKey
.initialize() );
37
38
// Initialise accessors
39
ATH_CHECK
(
m_acc_origin_label
.initialize() );
40
ATH_CHECK
(
m_acc_type_label
.initialize() );
41
ATH_CHECK
(
m_acc_source_label
.initialize() );
42
ATH_CHECK
(
m_acc_vertex_index
.initialize() );
43
ATH_CHECK
(
m_acc_parent_uniqueID
.initialize() );
44
45
// Initialise decorators
46
ATH_CHECK
(
m_dec_origin_label
.initialize() );
47
ATH_CHECK
(
m_dec_type_label
.initialize() );
48
ATH_CHECK
(
m_dec_source_label
.initialize() );
49
ATH_CHECK
(
m_dec_vertex_index
.initialize() );
50
ATH_CHECK
(
m_dec_uniqueID
.initialize() );
51
ATH_CHECK
(
m_dec_parent_uniqueID
.initialize() );
52
53
ATH_CHECK
(
m_truthParticleLinkKey
.initialize() );
54
ATH_CHECK
(
m_classifierParticleTypeKey
.initialize() );
55
// ATLASRECTS-8290: this is for backward compatability, remove eventually
56
if
(
m_use_barcode
) {
57
m_uidKey
=
"barcode"
;
58
}
59
ATH_CHECK
(
m_uidKey
.initialize() );
60
61
return
StatusCode::SUCCESS;
62
}
63
64
StatusCode
SoftElectronTruthDecoratorAlg::execute
(
const
EventContext& ctx)
const
{
65
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"... "
);
66
67
using
EC =
xAOD::ElectronContainer
;
68
69
// read collections
70
SG::ReadHandle<EC>
electrons(
m_ElectronContainerKey
,ctx);
71
ATH_CHECK
( electrons.isValid() );
72
ATH_MSG_DEBUG
(
"Retrieved "
<< electrons->size() <<
" electrons..."
);
73
74
// instantiate accessors
75
using
RDH =
SG::ReadDecorHandle<xAOD::TruthParticleContainer, int>
;
76
RDH acc_origin_label(
m_acc_origin_label
, ctx);
77
RDH acc_type_label(
m_acc_type_label
, ctx);
78
RDH acc_source_label(
m_acc_source_label
, ctx);
79
RDH acc_vertex_index(
m_acc_vertex_index
, ctx);
80
RDH acc_parent_uniqueID(
m_acc_parent_uniqueID
, ctx);
81
82
SG::ReadDecorHandle<xAOD::ElectronContainer, ElementLink<xAOD::TruthParticleContainer>
> truthParticleLink(
m_truthParticleLinkKey
, ctx);
83
SG::ReadDecorHandle<xAOD::TruthParticleContainer, unsigned int>
classifierParticleType(
m_classifierParticleTypeKey
, ctx);
84
SG::ReadDecorHandle<xAOD::TruthParticleContainer, int>
uid(
m_uidKey
, ctx);
85
86
// instantiate decorators
87
using
WDH =
SG::WriteDecorHandle<EC, int>
;
88
WDH dec_origin_label(
m_dec_origin_label
, ctx);
89
WDH dec_type_label(
m_dec_type_label
, ctx);
90
WDH dec_source_label(
m_dec_source_label
, ctx);
91
WDH dec_vertex_index(
m_dec_vertex_index
, ctx);
92
WDH dec_uniqueID(
m_dec_uniqueID
, ctx);
93
WDH dec_parent_uniqueID(
m_dec_parent_uniqueID
, ctx);
94
95
std::vector<const xAOD::Electron*> el_vector(electrons->begin(), electrons->end());
96
for
(
const
auto
& electron : el_vector ) {
97
98
// get the linked truth particle
99
const
auto
truth_link = truthParticleLink(*electron);
100
101
if
(!truth_link || !truth_link.isValid()) {
102
// if the truth link is broken, assume PU
103
dec_origin_label(*electron) =
InDet::ExclusiveOrigin::Pileup
;
104
dec_type_label(*electron) = TruthDecoratorHelpers::TruthType::Label::NoTruth;
105
dec_source_label(*electron) = TruthDecoratorHelpers::TruthSource::Label::NoTruth;
106
dec_vertex_index(*electron) = -2;
107
dec_uniqueID(*electron) =
HepMC::UNDEFINED_ID
;
108
dec_parent_uniqueID(*electron) =
HepMC::UNDEFINED_ID
;
109
}
else
{
110
const
auto
*truth = *truth_link;
111
int
electron_type = classifierParticleType(*truth);
112
113
if
(
m_valid_types
.count(electron_type)) {
114
dec_origin_label(*electron) = acc_origin_label(*truth);
115
}
116
else
{
117
dec_origin_label(*electron) =
InDet::ExclusiveOrigin::Fake
;
118
}
119
120
dec_vertex_index(*electron) = acc_vertex_index(*truth);
121
dec_type_label(*electron) = acc_type_label(*truth);
122
dec_source_label(*electron) = acc_source_label(*truth);
123
// ATLASRECTS-8290: replace uid with ->uid() eventually
124
dec_uniqueID(*electron) = uid(*truth);
125
dec_parent_uniqueID(*electron) = acc_parent_uniqueID(*truth);
126
}
127
}
128
return
StatusCode::SUCCESS;
129
}
130
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
EgammaxAODHelpers.h
ElectronContainer.h
InDetTrackTruthOriginDefs.h
MagicNumbers.h
SoftElectronTruthDecoratorAlg.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TruthDecoratorHelpers.h
TruthVertexContainer.h
TruthVertex.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_uidKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_uidKey
Definition
SoftElectronTruthDecoratorAlg.h:102
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_valid_types
const std::set< int > m_valid_types
Definition
SoftElectronTruthDecoratorAlg.h:87
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_classifierParticleTypeKey
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_classifierParticleTypeKey
Definition
SoftElectronTruthDecoratorAlg.h:98
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_origin_label
RDHK m_acc_origin_label
Definition
SoftElectronTruthDecoratorAlg.h:43
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_ElectronContainerKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_ElectronContainerKey
Definition
SoftElectronTruthDecoratorAlg.h:34
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_use_barcode
Gaudi::Property< bool > m_use_barcode
Definition
SoftElectronTruthDecoratorAlg.h:90
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_truthParticleContainerKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
Definition
SoftElectronTruthDecoratorAlg.h:37
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_vertex_index
RDHK m_acc_vertex_index
Definition
SoftElectronTruthDecoratorAlg.h:52
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition
SoftElectronTruthDecoratorAlg.cxx:64
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_type_label
WDHK m_dec_type_label
Definition
SoftElectronTruthDecoratorAlg.h:64
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_uniqueID
WDHK m_dec_uniqueID
Definition
SoftElectronTruthDecoratorAlg.h:73
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_parent_uniqueID
RDHK m_acc_parent_uniqueID
Definition
SoftElectronTruthDecoratorAlg.h:55
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_source_label
RDHK m_acc_source_label
Definition
SoftElectronTruthDecoratorAlg.h:49
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_origin_label
WDHK m_dec_origin_label
Definition
SoftElectronTruthDecoratorAlg.h:61
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::SoftElectronTruthDecoratorAlg
SoftElectronTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
SoftElectronTruthDecoratorAlg.cxx:24
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_vertex_index
WDHK m_dec_vertex_index
Definition
SoftElectronTruthDecoratorAlg.h:70
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
SoftElectronTruthDecoratorAlg.cxx:28
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_parent_uniqueID
WDHK m_dec_parent_uniqueID
Definition
SoftElectronTruthDecoratorAlg.h:76
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_dec_source_label
WDHK m_dec_source_label
Definition
SoftElectronTruthDecoratorAlg.h:67
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_truthParticleLinkKey
SG::ReadDecorHandleKey< xAOD::ElectronContainer > m_truthParticleLinkKey
Definition
SoftElectronTruthDecoratorAlg.h:95
FlavorTagDiscriminants::SoftElectronTruthDecoratorAlg::m_acc_type_label
RDHK m_acc_type_label
Definition
SoftElectronTruthDecoratorAlg.h:46
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
FlavorTagDiscriminants
Definition
CaloChargedFlowDecoratorAlg.h:15
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
InDet::ExclusiveOrigin::Fake
@ Fake
Definition
InDetTrackTruthOriginDefs.h:17
InDet::ExclusiveOrigin::Pileup
@ Pileup
Definition
InDetTrackTruthOriginDefs.h:16
xAOD::ElectronContainer
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
Definition
Event/xAOD/xAODEgamma/xAODEgamma/ElectronContainer.h:17
Generated on
for ATLAS Offline Software by
1.17.0