ATLAS Offline Software
Loading...
Searching...
No Matches
AccessorHelpers.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 ACCESSORHELPERS_H
9#define ACCESSORHELPERS_H
10
11#include <Math/Vector4D.h>
12#include <TMath.h>
13
14#include <map>
15
24 std::map<std::string, std::unique_ptr<SG::Accessor<float>>> floatAccessors;
25 std::map<std::string, std::unique_ptr<SG::Accessor<int>>> intAccessors;
26
32 void initializeFloatAccessor(const std::string& name) {
33 floatAccessors[name] = std::make_unique<SG::Accessor<float>>(name);
34 }
35
41 void initializeFloatAccessor(const std::vector<std::string>& names) {
42 for (const auto& name : names) {
44 }
45 }
46
52 void initializeIntAccessor(const std::string& name) {
53 intAccessors[name] = std::make_unique<SG::Accessor<int>>(name);
54 }
55
61 void initializeIntAccessor(const std::vector<std::string>& names) {
62 for (const auto& name : names) {
64 }
65 }
66
72 void initializePtEtaPhiMAccessor(const std::string& prefix) {
73 initializeFloatAccessor(prefix + "_pt");
74 initializeFloatAccessor(prefix + "_eta");
75 initializeFloatAccessor(prefix + "_phi");
76 initializeFloatAccessor(prefix + "_m");
77 }
78
85 template <typename T>
86 float getFloat(const std::string& name, T* object) {
87 return (*floatAccessors.at(name))(*object);
88 }
89
96 template <typename T>
97 int getInt(const std::string& name, T* object) {
98 return (*intAccessors.at(name))(*object);
99 }
100
108 template <typename T>
109 void getPtEtaPhiMVector(const std::string& prefix,
110 ROOT::Math::PtEtaPhiMVector& p, T* object) {
111 p.SetCoordinates(
112 getFloat(prefix + "_pt", object), getFloat(prefix + "_eta", object),
113 getFloat(prefix + "_phi", object), getFloat(prefix + "_m", object));
114 }
115};
116
117#endif // ACCESSORHELPERS_H
Struct to manage accessors to objects.
void initializeFloatAccessor(const std::vector< std::string > &names)
Initialize multiple float accessors by a list of names.
std::map< std::string, std::unique_ptr< SG::Accessor< float > > > floatAccessors
std::map< std::string, std::unique_ptr< SG::Accessor< int > > > intAccessors
void initializeFloatAccessor(const std::string &name)
Initialize a float accessor by name.
void initializeIntAccessor(const std::string &name)
Initialize an integer accessor by name.
int getInt(const std::string &name, T *object)
Template to get an Int via the name of an accessor.
float getFloat(const std::string &name, T *object)
Template to get an Float via the name of an accessor.
void initializeIntAccessor(const std::vector< std::string > &names)
Initialize multiple integer accessors by a list of names.
void getPtEtaPhiMVector(const std::string &prefix, ROOT::Math::PtEtaPhiMVector &p, T *object)
Template to get a PtEtaPhiMVector via the name of an accessor.
void initializePtEtaPhiMAccessor(const std::string &prefix)
Initialize a PtEtaPhiMVector using floats.