ATLAS Offline Software
Loading...
Searching...
No Matches
DecoratorHelpers.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#ifndef DECORATORHELPERS_H
9#define DECORATORHELPERS_H
10
11#include <Math/Vector4D.h>
12#include <TMath.h>
14
28template <typename T, typename U, typename V>
29void FillParticleInfo(const SG::Decorator<T>& dec, const U& value,
30 const V* object) {
31 dec(*object) = value;
32}
33
45template <typename T, typename U, typename V>
46void FillVectorParticleInfo(const SG::Decorator<std::vector<T>>& dec,
47 const U& value, const V* object) {
48 dec(*object).push_back(value);
49}
50
64template <typename T, typename U>
66 const SG::Decorator<T>& dec_eta,
67 const SG::Decorator<T>& dec_phi,
68 const SG::Decorator<T>& dec_m,
69 const ROOT::Math::PtEtaPhiMVector& particle, U* object) {
70 FillParticleInfo(dec_pt, particle.Pt(), object);
71 FillParticleInfo(dec_eta, particle.Eta(), object);
72 FillParticleInfo(dec_phi, particle.Phi(), object);
73 FillParticleInfo(dec_m, particle.M(), object);
74}
75
83template <typename T, typename U>
84void FillVectorParticleInfo(const SG::Decorator<std::vector<T>>& dec_pt,
85 const SG::Decorator<std::vector<T>>& dec_eta,
86 const SG::Decorator<std::vector<T>>& dec_phi,
87 const SG::Decorator<std::vector<T>>& dec_m,
88 const ROOT::Math::PtEtaPhiMVector& particle,
89 U* object) {
90 FillVectorParticleInfo(dec_pt, particle.Pt(), object);
91 FillVectorParticleInfo(dec_eta, particle.Eta(), object);
92 FillVectorParticleInfo(dec_phi, particle.Phi(), object);
93 FillVectorParticleInfo(dec_m, particle.M(), object);
94}
95
103template <typename T, typename U>
105 const SG::Decorator<T>& dec_eta,
106 const SG::Decorator<T>& dec_phi,
107 const SG::Decorator<T>& dec_m,
108 const SG::Decorator<int>& dec_pdgId,
109 const ROOT::Math::PtEtaPhiMVector& particle, int pdgId,
110 U* object) {
111 FillParticleInfo(dec_pdgId, pdgId, object);
112 FillParticleInfo(dec_pt, dec_eta, dec_phi, dec_m, particle, object);
113}
114
122template <typename T, typename U>
123void FillVectorParticleInfo(const SG::Decorator<std::vector<T>>& dec_pt,
124 const SG::Decorator<std::vector<T>>& dec_eta,
125 const SG::Decorator<std::vector<T>>& dec_phi,
126 const SG::Decorator<std::vector<T>>& dec_m,
127 const SG::Decorator<std::vector<int>>& dec_pdgId,
128 const ROOT::Math::PtEtaPhiMVector& particle,
129 int pdgId, U* object) {
130 FillVectorParticleInfo(dec_pdgId, pdgId, object);
131 FillVectorParticleInfo(dec_pt, dec_eta, dec_phi, dec_m, particle, object);
132}
133
141template <typename T, typename U>
143 const SG::Decorator<T>& dec_eta,
144 const SG::Decorator<T>& dec_phi,
145 const SG::Decorator<T>& dec_m, U* object) {
146 FillParticleInfo(dec_pt, -1, object);
147 FillParticleInfo(dec_eta, -999, object);
148 FillParticleInfo(dec_phi, -999, object);
149 FillParticleInfo(dec_m, -1, object);
150}
151
159template <typename T, typename U>
160void FillDefaultVectorParticleInfo(const SG::Decorator<std::vector<T>>& dec_pt,
161 const SG::Decorator<std::vector<T>>& dec_eta,
162 const SG::Decorator<std::vector<T>>& dec_phi,
163 const SG::Decorator<std::vector<T>>& dec_m,
164 U* object) {
165 dec_pt(*object) = {};
166 dec_eta(*object) = {};
167 dec_phi(*object) = {};
168 dec_m(*object) = {};
169}
170
178template <typename T, typename U>
180 const SG::Decorator<T>& dec_eta,
181 const SG::Decorator<T>& dec_phi,
182 const SG::Decorator<T>& dec_m,
183 const SG::Decorator<int>& dec_pdgId, U* object) {
184 FillParticleInfo(dec_pdgId, 0, object);
185 FillDefaultParticleInfo(dec_pt, dec_eta, dec_phi, dec_m, object);
186}
187
195template <typename T, typename U>
197 const SG::Decorator<std::vector<T>>& dec_pt,
198 const SG::Decorator<std::vector<T>>& dec_eta,
199 const SG::Decorator<std::vector<T>>& dec_phi,
200 const SG::Decorator<std::vector<T>>& dec_m,
201 const SG::Decorator<std::vector<int>>& dec_pdgId, U* object) {
202 dec_pdgId(*object) = {};
203 FillDefaultVectorParticleInfo(dec_pt, dec_eta, dec_phi, dec_m, object);
204}
205
222 std::map<std::string, std::unique_ptr<SG::Decorator<float>>> floatDecorators;
223 std::map<std::string, std::unique_ptr<SG::Decorator<std::vector<float>>>>
225 std::map<std::string, std::unique_ptr<SG::Decorator<int>>> intDecorators;
226 std::map<std::string, std::unique_ptr<SG::Decorator<std::vector<int>>>>
228
237 void setPrefix(const std::string& prefix) { m_prefix = prefix; }
238
247 void setEventInfo(const xAOD::EventInfo* eventInfo) {
248 m_eventInfo = eventInfo;
249 }
250
251 // ── Initialize methods ────────────────────────────────────────────────────
252
254 void initializeFloatDecorator(const std::string& name) {
255 const std::string key = fullName(name);
256 floatDecorators[key] = std::make_unique<SG::Decorator<float>>(key);
257 }
258
260 void initializeVectorFloatDecorator(const std::string& name) {
261 const std::string key = fullName(name);
263 std::make_unique<SG::Decorator<std::vector<float>>>(key);
264 }
265
267 void initializeFloatDecorator(const std::vector<std::string>& names) {
268 for (const auto& name : names)
270 }
271
277 void initializePtEtaPhiMDecorator(const std::string& prefix) {
278 initializeFloatDecorator(prefix + "_pt");
279 initializeFloatDecorator(prefix + "_eta");
280 initializeFloatDecorator(prefix + "_phi");
281 initializeFloatDecorator(prefix + "_m");
282 }
283
288 void initializeVectorPtEtaPhiMDecorator(const std::string& prefix) {
289 initializeVectorFloatDecorator(prefix + "_pt");
290 initializeVectorFloatDecorator(prefix + "_eta");
291 initializeVectorFloatDecorator(prefix + "_phi");
292 initializeVectorFloatDecorator(prefix + "_m");
293 }
294
296 void initializeIntDecorator(const std::string& name) {
297 const std::string key = fullName(name);
298 intDecorators[key] = std::make_unique<SG::Decorator<int>>(key);
299 }
300
302 void initializeVectorIntDecorator(const std::string& name) {
303 const std::string key = fullName(name);
305 std::make_unique<SG::Decorator<std::vector<int>>>(key);
306 }
307
309 void initializeIntDecorator(const std::vector<std::string>& names) {
310 for (const auto& name : names)
312 }
313
314 // ── Getter methods ────────────────────────────────────────────────────────
315
320 SG::Decorator<int>* getIntDecorator(const std::string& name) const {
321 const std::string key = fullName(name);
322 auto it = intDecorators.find(key);
323 if (it != intDecorators.end())
324 return it->second.get();
325 throw std::runtime_error("Decorator with name " + key + " not found.");
326 }
327
333 const std::string& name) const {
334 const std::string key = fullName(name);
335 auto it = vectorintDecorators.find(key);
336 if (it != vectorintDecorators.end())
337 return it->second.get();
338 throw std::runtime_error("Decorator with name " + key + " not found.");
339 }
340
345 SG::Decorator<float>* getFloatDecorator(const std::string& name) const {
346 const std::string key = fullName(name);
347 auto it = floatDecorators.find(key);
348 if (it != floatDecorators.end())
349 return it->second.get();
350 throw std::runtime_error("Decorator with name " + key + " not found.");
351 }
352
358 const std::string& name) const {
359 const std::string key = fullName(name);
360 auto it = vectorfloatDecorators.find(key);
361 if (it != vectorfloatDecorators.end())
362 return it->second.get();
363 throw std::runtime_error("Decorator with name " + key + " not found.");
364 }
365
366 // ── Decorate methods ──────────────────────────────────────────────────────
367 // All write to m_eventInfo. Call setEventInfo() once per event first.
368
374 void decorateDefault(const std::string& prefix) {
376 *getFloatDecorator(prefix + "_pt"), *getFloatDecorator(prefix + "_eta"),
377 *getFloatDecorator(prefix + "_phi"), *getFloatDecorator(prefix + "_m"),
378 *getIntDecorator(prefix + "_pdgId"), m_eventInfo);
379 }
380
382 void decorateVectorDefault(const std::string& prefix) {
384 *getVectorFloatDecorator(prefix + "_eta"),
385 *getVectorFloatDecorator(prefix + "_phi"),
386 *getVectorFloatDecorator(prefix + "_m"),
387 *getVectorIntDecorator(prefix + "_pdgId"),
389 }
390
394 void decorateDefaultNoPdgId(const std::string& prefix) {
396 *getFloatDecorator(prefix + "_eta"),
397 *getFloatDecorator(prefix + "_phi"),
398 *getFloatDecorator(prefix + "_m"), m_eventInfo);
399 }
400
402 void decorateCustom(const std::string& name, float value) {
404 }
405
407 void decorateCustom(const std::string& name, int value) {
409 }
410
417 void decorateParticle(const std::string& prefix,
418 const ROOT::Math::PtEtaPhiMVector& p) {
419 FillParticleInfo(*getFloatDecorator(prefix + "_pt"),
420 *getFloatDecorator(prefix + "_eta"),
421 *getFloatDecorator(prefix + "_phi"),
422 *getFloatDecorator(prefix + "_m"), p, m_eventInfo);
423 }
424
432 void decorateParticle(const std::string& prefix,
433 const ROOT::Math::PtEtaPhiMVector& p, int pdgId) {
435 *getFloatDecorator(prefix + "_pt"), *getFloatDecorator(prefix + "_eta"),
436 *getFloatDecorator(prefix + "_phi"), *getFloatDecorator(prefix + "_m"),
437 *getIntDecorator(prefix + "_pdgId"), p, pdgId, m_eventInfo);
438 }
439
449 const std::string& prefix,
450 const std::vector<ROOT::Math::PtEtaPhiMVector>& vec_p,
451 const std::vector<int>& vec_pdgId) {
452 for (size_t i = 0; i < vec_p.size(); i++) {
454 *getVectorFloatDecorator(prefix + "_eta"),
455 *getVectorFloatDecorator(prefix + "_phi"),
456 *getVectorFloatDecorator(prefix + "_m"),
457 *getVectorIntDecorator(prefix + "_pdgId"),
458 vec_p.at(i), vec_pdgId.at(i), m_eventInfo);
459 }
460 }
461
462 private:
463 std::string m_prefix;
465 nullptr};
466
470 std::string fullName(const std::string& name) const {
471 return m_prefix.empty() ? name : m_prefix + "_" + name;
472 }
473};
474
475#endif // DECORATORHELPERS_H
void FillDefaultParticleInfo(const SG::Decorator< T > &dec_pt, const SG::Decorator< T > &dec_eta, const SG::Decorator< T > &dec_phi, const SG::Decorator< T > &dec_m, U *object)
Template function to fill default (placeholder) particle kinematics into an object.
void FillParticleInfo(const SG::Decorator< T > &dec, const U &value, const V *object)
Template function to fill particle information into a given object.
void FillDefaultVectorParticleInfo(const SG::Decorator< std::vector< T > > &dec_pt, const SG::Decorator< std::vector< T > > &dec_eta, const SG::Decorator< std::vector< T > > &dec_phi, const SG::Decorator< std::vector< T > > &dec_m, U *object)
Template function to fill default (placeholder) vector particle kinematics into an object.
void FillVectorParticleInfo(const SG::Decorator< std::vector< T > > &dec, const U &value, const V *object)
Template function to fill vector particle information into a given object.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576
EventInfo_v1 EventInfo
Definition of the latest event info version.
Struct to manage and apply decorators to the EventInfo object.
void setPrefix(const std::string &prefix)
Set the prefix prepended to all decorator names.
void decorateVectorParticle(const std::string &prefix, const std::vector< ROOT::Math::PtEtaPhiMVector > &vec_p, const std::vector< int > &vec_pdgId)
Decorate with a vector of particle kinematics and PDG IDs (bare prefix).
void decorateDefault(const std::string &prefix)
Decorate with default particle kinematics (bare prefix).
void decorateVectorDefault(const std::string &prefix)
Decorate with default vector particle kinematics (bare prefix).
SG::Decorator< float > * getFloatDecorator(const std::string &name) const
Retrieve a pointer to a float decorator by bare name.
const xAOD::EventInfo * m_eventInfo
Target object; set once per event via setEventInfo().
void initializeVectorPtEtaPhiMDecorator(const std::string &prefix)
Initialize vector pt, eta, phi, m float decorators for a bare prefix.
SG::Decorator< std::vector< int > > * getVectorIntDecorator(const std::string &name) const
Retrieve a pointer to a vector-of-int decorator by bare name.
std::map< std::string, std::unique_ptr< SG::Decorator< float > > > floatDecorators
void initializeVectorFloatDecorator(const std::string &name)
Initialize a vector-of-float decorator by bare name.
void initializeFloatDecorator(const std::string &name)
Initialize a float decorator by bare name.
SG::Decorator< std::vector< float > > * getVectorFloatDecorator(const std::string &name) const
Retrieve a pointer to a vector-of-float decorator by bare name.
void decorateDefaultNoPdgId(const std::string &prefix)
Decorate with default particle kinematics, no PDG ID (bare prefix).
void initializeFloatDecorator(const std::vector< std::string > &names)
Initialize multiple float decorators by a list of bare names.
void decorateCustom(const std::string &name, int value)
Decorate with a custom integer value (bare name).
void setEventInfo(const xAOD::EventInfo *eventInfo)
Set the EventInfo object to decorate for the current event.
std::map< std::string, std::unique_ptr< SG::Decorator< std::vector< float > > > > vectorfloatDecorators
void decorateCustom(const std::string &name, float value)
Decorate with a custom float value (bare name).
void initializeIntDecorator(const std::string &name)
Initialize an integer decorator by bare name.
void initializeVectorIntDecorator(const std::string &name)
Initialize a vector-of-int decorator by bare name.
std::string m_prefix
Prefix prepended to all decorator names.
void initializeIntDecorator(const std::vector< std::string > &names)
Initialize multiple integer decorators by a list of bare names.
std::string fullName(const std::string &name) const
Returns the full (prefixed) decorator key for internal use.
void initializePtEtaPhiMDecorator(const std::string &prefix)
Initialize pt, eta, phi, m float decorators for a bare prefix.
void decorateParticle(const std::string &prefix, const ROOT::Math::PtEtaPhiMVector &p, int pdgId)
Decorate with particle kinematics and PDG ID (bare prefix).
std::map< std::string, std::unique_ptr< SG::Decorator< int > > > intDecorators
void decorateParticle(const std::string &prefix, const ROOT::Math::PtEtaPhiMVector &p)
Decorate with particle kinematics, no PDG ID (bare prefix).
std::map< std::string, std::unique_ptr< SG::Decorator< std::vector< int > > > > vectorintDecorators
SG::Decorator< int > * getIntDecorator(const std::string &name) const
Retrieve a pointer to an integer decorator by bare name.