8#ifndef DECORATORHELPERS_H
9#define DECORATORHELPERS_H
12#include <Math/Vector4D.h>
18#include <unordered_map>
36template <
typename T,
typename U,
typename V>
53template <
typename T,
typename U,
typename V>
55 const U& value,
const V*
object) {
56 dec(*object).push_back(value);
72template <
typename T,
typename U>
77 const ROOT::Math::PtEtaPhiMVector& particle, U*
object) {
91template <
typename T,
typename U>
96 const ROOT::Math::PtEtaPhiMVector& particle,
111template <
typename T,
typename U>
117 const ROOT::Math::PtEtaPhiMVector& particle,
int pdgId,
130template <
typename T,
typename U>
136 const ROOT::Math::PtEtaPhiMVector& particle,
137 int pdgId, U*
object) {
149template <
typename T,
typename U>
167template <
typename T,
typename U>
173 dec_pt(*
object) = {};
174 dec_eta(*
object) = {};
175 dec_phi(*
object) = {};
186template <
typename T,
typename U>
203template <
typename T,
typename U>
209 const SG::Decorator<std::vector<int>>& dec_pdgId, U*
object) {
210 dec_pdgId(*
object) = {};
233 std::unordered_map<std::string, SG::Decorator<std::vector<float>>>
236 std::unordered_map<std::string, SG::Decorator<std::vector<int>>>
362 const std::string&
name)
const {
379 const std::string&
name)
const {
430 const ROOT::Math::PtEtaPhiMVector& p) {
443 const ROOT::Math::PtEtaPhiMVector& p,
int pdgId) {
458 const std::string& prefix,
459 const std::vector<ROOT::Math::PtEtaPhiMVector>& vec_p,
460 const std::vector<int>& vec_pdgId) {
462 for (
size_t i = 0; i < vec_p.size(); i++) {
464 *decs.
pdgId, vec_p.at(i), vec_pdgId.at(i),
496 std::unordered_map<std::string, VectorParticleDecorators>
507 template <
typename T>
508 const T*
findDecorator(
const std::unordered_map<std::string, T>& decorators,
509 const std::string&
name)
const {
511 auto it = decorators.find(key);
512 if (it != decorators.end())
514 throw std::runtime_error(
"Decorator with name " + key +
" not found.");
536 decs.
pdgId = &pdgIdIt->second;
543 const std::string& prefix) {
558 const std::string& prefix)
const {
560 throw std::runtime_error(
"Decorator with name " +
561 fullName(prefix +
"_pdgId") +
" not found.");
Helper class to provide type-safe access to aux data.
Select isolated Photons, Electrons and Muons.
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.
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 FillParticleInfo(const SG::Decorator< T > &dec, const U &value, const V *object)
Template function to fill particle information into a given object.
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.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
EventInfo_v1 EventInfo
Definition of the latest event info version.
static const EventInfo_v1::Accessor< std::vector< std::string > > names("streamTagNames")
Decorators of one scalar particle prefix; pdgId is nullptr if the "<prefix>_pdgId" decorator was not ...
const SG::Decorator< float > * eta
const SG::Decorator< float > * phi
const SG::Decorator< float > * m
const SG::Decorator< float > * pt
const SG::Decorator< int > * pdgId
Decorators of one vector particle prefix.
const SG::Decorator< std::vector< float > > * phi
const SG::Decorator< std::vector< float > > * pt
const SG::Decorator< std::vector< float > > * m
const SG::Decorator< std::vector< float > > * eta
const SG::Decorator< std::vector< int > > * pdgId
Struct to manage and apply decorators to the EventInfo object.
void initializeParticleDecorators(const std::string &prefix)
Initialize pt, eta, phi, m float and pdgId int decorators for a bare prefix.
const ParticleDecorators & particleDecorators(const std::string &prefix)
Resolve (once) the scalar decorators belonging to a bare prefix.
void initializeVectorFloatDecorator(const std::string &name)
Initialize a vector-of-float decorator by bare name.
void decorateParticle(const std::string &prefix, const ROOT::Math::PtEtaPhiMVector &p, int pdgId)
Decorate with particle kinematics and PDG ID (bare prefix).
void clearCaches()
Invalidate the per-prefix bundles, e.g. after new decorators were added.
void decorateDefault(const std::string &prefix)
Decorate with default particle kinematics (bare prefix).
void initializeVectorParticleDecorators(const std::string &prefix)
Initialize vector pt, eta, phi, m float and pdgId int decorators for a bare prefix.
const T * findDecorator(const std::unordered_map< std::string, T > &decorators, const std::string &name) const
Look up a decorator by bare name; throws if it was not initialized.
std::unordered_map< std::string, SG::Decorator< std::vector< float > > > vectorfloatDecorators
void initializeIntDecorator(const std::string &name)
Initialize an integer decorator by bare name.
void initializeFloatDecorator(const std::string &name)
Initialize a float decorator by bare name.
const xAOD::EventInfo * m_eventInfo
Target object; set once per event via setEventInfo().
void decorateCustom(const std::string &name, int value)
Decorate with a custom integer value (bare name).
std::unordered_map< std::string, SG::Decorator< int > > intDecorators
const SG::Decorator< int > * getIntDecorator(const std::string &name) const
Retrieve a pointer to an integer decorator by bare name.
void initializeVectorIntDecorator(const std::string &name)
Initialize a vector-of-int decorator by bare name.
void initializeIntDecorator(const std::vector< std::string > &names)
Initialize multiple integer decorators by a list of bare names.
void decorateDefaultNoPdgId(const std::string &prefix)
Decorate with default particle kinematics, no PDG ID (bare prefix).
const SG::Decorator< float > * getFloatDecorator(const std::string &name) const
Retrieve a pointer to a float decorator by bare name.
void setEventInfo(const xAOD::EventInfo *eventInfo)
Set the EventInfo object to decorate for the current event.
std::string m_prefix
Prefix prepended to all decorator names.
void decorateCustom(const std::string &name, float value)
Decorate with a custom float value (bare name).
void initializeFloatDecorator(const std::vector< std::string > &names)
Initialize multiple float decorators by a list of bare names.
void initializeVectorPtEtaPhiMDecorator(const std::string &prefix)
Initialize vector pt, eta, phi, m float decorators for a bare prefix.
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).
std::unordered_map< std::string, VectorParticleDecorators > m_vectorParticleCache
void initializePtEtaPhiMDecorator(const std::string &prefix)
Initialize pt, eta, phi, m float decorators for a bare prefix.
const VectorParticleDecorators & vectorParticleDecorators(const std::string &prefix)
Resolve (once) the vector decorators belonging to a bare prefix.
std::unordered_map< std::string, SG::Decorator< std::vector< int > > > vectorintDecorators
std::string fullName(const std::string &name) const
Returns the full (prefixed) decorator key for internal use.
std::unordered_map< std::string, ParticleDecorators > m_particleCache
Per-prefix decorator bundles, keyed by bare prefix.
void setPrefix(const std::string &prefix)
Set the prefix prepended to all decorator names.
const SG::Decorator< std::vector< int > > * getVectorIntDecorator(const std::string &name) const
Retrieve a pointer to a vector-of-int decorator by bare name.
const SG::Decorator< std::vector< float > > * getVectorFloatDecorator(const std::string &name) const
Retrieve a pointer to a vector-of-float decorator by bare name.
const SG::Decorator< int > & pdgIdDecorator(const ParticleDecorators &decs, const std::string &prefix) const
The pdgId decorator of a bundle; throws if it was not initialized.
void decorateParticle(const std::string &prefix, const ROOT::Math::PtEtaPhiMVector &p)
Decorate with particle kinematics, no PDG ID (bare prefix).
std::unordered_map< std::string, SG::Decorator< float > > floatDecorators
void decorateVectorDefault(const std::string &prefix)
Decorate with default vector particle kinematics (bare prefix).