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
12#include <Math/Vector4D.h>
13#include <TMath.h>
14
15#include <map>
16#include <memory>
17#include <string>
18#include <vector>
19
20namespace CP {
21
30 std::map<std::string, std::unique_ptr<SG::Accessor<float>>> floatAccessors;
31 std::map<std::string, std::unique_ptr<SG::Accessor<int>>> intAccessors;
32
38 void initializeFloatAccessor(const std::string& name) {
39 floatAccessors[name] = std::make_unique<SG::Accessor<float>>(name);
40 }
41
47 void initializeFloatAccessor(const std::vector<std::string>& names) {
48 for (const auto& name : names) {
50 }
51 }
52
58 void initializeIntAccessor(const std::string& name) {
59 intAccessors[name] = std::make_unique<SG::Accessor<int>>(name);
60 }
61
67 void initializeIntAccessor(const std::vector<std::string>& names) {
68 for (const auto& name : names) {
70 }
71 }
72
78 void initializePtEtaPhiMAccessor(const std::string& prefix) {
79 initializeFloatAccessor(prefix + "_pt");
80 initializeFloatAccessor(prefix + "_eta");
81 initializeFloatAccessor(prefix + "_phi");
82 initializeFloatAccessor(prefix + "_m");
83 }
84
91 template <typename T>
92 float getFloat(const std::string& name, T* object) {
93 return (*floatAccessors.at(name))(*object);
94 }
95
102 template <typename T>
103 int getInt(const std::string& name, T* object) {
104 return (*intAccessors.at(name))(*object);
105 }
106
114 template <typename T>
115 void getPtEtaPhiMVector(const std::string& prefix,
116 ROOT::Math::PtEtaPhiMVector& p, T* object) {
117 p.SetCoordinates(
118 getFloat(prefix + "_pt", object), getFloat(prefix + "_eta", object),
119 getFloat(prefix + "_phi", object), getFloat(prefix + "_m", object));
120 }
121};
122
123} // namespace CP
124
125#endif // ACCESSORHELPERS_H
Helper class to provide type-safe access to aux data.
Select isolated Photons, Electrons and Muons.
static const EventInfo_v1::Accessor< std::vector< std::string > > names("streamTagNames")
Struct to manage accessors to objects.
float getFloat(const std::string &name, T *object)
Template to get an Float via the name of an accessor.
std::map< std::string, std::unique_ptr< SG::Accessor< int > > > intAccessors
int getInt(const std::string &name, T *object)
Template to get an Int via the name of an accessor.
void initializeFloatAccessor(const std::string &name)
Initialize a float accessor by name.
void initializeIntAccessor(const std::vector< std::string > &names)
Initialize multiple integer accessors by a list of names.
void initializePtEtaPhiMAccessor(const std::string &prefix)
Initialize a PtEtaPhiMVector using floats.
void initializeFloatAccessor(const std::vector< std::string > &names)
Initialize multiple float 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 initializeIntAccessor(const std::string &name)
Initialize an integer accessor by name.
std::map< std::string, std::unique_ptr< SG::Accessor< float > > > floatAccessors