ATLAS Offline Software
UnitConverters.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef ACTSINTEROPS_UNITCONVERTER_H
5 #define ACTSINTEROPS_UNITCONVERTER_H
6 
7 
9 #include "GaudiKernel/SystemOfUnits.h"
11 
12 #include "Acts/Definitions/Units.hpp"
13 #include "Acts/Definitions/Algebra.hpp"
14 #include "Acts/Definitions/Common.hpp"
15 
16 #include <utility>
17 
18 namespace ActsTrk{
21  inline constexpr double energyToActs(const double athenaE) {
22  using namespace Acts::UnitLiterals;
23  constexpr double energyCnv = 1_MeV / Gaudi::Units::MeV;
24  return energyCnv * athenaE;
25  }
28  inline constexpr double energyToAthena(const double actsE) {
29  using namespace Acts::UnitLiterals;
30  constexpr double energyCnv = Gaudi::Units::MeV / 1_MeV;
31  return energyCnv * actsE;
32  }
35  inline constexpr double lengthToActs(const double athenaL) {
36  using namespace Acts::UnitLiterals;
37  constexpr double lengthCnv = 1_mm / Gaudi::Units::mm;
38  return lengthCnv * athenaL;
39  }
42  inline constexpr double lengthToAthena(const double actsL) {
43  using namespace Acts::UnitLiterals;
44  constexpr double lengthCnv = Gaudi::Units::mm / 1_mm;
45  return lengthCnv * actsL;
46  }
49  inline constexpr double timeToActs(const double athenaT) {
50  using namespace Acts::UnitLiterals;
51  constexpr double timeCnv = 1_ns / Gaudi::Units::ns;
52  return timeCnv * athenaT;
53  }
56  inline constexpr double timeToAthena(const double actsT) {
57  using namespace Acts::UnitLiterals;
58  constexpr double timeCnv = Gaudi::Units::ns/ 1_ns;
59  return timeCnv * actsT;
60  }
63  inline Acts::Vector3 convertDirToActs(const Amg::Vector3D& athenaDir) {
64  return athenaDir;
65  }
68  inline Amg::Vector3D convertDirFromActs(const Acts::Vector3& actsDir) {
69  return actsDir;
70  }
74  inline Acts::Vector4 convertPosToActs(const Amg::Vector3D& athenaPos,
75  const double athenaTime =0.) {
76  Acts::Vector4 pos{Acts::Vector4::Zero()};
77  pos[Acts::eTime] = timeToActs(athenaTime);
78  pos[Acts::ePos0] = lengthToActs(athenaPos.x());
79  pos[Acts::ePos1] = lengthToActs(athenaPos.y());
80  pos[Acts::ePos2] = lengthToActs(athenaPos.z());
81  return pos;
82  }
86  inline std::pair<Amg::Vector3D, double> convertPosFromActs(const Acts::Vector4& actsPos) {
88  pos[Amg::x] = lengthToAthena(actsPos[Acts::ePos0]);
89  pos[Amg::y] = lengthToAthena(actsPos[Acts::ePos1]);
90  pos[Amg::z] = lengthToAthena(actsPos[Acts::ePos2]);
91  return std::make_pair(std::move(pos), timeToAthena(actsPos[Acts::eTime]));
92  }
97  inline Acts::Vector4 convertMomToActs(const Amg::Vector3D& threeMom, const double mass = 0.) {
98  using namespace Acts::UnitLiterals;
99  Acts::Vector4 fourMom{Acts::Vector4::Zero()};
100  fourMom[Acts::eEnergy] = energyToActs(std::sqrt(threeMom.dot(threeMom) + mass*mass));
101  fourMom[Acts::eMom0] = energyToActs(threeMom.x());
102  fourMom[Acts::eMom1] = energyToActs(threeMom.y());
103  fourMom[Acts::eMom2] = energyToActs(threeMom.z());
104  return fourMom;
105  }
109  inline std::pair<Amg::Vector3D, double> convertMomFromActs(const Acts::Vector4& actsMom) {
111  threeMom[Amg::x] = energyToAthena(actsMom[Acts::eMom0]);
112  threeMom[Amg::y] = energyToAthena(actsMom[Acts::eMom1]);
113  threeMom[Amg::z] = energyToAthena(actsMom[Acts::eMom2]);
114  return std::make_pair(std::move(threeMom), energyToAthena(actsMom[Acts::eEnergy]));
115  }
116 }
117 #endif
python.SystemOfUnits.mm
float mm
Definition: SystemOfUnits.py:98
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
ActsTrk::energyToActs
constexpr double energyToActs(const double athenaE)
Converts an energy scalar from Athena to Acts units.
Definition: UnitConverters.h:21
Amg::y
@ y
Definition: GeoPrimitives.h:35
ActsTrk::convertPosToActs
Acts::Vector4 convertPosToActs(const Amg::Vector3D &athenaPos, const double athenaTime=0.)
Converts a position vector & time from Athena units into Acts units.
Definition: UnitConverters.h:74
ActsTrk::timeToAthena
constexpr double timeToAthena(const double actsT)
Converts a time unit from Acts to Athena units.
Definition: UnitConverters.h:56
python.SystemOfUnits.MeV
float MeV
Definition: SystemOfUnits.py:172
ActsTrk::energyToAthena
constexpr double energyToAthena(const double actsE)
Converts an energy scalar from Acts to Athena units.
Definition: UnitConverters.h:28
GeoPrimitives.h
Amg::z
@ z
Definition: GeoPrimitives.h:36
ActsTrk::timeToActs
constexpr double timeToActs(const double athenaT)
Converts a time unit from Athena to Acts units.
Definition: UnitConverters.h:49
ActsTrk::lengthToAthena
constexpr double lengthToAthena(const double actsL)
Converts a length scalar from Acts to Athena units.
Definition: UnitConverters.h:42
ActsTrk::convertMomToActs
Acts::Vector4 convertMomToActs(const Amg::Vector3D &threeMom, const double mass=0.)
Converts a three momentum vector from Athena together with the associated particle mass into an Acts ...
Definition: UnitConverters.h:97
Amg::x
@ x
Definition: GeoPrimitives.h:34
ActsTrk::convertPosFromActs
std::pair< Amg::Vector3D, double > convertPosFromActs(const Acts::Vector4 &actsPos)
Converts an Acts 4-vector into a pair of an Athena spatial vector and the passed time.
Definition: UnitConverters.h:86
ActsTrk::convertDirFromActs
Amg::Vector3D convertDirFromActs(const Acts::Vector3 &actsDir)
Converts a direction vector from acts units into athena units.
Definition: UnitConverters.h:68
ActsTrk::convertMomFromActs
std::pair< Amg::Vector3D, double > convertMomFromActs(const Acts::Vector4 &actsMom)
Converts an Acts four-momentum vector into an pair of an Athena three-momentum and the paritcle's ene...
Definition: UnitConverters.h:109
ActsTrk::convertDirToActs
Acts::Vector3 convertDirToActs(const Amg::Vector3D &athenaDir)
Converts a direction vector from athena units into acts units.
Definition: UnitConverters.h:63
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
ActsTrk::lengthToActs
constexpr double lengthToActs(const double athenaL)
Converts a length scalar from Acts to Athena units.
Definition: UnitConverters.h:35
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
python.SystemOfUnits.ns
float ns
Definition: SystemOfUnits.py:146
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32