ATLAS Offline Software
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 
16 namespace 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:
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:
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 
293  MomentumAccessors () noexcept
294  {
295  reset (std::in_place_type<Detail::MomentumAccessorsIParticle<CI,CM>>);
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>
345  template<ContainerIdConcept CI, typename CM>
348  template<ContainerIdConcept CI, typename CM>
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_") {
354  template<ContainerIdConcept CI, typename CM>
357  template<ContainerIdConcept CI, typename CM>
360  template<ContainerIdConcept CI, typename CM>
362  resetPtEtaPhiReadM (accessors, columnarTool); }
363  template<ContainerIdConcept CI, typename CM>
366  template<ContainerIdConcept CI, typename CM>
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
ParticleConstants::photonMassInMeV
constexpr double photonMassInMeV
various mass-less particles
Definition: ParticleConstants.h:136
columnar::Detail::IMomentumAccessors::e
virtual double e(ObjectId< CI, CM > object) const =0
columnar::Detail::FullMomentumAccessorsPtEtaPhiM::rapidity
double rapidity(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:143
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
columnar::Detail::IMomentumAccessors::phi
virtual double phi(ObjectId< CI, CM > object) const =0
columnar::Detail::MomentumAccessorsImp::CI
CoreAccessors::CI CI
Definition: MomentumAccessors.h:239
columnar::Detail::MomentumAccessorsImp::m
virtual double m(ObjectId< CI, CM > object) const override
Definition: MomentumAccessors.h:252
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
columnar::Detail::MomentumAccessorsImp::CM
typename CoreAccessors::CM CM
Definition: MomentumAccessors.h:240
columnar::Detail::IMomentumAccessors::~IMomentumAccessors
virtual ~IMomentumAccessors()=default
columnar::Detail::FullMomentumAccessorsPtEtaPhiM::CI
CoreAccessors::CI CI
Definition: MomentumAccessors.h:127
columnar::Detail::CoreMomentumAccessorsPtEtaPhi::CoreMomentumAccessorsPtEtaPhi
CoreMomentumAccessorsPtEtaPhi(ColumnarTool< CM > &columnarTool, const std::string &prefix)
a constructor that uses a prefix for the variables (used for jets)
Definition: MomentumAccessors.h:175
columnar::Detail::CoreMomentumAccessorsPtEtaPhiReadM::CoreMomentumAccessorsPtEtaPhiReadM
CoreMomentumAccessorsPtEtaPhiReadM(ColumnarTool< CM > &columnarTool, const std::string &prefix)
Definition: MomentumAccessors.h:190
columnar::resetObjectType
void resetObjectType(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool, xAODType::ObjectType type)
Definition: MomentumAccessors.h:371
columnar::MomentumAccessors
a handle to hold a IMomentumAccessors object
Definition: MomentumAccessors.h:290
ParticleConstants::PDG2011::muonMassInMeV
constexpr double muonMassInMeV
the mass of the muon (in MeV)
Definition: ParticleConstants.h:29
columnar::resetJetConstituentScale
void resetJetConstituentScale(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool, const std::string &prefix="JetConstitScaleMomentum_")
Definition: MomentumAccessors.h:352
columnar::Detail::MomentumAccessorsIParticle::eta
double eta(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:100
test_pyathena.pt
pt
Definition: test_pyathena.py:11
columnar::Detail::MomentumAccessorsImp::MomentumAccessorsImp
MomentumAccessorsImp(Args &&... args)
Definition: MomentumAccessors.h:243
columnar::Detail::MomentumAccessorsIParticle::pt
double pt(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:98
columnar::Detail::CoreMomentumAccessorsPtEtaPhiFixedM::mValue
double mValue
Definition: MomentumAccessors.h:200
columnar::Detail::CoreMomentumAccessorsPtEtaPhiReadM::m
ColumnAccessor< CI, RetypeColumn< double, float >, CM > m
Definition: MomentumAccessors.h:184
columnar::Detail::FullMomentumAccessorsPtEtaPhiM::CM
typename CoreAccessors::CM CM
Definition: MomentumAccessors.h:128
columnar::Detail::FullMomentumAccessorsPtEtaPhiM
generic columnar momentum accessors that use a pt, eta, phi, m representation underneath
Definition: MomentumAccessors.h:125
columnar::Detail::CoreMomentumAccessorsPtEtaPhiReadM
a core momentum accessor that reads pt, eta, phi, and m from the file
Definition: MomentumAccessors.h:183
Args
Definition: test_lwtnn_fastgraph.cxx:12
columnar::Detail::IMomentumAccessors::eta
virtual double eta(ObjectId< CI, CM > object) const =0
CI
std::map< std::string, HypoJetVector >::const_iterator CI
Definition: xAODJetCollector.h:18
columnar::Detail::IMomentumAccessors::m
virtual double m(ObjectId< CI, CM > object) const =0
columnar::MomentumAccessors::pt
double pt(ObjectId< CI, CM > object) const
the various momentum accessors
Definition: MomentumAccessors.h:311
columnar::resetTau
void resetTau(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:367
columnar::Detail::CoreMomentumAccessorsPtEtaPhiFixedM::CoreMomentumAccessorsPtEtaPhiFixedM
CoreMomentumAccessorsPtEtaPhiFixedM(ColumnarTool< CM > &columnarTool, double val_mValue)
Definition: MomentumAccessors.h:205
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
columnar::resetEgamma
void resetEgamma(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:361
columnar::Detail::CoreMomentumAccessorsPtEtaPhiReadM::CoreMomentumAccessorsPtEtaPhiReadM
CoreMomentumAccessorsPtEtaPhiReadM(ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:186
columnar::Detail::IMomentumAccessors
a virtual interface for columnar momentum accessors
Definition: MomentumAccessors.h:221
columnar::MomentumAccessors::rapidity
double rapidity(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:321
ObjectType.h
columnar::resetPhoton
void resetPhoton(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:358
columnar::Detail::CoreMomentumAccessorsPtEtaPhiFixedM
a core momentum accessor that reads pt, eta, phi from the file, but uses a fixed value for m
Definition: MomentumAccessors.h:199
ParticleConstants.h
columnar::Detail::MomentumAccessorsImp::e
virtual double e(ObjectId< CI, CM > object) const override
Definition: MomentumAccessors.h:254
ColumnAccessor.h
columnar::resetElectron
void resetElectron(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:355
columnar::Detail::CoreMomentumAccessorsPtEtaPhi::eta
ColumnAccessor< CI, RetypeColumn< double, float >, CM > eta
Definition: MomentumAccessors.h:167
columnar::MomentumAccessors::MomentumAccessors
MomentumAccessors(std::in_place_type_t< MyMomentumAccessors >, Args &&... args)
Definition: MomentumAccessors.h:299
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
columnar::MomentumAccessors::phi
double phi(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:315
columnar::Detail::IMomentumAccessors::rapidity
virtual double rapidity(ObjectId< CI, CM > object) const =0
columnar::Detail::CoreMomentumAccessorsPtEtaPhi< CI, CM >::CI
CIVal CI
Definition: MomentumAccessors.h:163
columnar::Detail::FullMomentumAccessorsPtEtaPhiM::e
double e(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:132
columnar::Detail::MomentumAccessorsIParticle::CM
CMVal CM
Definition: MomentumAccessors.h:96
columnar::resetIParticle
void resetIParticle(MomentumAccessors< CI, CM > &accessors)
reset the dynamic momentum accessors to various default implementations
Definition: MomentumAccessors.h:340
columnar::CM
ColumnarModeXAOD CM
Definition: ObjectRange.h:141
columnar::Detail::MomentumAccessorsImp::rapidity
virtual double rapidity(ObjectId< CI, CM > object) const override
Definition: MomentumAccessors.h:256
columnar::Detail::MomentumAccessorsIParticle
columnar momentum accessors that redirect to the xAOD::IParticle interface internally
Definition: MomentumAccessors.h:93
columnar::final
CM final
Definition: ColumnAccessor.h:106
columnar::Detail::MomentumAccessorsImp::eta
virtual double eta(ObjectId< CI, CM > object) const override
Definition: MomentumAccessors.h:248
columnar::resetPtEtaPhiFixedM
void resetPtEtaPhiFixedM(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool, double mValue)
Definition: MomentumAccessors.h:346
columnar::MomentumAccessors::e
double e(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:319
columnar::ObjectId
a class representing a single object (electron, muons, etc.)
Definition: ContainerId.h:178
columnar::Detail::MomentumAccessorsImp
the implementation of IMomentumAccessors that wraps a static accessor class
Definition: MomentumAccessors.h:237
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAOD::DiTauJetParameters::Detail
Detail
Definition: DiTauDefs.h:38
columnar::Detail::MomentumAccessorsIParticle::m
double m(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:104
columnar::Detail::CoreMomentumAccessorsPtEtaPhiFixedM::m
double m(ObjectId< CI, CM >) const noexcept
Definition: MomentumAccessors.h:202
columnar::resetMuon
void resetMuon(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:364
columnar::Detail::MomentumAccessorsImp::m_coreAccessors
CoreAccessors m_coreAccessors
Definition: MomentumAccessors.h:260
columnar::Detail::CoreMomentumAccessorsPtEtaPhi< CI, CM >::CM
CM CM
Definition: MomentumAccessors.h:164
columnar::Detail::MomentumAccessorsImp::pt
virtual double pt(ObjectId< CI, CM > object) const override
Definition: MomentumAccessors.h:246
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
columnar::Detail::CoreMomentumAccessorsPtEtaPhi::pt
ColumnAccessor< CI, RetypeColumn< double, float >, CM > pt
Definition: MomentumAccessors.h:166
columnar
Definition: ClusterDef.h:16
columnar::MomentumAccessors::MomentumAccessors
MomentumAccessors() noexcept
Definition: MomentumAccessors.h:293
columnar::MomentumAccessors::m_accessors
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...
Definition: MomentumAccessors.h:328
columnar::ColumnarTool
the base class for all columnar components
Definition: ColumnAccessorDataArray.h:17
columnar::resetPtEtaPhiReadM
void resetPtEtaPhiReadM(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:343
columnar::MomentumAccessors::reset
void reset(std::in_place_type_t< MyMomentumAccessors >, Args &&... args)
Definition: MomentumAccessors.h:305
columnar::MomentumAccessors::m
double m(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:317
columnar::Detail::MomentumAccessorsIParticle::phi
double phi(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:102
columnar::Detail::CoreMomentumAccessorsPtEtaPhi
a core momentum accessor that reads pt, eta, phi from the file
Definition: MomentumAccessors.h:162
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
columnar::Detail::CoreMomentumAccessorsPtEtaPhi::phi
ColumnAccessor< CI, RetypeColumn< double, float >, CM > phi
Definition: MomentumAccessors.h:168
columnar::Detail::MomentumAccessorsIParticle::CI
CIVal CI
Definition: MomentumAccessors.h:95
xAODRootTest.accessors
dictionary accessors
Definition: xAODRootTest.py:73
columnar::AccessorTemplate
the raw column accessor template class
Definition: ColumnAccessor.h:81
columnar::Detail::MomentumAccessorsIParticle::e
double e(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:106
xAODType::ObjectType
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition: ObjectType.h:32
columnar::MomentumAccessors::eta
double eta(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:313
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
columnar::Detail::CoreMomentumAccessorsPtEtaPhi::CoreMomentumAccessorsPtEtaPhi
CoreMomentumAccessorsPtEtaPhi(ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:170
columnar::Detail::MomentumAccessorsImp::phi
virtual double phi(ObjectId< CI, CM > object) const override
Definition: MomentumAccessors.h:250
columnar::Detail::MomentumAccessorsIParticle::rapidity
double rapidity(ObjectId< CI, CM > object) const
Definition: MomentumAccessors.h:108
columnar::Detail::IMomentumAccessors::pt
virtual double pt(ObjectId< CI, CM > object) const =0
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106
columnar::resetJet
void resetJet(MomentumAccessors< CI, CM > &accessors, ColumnarTool< CM > &columnarTool)
Definition: MomentumAccessors.h:349
ParticleConstants::PDG2011::electronMassInMeV
constexpr double electronMassInMeV
the mass of the electron (in MeV)
Definition: ParticleConstants.h:26