ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagDiscriminants
src
TrackTruthDecoratorAlg.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/TrackTruthDecoratorAlg.h
"
7
#include "
FlavorTagDiscriminants/TruthDecoratorHelpers.h
"
8
9
#include "
StoreGate/WriteDecorHandle.h
"
10
#include "
StoreGate/ReadDecorHandle.h
"
11
12
#include "
xAODTracking/TrackParticle.h
"
13
#include "
xAODTracking/TrackParticleContainer.h
"
14
15
#include "
xAODTruth/TruthVertex.h
"
16
#include "
xAODTruth/TruthVertexContainer.h
"
17
18
#include "
TruthUtils/MagicNumbers.h
"
19
20
#include "
InDetTrackSystematicsTools/InDetTrackTruthOriginDefs.h
"
21
22
23
namespace
FlavorTagDiscriminants
{
24
25
TrackTruthDecoratorAlg::TrackTruthDecoratorAlg
(
26
const
std::string& name, ISvcLocator* loc )
27
:
AthReentrantAlgorithm
(name, loc) {}
28
29
StatusCode
TrackTruthDecoratorAlg::initialize
() {
30
ATH_MSG_INFO
(
"Inizializing "
<< name() <<
"... "
);
31
32
// Initialize Container keys
33
ATH_MSG_DEBUG
(
"Inizializing containers:"
);
34
ATH_MSG_DEBUG
(
" ** "
<<
m_TrackContainerKey
);
35
ATH_MSG_DEBUG
(
" ** "
<<
m_MuonContainerKey
);
36
ATH_CHECK
(
m_TrackContainerKey
.initialize() );
37
ATH_CHECK
(
m_MuonContainerKey
.initialize() );
38
ATH_CHECK
(
m_truthParticleContainerKey
.initialize() );
39
40
// Initialize accessors
41
ATH_CHECK
(
m_acc_type_label
.initialize() );
42
ATH_CHECK
(
m_acc_source_label
.initialize() );
43
ATH_CHECK
(
m_acc_vertex_index
.initialize() );
44
ATH_CHECK
(
m_acc_parent_uniqueID
.initialize() );
45
46
// Initialize decorators
47
ATH_CHECK
(
m_dec_origin_label
.initialize() );
48
ATH_CHECK
(
m_dec_type_label
.initialize() );
49
ATH_CHECK
(
m_dec_source_label
.initialize() );
50
ATH_CHECK
(
m_dec_vertex_index
.initialize() );
51
ATH_CHECK
(
m_dec_uniqueID
.initialize() );
52
ATH_CHECK
(
m_dec_parent_uniqueID
.initialize() );
53
ATH_CHECK
(
m_dec_muon_origin_label
.initialize() );
54
55
// Retrieve tools
56
ATH_CHECK
(
m_trackTruthOriginTool
.retrieve() );
57
if
(!
m_truthLeptonTool
.empty()) {
58
ATH_CHECK
(
m_truthLeptonTool
.retrieve() );
59
}
60
61
// ATLASRECTS-8290: this should be removed eventually
62
if
(
m_use_barcode
)
m_uid
=
SG::ConstAccessor<int>
(
"barcode"
);
63
64
return
StatusCode::SUCCESS;
65
}
66
67
StatusCode
TrackTruthDecoratorAlg::execute
(
const
EventContext& ctx)
const
{
68
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"... "
);
69
using
TPC =
xAOD::TrackParticleContainer
;
70
71
// read collections
72
SG::ReadHandle<TPC>
tracks(
m_TrackContainerKey
, ctx);
73
CHECK
( tracks.
isValid
() );
74
ATH_MSG_DEBUG
(
"Retrieved "
<< tracks->size() <<
" tracks..."
);
75
SG::ReadHandle<xAOD::MuonContainer>
muons(
m_MuonContainerKey
,ctx);
76
CHECK
( tracks.
isValid
() );
77
ATH_MSG_DEBUG
(
"Retrieved "
<< muons->size() <<
" muons..."
);
78
79
// instantiate accessors
80
using
RDH =
SG::ReadDecorHandle<xAOD::TruthParticleContainer, int>
;
81
RDH acc_type_label(
m_acc_type_label
, ctx);
82
RDH acc_source_label(
m_acc_source_label
, ctx);
83
RDH acc_vertex_index(
m_acc_vertex_index
, ctx);
84
RDH acc_parent_uniqueID(
m_acc_parent_uniqueID
, ctx);
85
86
// instantiate decorators
87
using
WDH =
SG::WriteDecorHandle<TPC, 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
WDH dec_muon_origin_label(
m_dec_muon_origin_label
, ctx);
95
96
// decorate loop
97
std::vector<const xAOD::TrackParticle*> tracks_vector(tracks->begin(), tracks->end());
98
for
(
const
auto
& track : tracks_vector ) {
99
100
// for the origin label we need to start from the track object (to label fake tracks)
101
int
trackTruthOrigin =
m_trackTruthOriginTool
->getTrackOrigin(track);
102
dec_origin_label(*track) =
InDet::ExclusiveOrigin::getExclusiveOrigin
(trackTruthOrigin);
103
104
// everything else is already decorated to the associated truth particle
105
const
auto
truth =
m_trackTruthOriginTool
->getTruth(track);
106
// ATLASRECTS-8290: replace m_uid with HepMC::uniqueID
107
dec_uniqueID(*track) = truth ?
m_uid
(*truth) :
HepMC::UNDEFINED_ID
;
108
dec_parent_uniqueID(*track) = truth ? acc_parent_uniqueID(*truth) :
HepMC::UNDEFINED_ID
;
109
dec_type_label(*track) = truth ? acc_type_label(*truth) : TruthDecoratorHelpers::TruthType::Label::NoTruth;
110
dec_source_label(*track) = truth ? acc_source_label(*truth) : TruthDecoratorHelpers::TruthSource::Label::NoTruth;
111
dec_vertex_index(*track) = truth ? acc_vertex_index(*truth) : -2;
112
dec_muon_origin_label(*track) = -2;
113
114
}
115
if
( !
m_truthLeptonTool
.empty() ) {
116
117
// decorate muon tracks with truth origin
118
for
(
const
auto
muon : *muons ) {
119
120
// Check if the muon is a combined muon
121
if
(muon->muonType() != xAOD::Muon::MuonType::Combined) {
continue
; }
122
123
// Classify muon truth origin (https://gitlab.cern.ch/atlas/athena/-/tree/main/PhysicsAnalysis/AnalysisCommon/TruthClassification)
124
unsigned
int
muTruthOrigin = 0;
125
ATH_CHECK
(
m_truthLeptonTool
->classify(*muon, muTruthOrigin));
126
Truth::Type
muTruthOriginType =
static_cast<
Truth::Type
>
(muTruthOrigin);
127
128
// Get the track associated to the muon
129
auto
track = muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
130
if
( !track ) {
continue
; }
131
132
// Get the truth particle associated to the track
133
const
auto
truth =
m_trackTruthOriginTool
->getTruth(track);
134
if
( !truth ) {
continue
; }
135
136
// Get the track truth origin
137
int
trackTruthOrigin =
m_trackTruthOriginTool
->getTrackOrigin(track);
138
139
if
( abs(truth->pdgId()) != 13 ) {
140
// Check if the truth particle associated to the track is not a muon
141
muTruthOrigin = 9;
142
}
143
else
if
( muTruthOriginType == Truth::Type::CHadronDecay &&
InDet::TrkOrigin::isFromDfromB
(trackTruthOrigin) ) {
144
// Check if a muon is FromC and the associated track is FromBC
145
muTruthOrigin = 4;
146
}
147
else
if
( muTruthOriginType == Truth::Type::CHadronDecay && !
InDet::TrkOrigin::isFromDfromB
(trackTruthOrigin) ) {
148
// Check if a muon is FromC and the associated track is not FromBC
149
muTruthOrigin = 5;
150
}
151
else
{
152
// any alternative truth origin label are taken from TruthClassificationTool and mapped
153
auto
it =
m_muTruthMap
.find(muTruthOriginType);
154
if
( it !=
m_muTruthMap
.end() ){
155
muTruthOrigin = it->second;
156
}
157
else
{
158
// raise an error if the muon truth origin label is not found in the map
159
ATH_MSG_ERROR
(
"Muon truth origin not found in the map: "
<<
static_cast<
int
>
(muTruthOriginType));
160
return
StatusCode::FAILURE;
161
}
162
}
163
164
// decorate the muon track
165
dec_muon_origin_label(*track) = muTruthOrigin;
166
}
167
}
168
return
StatusCode::SUCCESS;
169
}
170
}
171
172
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TrackParticleContainer.h
TrackParticle.h
InDetTrackTruthOriginDefs.h
MagicNumbers.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TrackTruthDecoratorAlg.h
TruthDecoratorHelpers.h
TruthVertexContainer.h
TruthVertex.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_uniqueID
WDHK m_dec_uniqueID
Definition
TrackTruthDecoratorAlg.h:72
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_muTruthMap
std::unordered_map< Truth::Type, unsigned int > m_muTruthMap
Definition
TrackTruthDecoratorAlg.h:93
FlavorTagDiscriminants::TrackTruthDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
TrackTruthDecoratorAlg.cxx:29
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_use_barcode
Gaudi::Property< bool > m_use_barcode
Definition
TrackTruthDecoratorAlg.h:110
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_truthLeptonTool
ToolHandle< CP::IClassificationTool > m_truthLeptonTool
Definition
TrackTruthDecoratorAlg.h:88
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_uid
SG::ConstAccessor< int > m_uid
Definition
TrackTruthDecoratorAlg.h:113
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_muon_origin_label
WDHK m_dec_muon_origin_label
Definition
TrackTruthDecoratorAlg.h:78
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_origin_label
WDHK m_dec_origin_label
Definition
TrackTruthDecoratorAlg.h:60
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_type_label
WDHK m_dec_type_label
Definition
TrackTruthDecoratorAlg.h:63
FlavorTagDiscriminants::TrackTruthDecoratorAlg::TrackTruthDecoratorAlg
TrackTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TrackTruthDecoratorAlg.cxx:25
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_acc_source_label
RDHK m_acc_source_label
Definition
TrackTruthDecoratorAlg.h:48
FlavorTagDiscriminants::TrackTruthDecoratorAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition
TrackTruthDecoratorAlg.cxx:67
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_parent_uniqueID
WDHK m_dec_parent_uniqueID
Definition
TrackTruthDecoratorAlg.h:75
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_MuonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_MuonContainerKey
Definition
TrackTruthDecoratorAlg.h:36
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_acc_parent_uniqueID
RDHK m_acc_parent_uniqueID
Definition
TrackTruthDecoratorAlg.h:54
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_vertex_index
WDHK m_dec_vertex_index
Definition
TrackTruthDecoratorAlg.h:69
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_TrackContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_TrackContainerKey
Definition
TrackTruthDecoratorAlg.h:33
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_truthParticleContainerKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerKey
Definition
TrackTruthDecoratorAlg.h:39
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_acc_type_label
RDHK m_acc_type_label
Definition
TrackTruthDecoratorAlg.h:45
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_dec_source_label
WDHK m_dec_source_label
Definition
TrackTruthDecoratorAlg.h:66
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_trackTruthOriginTool
ToolHandle< InDet::InDetTrackTruthOriginTool > m_trackTruthOriginTool
Definition
TrackTruthDecoratorAlg.h:84
FlavorTagDiscriminants::TrackTruthDecoratorAlg::m_acc_vertex_index
RDHK m_acc_vertex_index
Definition
TrackTruthDecoratorAlg.h:51
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
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::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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::getExclusiveOrigin
int getExclusiveOrigin(int origin)
Definition
InDetTrackTruthOriginDefs.h:199
InDet::TrkOrigin::isFromDfromB
bool isFromDfromB(int origin)
from B-->D decay chain
Definition
InDetTrackTruthOriginDefs.h:150
Truth::Type
Type
truth classification type enum
Definition
ITruthClassificationTool.h:19
xAOD::TrackParticleContainer
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Definition
Event/xAOD/xAODTracking/xAODTracking/TrackParticleContainer.h:14
Generated on
for ATLAS Offline Software by
1.17.0