ATLAS Offline Software
Loading...
Searching...
No Matches
MomentumAccessors.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef COLUMNAR_CORE_MOMENTUM_ACCESSORS_H
9#define COLUMNAR_CORE_MOMENTUM_ACCESSORS_H
10
13#include <xAODBase/ObjectType.h>
14#include <Math/Vector4D.h>
15
16namespace columnar
17{
80
81 namespace Detail
82 {
90
91 template<ContainerIdConcept CIVal, typename CMVal = ColumnarModeDefault>
93 {
94 public:
95 using CI = CIVal;
96 using CM = CMVal;
97
98 double pt (ObjectId<CI,CM> object) const {
99 return object.getXAODObject().pt();}
100 double eta (ObjectId<CI,CM> object) const {
101 return object.getXAODObject().eta();}
102 double phi (ObjectId<CI,CM> object) const {
103 return object.getXAODObject().phi();}
104 double m (ObjectId<CI,CM> object) const {
105 return object.getXAODObject().m();}
106 double e (ObjectId<CI,CM> object) const {
107 return object.getXAODObject().e();}
108 double rapidity (ObjectId<CI,CM> object) const {
109 return object.getXAODObject().rapidity();}
110 };
111
122
123 template<typename CoreAccessors>
124 class FullMomentumAccessorsPtEtaPhiM : public CoreAccessors
125 {
126 public:
127 using CI = CoreAccessors::CI;
128 using CM = typename CoreAccessors::CM;
129
130 using CoreAccessors::CoreAccessors;
131
132 double e (ObjectId<CI,CM> object) const
133 {
134 const double myPt = this->pt (object);
135 const double myEta = this->eta (object);
136 const double myM = this->m (object);
137
138 // not reading phi, not part of the energy calculation
139 const ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>> myP4 {myPt, myEta, 0, myM};
140 return myP4.energy();
141 }
142
143 double rapidity (ObjectId<CI,CM> object) const
144 {
145 const double myEta = this->eta(object);
146 const double myM = this->m(object);
147 if (myM == 0)
148 return myEta; // for massless particles, rapidity is the same as eta
149 const double myPt = this->pt(object);
150
151 // not reading phi, not part of the rapidity calculation
152 const ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>> myP4 {myPt, myEta, 0, myM};
153 return myP4.Rapidity();
154 }
155 };
156
157
158
160 template<ContainerIdConcept CIVal,typename CMVal>
162 {
163 using CI = CIVal;
164 using CM = CMVal;
165
169
171 : pt (columnarTool, "pt"), eta (columnarTool, "eta"), phi (columnarTool, "phi")
172 {}
173
175 CoreMomentumAccessorsPtEtaPhi (ColumnarTool<CM>& columnarTool, const std::string& prefix)
176 : pt (columnarTool, prefix + "pt"), eta (columnarTool, prefix + "eta"), phi (columnarTool, prefix + "phi")
177 {}
178 };
179
181 template<ContainerIdConcept CI, typename CM> struct CoreMomentumAccessorsPtEtaPhiReadM
183 {
185
187 : CoreMomentumAccessorsPtEtaPhi<CI,CM> (columnarTool), m (columnarTool, "m")
188 {}
189
190 CoreMomentumAccessorsPtEtaPhiReadM (ColumnarTool<CM>& columnarTool, const std::string& prefix)
191 : CoreMomentumAccessorsPtEtaPhi<CI,CM> (columnarTool, prefix), m (columnarTool, prefix + "m")
192 {}
193 };
194
197 template<ContainerIdConcept CI, typename CM>
199 {
200 double mValue = 0;
201
202 double m (ObjectId<CI,CM> /*object*/) const noexcept {
203 return mValue; }
204
205 CoreMomentumAccessorsPtEtaPhiFixedM (ColumnarTool<CM>& columnarTool, double val_mValue)
206 : CoreMomentumAccessorsPtEtaPhi<CI,CM> (columnarTool), mValue (val_mValue)
207 {}
208 };
209
210
219 template<ContainerIdConcept CI, typename CM = ColumnarModeDefault>
221 {
222 public:
223 virtual ~IMomentumAccessors () = default;
224
225 virtual double pt (ObjectId<CI,CM> object) const = 0;
226 virtual double eta (ObjectId<CI,CM> object) const = 0;
227 virtual double phi (ObjectId<CI,CM> object) const = 0;
228 virtual double m (ObjectId<CI,CM> object) const = 0;
229 virtual double e (ObjectId<CI,CM> object) const = 0;
230 virtual double rapidity (ObjectId<CI,CM> object) const = 0;
231 };
232
235 template<typename CoreAccessors>
236 class MomentumAccessorsImp : public IMomentumAccessors<typename CoreAccessors::CI,typename CoreAccessors::CM>
237 {
238 public:
239 using CI = CoreAccessors::CI;
240 using CM = typename CoreAccessors::CM;
241
242 template<typename... Args>
244 : m_coreAccessors (std::forward<Args> (args)...) {}
245
246 virtual double pt (ObjectId<CI,CM> object) const override {
247 return m_coreAccessors.pt (object); }
248 virtual double eta (ObjectId<CI,CM> object) const override {
249 return m_coreAccessors.eta (object); }
250 virtual double phi (ObjectId<CI,CM> object) const override {
251 return m_coreAccessors.phi (object); }
252 virtual double m (ObjectId<CI,CM> object) const override {
253 return m_coreAccessors.m (object); }
254 virtual double e (ObjectId<CI,CM> object) const override {
255 return m_coreAccessors.e (object); }
256 virtual double rapidity (ObjectId<CI,CM> object) const override {
257 return m_coreAccessors.rapidity (object); }
258
259 private:
260 CoreAccessors m_coreAccessors;
261 };
262 }
263
287
288 template<ContainerIdConcept CI, typename CM = ColumnarModeDefault>
290 {
291 public:
292
294 {
296 }
297
298 template<typename MyMomentumAccessors,typename... Args>
299 MomentumAccessors (std::in_place_type_t<MyMomentumAccessors>, Args&&... args)
300 {
301 reset (std::in_place_type<MyMomentumAccessors>, std::forward<Args> (args)...);
302 }
303
304 template<typename MyMomentumAccessors,typename... Args>
305 void reset (std::in_place_type_t<MyMomentumAccessors>, Args&&... args)
306 {
307 m_accessors = std::make_shared<Detail::MomentumAccessorsImp<MyMomentumAccessors>> (std::forward<Args> (args)...);
308 }
309
311 [[nodiscard]] double pt (ObjectId<CI,CM> object) const {
312 return m_accessors->pt (object); }
313 [[nodiscard]] double eta (ObjectId<CI,CM> object) const {
314 return m_accessors->eta (object); }
315 [[nodiscard]] double phi (ObjectId<CI,CM> object) const {
316 return m_accessors->phi (object); }
317 [[nodiscard]] double m (ObjectId<CI,CM> object) const {
318 return m_accessors->m (object); }
319 [[nodiscard]] double e (ObjectId<CI,CM> object) const {
320 return m_accessors->e (object); }
321 [[nodiscard]] double rapidity (ObjectId<CI,CM> object) const {
322 return m_accessors->rapidity (object); }
323
324 private:
325
328 std::shared_ptr<const Detail::IMomentumAccessors<CI,CM>> m_accessors;
329 };
330
339 template<ContainerIdConcept CI, typename CM>
341 accessors.reset (std::in_place_type<Detail::MomentumAccessorsIParticle<CI,CM>>); }
342 template<ContainerIdConcept CI, typename CM>
344 accessors.reset (std::in_place_type<Detail::FullMomentumAccessorsPtEtaPhiM<Detail::CoreMomentumAccessorsPtEtaPhiReadM<CI,CM>>>, columnarTool); }
345 template<ContainerIdConcept CI, typename CM>
346 void resetPtEtaPhiFixedM (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool, double mValue) {
347 accessors.reset (std::in_place_type<Detail::FullMomentumAccessorsPtEtaPhiM<Detail::CoreMomentumAccessorsPtEtaPhiFixedM<CI,CM>>>, columnarTool, mValue); }
348 template<ContainerIdConcept CI, typename CM>
349 void resetJet (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool) {
350 resetPtEtaPhiReadM (accessors, columnarTool); }
351 template<ContainerIdConcept CI, typename CM>
352 void resetJetConstituentScale (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool, const std::string& prefix = "JetConstitScaleMomentum_") {
353 accessors.reset (std::in_place_type<Detail::FullMomentumAccessorsPtEtaPhiM<Detail::CoreMomentumAccessorsPtEtaPhiReadM<CI,CM>>>, columnarTool, prefix); }
354 template<ContainerIdConcept CI, typename CM>
355 void resetElectron (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool) {
357 template<ContainerIdConcept CI, typename CM>
358 void resetPhoton (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool) {
359 resetPtEtaPhiFixedM (accessors, columnarTool, ParticleConstants::photonMassInMeV); }
360 template<ContainerIdConcept CI, typename CM>
361 void resetEgamma (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool) {
362 resetPtEtaPhiReadM (accessors, columnarTool); }
363 template<ContainerIdConcept CI, typename CM>
364 void resetMuon (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool) {
365 resetPtEtaPhiFixedM (accessors, columnarTool, ParticleConstants::muonMassInMeV); }
366 template<ContainerIdConcept CI, typename CM>
367 void resetTau (MomentumAccessors<CI,CM>& accessors, ColumnarTool<CM>& columnarTool) {
368 resetPtEtaPhiReadM (accessors, columnarTool); }
369
370 template<ContainerIdConcept CI, typename CM>
372 {
373 switch (type)
374 {
376 resetElectron (accessors, columnarTool);
377 break;
379 resetPhoton (accessors, columnarTool);
380 break;
382 resetMuon (accessors, columnarTool);
383 break;
385 resetTau (accessors, columnarTool);
386 break;
388 resetJet (accessors, columnarTool);
389 break;
390 default:
391 throw std::runtime_error ("Unknown object type for momentum accessors: " + std::to_string(static_cast<unsigned>(type)));
392 }
393 }
394}
395
396#endif
Scalar eta() const
pseudorapidity method
A number of constexpr particle constants to avoid hardcoding them directly in various places.
the base class for all columnar components
generic columnar momentum accessors that use a pt, eta, phi, m representation underneath
double e(ObjectId< CI, CM > object) const
double rapidity(ObjectId< CI, CM > object) const
a virtual interface for columnar momentum accessors
virtual double rapidity(ObjectId< CI, CM > object) const =0
virtual double eta(ObjectId< CI, CM > object) const =0
virtual double m(ObjectId< CI, CM > object) const =0
virtual double e(ObjectId< CI, CM > object) const =0
virtual double phi(ObjectId< CI, CM > object) const =0
virtual double pt(ObjectId< CI, CM > object) const =0
columnar momentum accessors that redirect to the xAOD::IParticle interface internally
double eta(ObjectId< CI, CM > object) const
double m(ObjectId< CI, CM > object) const
double phi(ObjectId< CI, CM > object) const
double pt(ObjectId< CI, CM > object) const
double rapidity(ObjectId< CI, CM > object) const
double e(ObjectId< CI, CM > object) const
virtual double rapidity(ObjectId< CI, CM > object) const override
virtual double eta(ObjectId< CI, CM > object) const override
virtual double m(ObjectId< CI, CM > object) const override
virtual double phi(ObjectId< CI, CM > object) const override
virtual double e(ObjectId< CI, CM > object) const override
virtual double pt(ObjectId< CI, CM > object) const override
a handle to hold a IMomentumAccessors object
double rapidity(ObjectId< CI, CM > object) const
double e(ObjectId< CI, CM > object) const
void reset(std::in_place_type_t< MyMomentumAccessors >, Args &&... args)
double phi(ObjectId< CI, CM > object) const
double m(ObjectId< CI, CM > object) const
double eta(ObjectId< CI, CM > object) const
double pt(ObjectId< CI, CM > object) const
the various momentum accessors
MomentumAccessors(std::in_place_type_t< MyMomentumAccessors >, Args &&... args)
std::shared_ptr< const Detail::IMomentumAccessors< CI, CM > > m_accessors
the underlying accessors, which default to the xAOD::IParticle accessors in case they are not overrid...
a class representing a single object (electron, muons, etc.)
constexpr double muonMassInMeV
the mass of the muon (in MeV)
constexpr double electronMassInMeV
the mass of the electron (in MeV)
constexpr double photonMassInMeV
various mass-less particles
void resetEgamma(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
AccessorTemplate< CI, CT, ColumnAccessMode::input, CM > ColumnAccessor
void resetObjectType(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool, xAODType::ObjectType type)
void resetPtEtaPhiFixedM(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool, double mValue)
void resetElectron(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
void resetIParticle(MomentumAccessors< CI, CM > &accessors)
reset the dynamic momentum accessors to various default implementations
void resetPhoton(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
void resetJetConstituentScale(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool, const std::string &prefix="JetConstitScaleMomentum_")
void resetMuon(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
void resetTau(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
void resetPtEtaPhiReadM(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
void resetJet(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
STL namespace.
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ Jet
The object is a jet.
Definition ObjectType.h:40
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
@ Tau
The object is a tau (jet)
Definition ObjectType.h:49
a core momentum accessor that reads pt, eta, phi from the file, but uses a fixed value for m
CoreMomentumAccessorsPtEtaPhiFixedM(ColumnarTool< CM > &columnarTool, double val_mValue)
double m(ObjectId< CI, CM >) const noexcept
a core momentum accessor that reads pt, eta, phi, and m from the file
CoreMomentumAccessorsPtEtaPhiReadM(ColumnarTool< CM > &columnarTool, const std::string &prefix)
ColumnAccessor< CI, RetypeColumn< double, float >, CM > m
CoreMomentumAccessorsPtEtaPhiReadM(ColumnarTool< CM > &columnarTool)
CoreMomentumAccessorsPtEtaPhi(ColumnarTool< CM > &columnarTool, const std::string &prefix)
a constructor that uses a prefix for the variables (used for jets)
ColumnAccessor< CI, RetypeColumn< double, float >, CM > eta
CoreMomentumAccessorsPtEtaPhi(ColumnarTool< CM > &columnarTool)
ColumnAccessor< CI, RetypeColumn< double, float >, CM > phi
ColumnAccessor< CI, RetypeColumn< double, float >, CM > pt