ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
15
16
17namespace ParticleJetTools{
19 const std::string& name, ISvcLocator* loc) : AthReentrantAlgorithm(name, loc) {}
20
22 ATH_MSG_INFO("Initializing " << name() << "... ");
23
24 ATH_CHECK(m_TruthContainerKey.initialize());
25 ATH_CHECK(m_JetContainerKey.initialize());
26
29 m_vertexID = m_TruthContainerKey.key() + "." + m_vertexID.key();
30
32 ATH_CHECK(m_vertexValid.initialize());
33 ATH_CHECK(m_vertexID.initialize());
34
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());
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
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); }
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
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
100
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){
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;
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
#define x
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumStrangeVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumBVerts
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_vertexSimpleDecayType
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumVerts
virtual StatusCode execute(const EventContext &) const override
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_vertexID
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_vertexValid
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_TruthContainerKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumMaterialIntVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumOtherVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumPionVerts
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumTauVerts
JetTruthVertexSummaryDecoratorAlg(const std::string &name, ISvcLocator *loc)
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decoNumCVerts
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
float z() const
Vertex longitudinal distance along the beam line form the origin.
float perp() const
Vertex transverse distance from the beam line.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
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.
Jet_v1 Jet
Definition of the current "jet version".
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.