ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
ParticleJetTools
src
JetTruthVertexSummaryDecoratorAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
// Decorates a jet with summary information about contained truth vertices
5
// See TruthVertexDecoratorAlg.h for more information
6
7
#include "
ParticleJetTools/FatVertex.h
"
8
#include "
JetTruthVertexSummaryDecoratorAlg.h
"
9
#include "
AthenaBaseComps/AthReentrantAlgorithm.h
"
10
#include "
StoreGate/ReadDecorHandle.h
"
11
12
#include "
xAODBase/IParticleContainer.h
"
13
#include "
xAODTruth/TruthParticleContainer.h
"
14
#include "
StoreGate/WriteDecorHandleKeyArray.h
"
15
16
17
namespace
ParticleJetTools
{
18
JetTruthVertexSummaryDecoratorAlg::JetTruthVertexSummaryDecoratorAlg
(
19
const
std::string& name, ISvcLocator* loc) :
AthReentrantAlgorithm
(name, loc) {}
20
21
StatusCode
JetTruthVertexSummaryDecoratorAlg::initialize
(){
22
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"... "
);
23
24
ATH_CHECK
(
m_TruthContainerKey
.initialize());
25
ATH_CHECK
(
m_JetContainerKey
.initialize());
26
27
m_vertexValid
=
m_TruthContainerKey
.key() +
"."
+
m_vertexValid
.key();
28
m_vertexSimpleDecayType
=
m_TruthContainerKey
.key() +
"."
+
m_vertexSimpleDecayType
.key();
29
m_vertexID
=
m_TruthContainerKey
.key() +
"."
+
m_vertexID
.key();
30
31
ATH_CHECK
(
m_vertexSimpleDecayType
.initialize());
32
ATH_CHECK
(
m_vertexValid
.initialize());
33
ATH_CHECK
(
m_vertexID
.initialize());
34
35
m_decoNumBVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumBVerts
.key();
36
m_decoNumCVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumCVerts
.key();
37
m_decoNumTauVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumTauVerts
.key();
38
m_decoNumStrangeVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumStrangeVerts
.key();
39
m_decoNumPionVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumPionVerts
.key();
40
m_decoNumMaterialIntVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumMaterialIntVerts
.key();
41
m_decoNumOtherVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumOtherVerts
.key();
42
m_decoNumVerts
=
m_JetContainerKey
.key() +
"."
+
m_decoNumVerts
.key();
43
44
ATH_CHECK
(
m_decoNumBVerts
.initialize());
45
ATH_CHECK
(
m_decoNumCVerts
.initialize());
46
ATH_CHECK
(
m_decoNumTauVerts
.initialize());
47
ATH_CHECK
(
m_decoNumStrangeVerts
.initialize());
48
ATH_CHECK
(
m_decoNumPionVerts
.initialize());
49
ATH_CHECK
(
m_decoNumMaterialIntVerts
.initialize());
50
ATH_CHECK
(
m_decoNumOtherVerts
.initialize());
51
ATH_CHECK
(
m_decoNumVerts
.initialize());
52
53
return
StatusCode::SUCCESS;
54
}
55
56
StatusCode
JetTruthVertexSummaryDecoratorAlg::execute
(
const
EventContext& ctx)
const
{
57
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"... "
);
58
59
// read collections
60
SG::ReadHandle<xAOD::TruthParticleContainer>
truth_particles(
m_TruthContainerKey
, ctx);
61
SG::ReadHandle<xAOD::JetContainer>
jets(
m_JetContainerKey
, ctx);
62
ATH_CHECK
(truth_particles.
isValid
());
63
ATH_CHECK
(jets.isValid());
64
ATH_MSG_DEBUG
(
"Retrieved "
<< truth_particles->size() <<
" truth_particles..."
);
65
66
// get jets sorted by descending pt
67
std::vector<const xAOD::Jet*> sorted_jets;
68
for
(
const
auto
jet
: *jets) { sorted_jets.push_back(
jet
); }
69
std::sort
(
70
sorted_jets.begin(), sorted_jets.end(),
71
[](
const
xAOD::Jet
* j1,
const
xAOD::Jet
* j2) {
72
return j1->pt() > j2->pt();
73
}
74
);
75
76
77
SG::ReadDecorHandle<xAOD::TruthParticleContainer, int>
acc_vertexId(
m_vertexID
, ctx);
78
SG::ReadDecorHandle<xAOD::TruthParticleContainer, int>
acc_vertexValid(
m_vertexValid
, ctx);
79
80
// Select one representative truth particle per fat vertex: the inpart
81
// (parent) particle. Inparts carry vertexValid=1 and vertexDecayID>=0,
82
// while internal chain particles carry only vertexDecayID>=0 (not valid).
83
// Since there is at most one inpart per fat vertex, this filter yields
84
// exactly one representative per vertex without needing an ID dedupe.
85
std::vector<const xAOD::TruthParticle*> tps_vec;
86
for
(
const
auto
tp : *truth_particles) {
87
if
(acc_vertexId(*tp) < 0)
continue
;
88
if
(!acc_vertexValid(*tp))
continue
;
89
tps_vec.push_back(tp);
90
}
91
92
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumBVerts(
m_decoNumBVerts
, ctx);
93
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumCVerts(
m_decoNumCVerts
, ctx);
94
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumTauVerts(
m_decoNumTauVerts
, ctx);
95
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumStrangeVerts(
m_decoNumStrangeVerts
, ctx);
96
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumPionVerts(
m_decoNumPionVerts
, ctx);
97
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumMaterialIntVerts(
m_decoNumMaterialIntVerts
, ctx);
98
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumOtherVerts(
m_decoNumOtherVerts
, ctx);
99
SG::WriteDecorHandle<xAOD::IParticleContainer, int>
decoNumVerts(
m_decoNumVerts
, ctx);
100
101
SG::ReadDecorHandle<xAOD::TruthParticleContainer, int>
acc_vertexSimpleType(
m_vertexSimpleDecayType
, ctx);
102
103
// Iterate jets in descending pT order. Each truth particle is assigned
104
// exclusively to the highest-pT jet it matches (to avoid double-counting vertices).
105
for
(
const
auto
jet
: sorted_jets){
106
std::vector<const xAOD::TruthParticle*> searched;
107
int
num_b = 0;
108
int
num_c = 0;
109
int
num_tau = 0;
110
int
num_strange = 0;
111
int
num_pion = 0;
112
int
num_material_int = 0;
113
int
num_other = 0;
114
int
num_verts = 0;
115
116
// iterate TPs and associate
117
for
(
const
xAOD::TruthParticle
* tp : tps_vec){
118
// If we only want verts in the ID, check if we sit inside the ID bounds defined by the user
119
if
(
m_onlyID
) {
120
const
xAOD::TruthVertex
* prod_vtx = tp->prodVtx();
121
if
(!tp->hasProdVtx() || !prod_vtx) {
122
searched.push_back(tp);
123
continue
;
124
}
125
if
(prod_vtx->
perp
() >
m_lxyIDThreshold
||
126
std::abs(prod_vtx->
z
()) >
m_zIDThreshold
) {
127
searched.push_back(tp);
128
continue
;
129
}
130
}
131
132
// Then check if we match to this jet
133
if
(
jet
->p4().DeltaR(tp->p4()) >
m_drThreshold
)
continue
;
134
135
searched.push_back(tp);
136
num_verts++;
137
int
simple_type_i = acc_vertexSimpleType(*tp);
138
FatVertex::SimpleVertexType
simple_type =
static_cast<
FatVertex::SimpleVertexType
>
(simple_type_i);
139
switch
(simple_type){
140
case
FatVertex::SimpleVertexType::BHadronDecay
: num_b++;
break
;
141
case
FatVertex::SimpleVertexType::CHadronDecay
: num_c++;
break
;
142
case
FatVertex::SimpleVertexType::TauDecay
: num_tau++;
break
;
143
case
FatVertex::SimpleVertexType::StrangeDecay
: num_strange++;
break
;
144
case
FatVertex::SimpleVertexType::PionDecay
: num_pion++;
break
;
145
case
FatVertex::SimpleVertexType::MaterialInteraction
: num_material_int++;
break
;
146
case
FatVertex::SimpleVertexType::OtherSecondaryVertex
: num_other++;
break
;
147
case
FatVertex::SimpleVertexType::Other
: num_other++;
break
;
148
default
:
break
;
149
}
150
}
151
// Erase everything we've searched and found to no longer care about (e.g. we've decorated it,
152
// or its not something we care about, for *speed*)
153
std::unordered_set<const xAOD::TruthParticle*> searched_set(searched.begin(), searched.end());
154
tps_vec.erase(
std::remove_if
(tps_vec.begin(), tps_vec.end(),
155
[&](
const
xAOD::TruthParticle
*
x
) { return searched_set.count(x); }),
156
tps_vec.end());
157
158
decoNumBVerts(*
jet
) = num_b;
159
decoNumCVerts(*
jet
) = num_c;
160
decoNumTauVerts(*
jet
) = num_tau;
161
decoNumStrangeVerts(*
jet
) = num_strange;
162
decoNumPionVerts(*
jet
) = num_pion;
163
decoNumMaterialIntVerts(*
jet
) = num_material_int;
164
decoNumOtherVerts(*
jet
) = num_other;
165
decoNumVerts(*
jet
) = num_verts;
166
167
}
168
return
StatusCode::SUCCESS;
169
}
170
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
AthReentrantAlgorithm.h
TruthParticleContainer.h
FatVertex.h
JetTruthVertexSummaryDecoratorAlg.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
WriteDecorHandleKeyArray.h
x
#define x
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumStrangeVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumStrangeVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:76
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumBVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumBVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:64
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_vertexSimpleDecayType
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_vertexSimpleDecayType
Definition
JetTruthVertexSummaryDecoratorAlg.h:61
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_JetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_JetContainerKey
Definition
JetTruthVertexSummaryDecoratorAlg.h:52
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
JetTruthVertexSummaryDecoratorAlg.cxx:21
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:92
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition
JetTruthVertexSummaryDecoratorAlg.cxx:56
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_lxyIDThreshold
Gaudi::Property< float > m_lxyIDThreshold
Definition
JetTruthVertexSummaryDecoratorAlg.h:40
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_drThreshold
Gaudi::Property< float > m_drThreshold
Definition
JetTruthVertexSummaryDecoratorAlg.h:32
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_onlyID
Gaudi::Property< bool > m_onlyID
Definition
JetTruthVertexSummaryDecoratorAlg.h:35
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_vertexID
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_vertexID
Definition
JetTruthVertexSummaryDecoratorAlg.h:58
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_vertexValid
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_vertexValid
Definition
JetTruthVertexSummaryDecoratorAlg.h:55
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_TruthContainerKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_TruthContainerKey
Definition
JetTruthVertexSummaryDecoratorAlg.h:49
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumMaterialIntVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumMaterialIntVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:84
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumOtherVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumOtherVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:88
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumPionVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumPionVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:80
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_zIDThreshold
Gaudi::Property< float > m_zIDThreshold
Definition
JetTruthVertexSummaryDecoratorAlg.h:45
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumTauVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumTauVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:72
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::JetTruthVertexSummaryDecoratorAlg
JetTruthVertexSummaryDecoratorAlg(const std::string &name, ISvcLocator *loc)
Definition
JetTruthVertexSummaryDecoratorAlg.cxx:18
ParticleJetTools::JetTruthVertexSummaryDecoratorAlg::m_decoNumCVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumCVerts
Definition
JetTruthVertexSummaryDecoratorAlg.h:68
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
xAOD::TruthVertex_v1::z
float z() const
Vertex longitudinal distance along the beam line form the origin.
xAOD::TruthVertex_v1::perp
float perp() const
Vertex transverse distance from the beam line.
Definition
TruthVertex_v1.cxx:164
ParticleJetTools::FatVertex::SimpleVertexType
SimpleVertexType
Definition
FatVertex.h:55
ParticleJetTools::FatVertex::SimpleVertexType::MaterialInteraction
@ MaterialInteraction
Definition
FatVertex.h:62
ParticleJetTools::FatVertex::SimpleVertexType::CHadronDecay
@ CHadronDecay
Definition
FatVertex.h:58
ParticleJetTools::FatVertex::SimpleVertexType::OtherSecondaryVertex
@ OtherSecondaryVertex
Definition
FatVertex.h:63
ParticleJetTools::FatVertex::SimpleVertexType::Other
@ Other
Definition
FatVertex.h:64
ParticleJetTools::FatVertex::SimpleVertexType::BHadronDecay
@ BHadronDecay
Definition
FatVertex.h:57
ParticleJetTools::FatVertex::SimpleVertexType::StrangeDecay
@ StrangeDecay
Definition
FatVertex.h:60
ParticleJetTools::FatVertex::SimpleVertexType::TauDecay
@ TauDecay
Definition
FatVertex.h:59
ParticleJetTools::FatVertex::SimpleVertexType::PionDecay
@ PionDecay
Definition
FatVertex.h:61
ParticleJetTools
Definition
FatVertex.h:15
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
std::remove_if
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
Definition
DVL_algorithms.h:70
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition
TruthVertex.h:15
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
IParticleContainer.h
Generated on
for ATLAS Offline Software by
1.17.0