ATLAS Offline Software
Loading...
Searching...
No Matches
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#include "Acts/Utilities/MathHelpers.hpp"
16
17#include <utility>
18#include <concepts>
19
20namespace ActsTrk{
23 inline constexpr double energyToActs(const double athenaE) {
24 using namespace Acts::UnitLiterals;
25 constexpr double energyCnv = 1_MeV / Gaudi::Units::MeV;
26 return energyCnv * athenaE;
27 }
28
30 inline constexpr double energyToAthena(const double actsE) {
31 using namespace Acts::UnitLiterals;
32 constexpr double energyCnv = Gaudi::Units::MeV / 1_MeV;
33 return energyCnv * actsE;
34 }
35
37 inline constexpr double lengthToActs(const double athenaL) {
38 using namespace Acts::UnitLiterals;
39 constexpr double lengthCnv = 1_mm / Gaudi::Units::mm;
40 return lengthCnv * athenaL;
41 }
42
44 inline constexpr double lengthToAthena(const double actsL) {
45 using namespace Acts::UnitLiterals;
46 constexpr double lengthCnv = Gaudi::Units::mm / 1_mm;
47 return lengthCnv * actsL;
48 }
49
51 template <std::floating_point T>
52 inline constexpr auto timeToActs(T athenaT) {
53 using namespace Acts::UnitLiterals;
54 constexpr auto timeCnv = static_cast<T>(1_ns / Gaudi::Units::ns);
55 return timeCnv * athenaT;
56 }
57
59 template <std::floating_point T>
60 inline constexpr double timeToAthena(T actsT) {
61 using namespace Acts::UnitLiterals;
62 constexpr auto timeCnv = static_cast<T>(Gaudi::Units::ns/ 1_ns);
63 return timeCnv * actsT;
64 }
65
67 template <std::floating_point T>
68 inline constexpr auto timeCovToActs(T athenaTCov) {
69 using namespace Acts::UnitLiterals;
70 constexpr auto sqr=[](double a) { return a*a;};
71 constexpr auto timeCnv = static_cast<T>(sqr(1_ns / Gaudi::Units::ns));
72 return timeCnv * athenaTCov;
73 }
74
76 template <std::floating_point T>
77 inline constexpr double timeCovToAthena(T actsTCov) {
78 using namespace Acts::UnitLiterals;
79 constexpr auto sqr=[](double a) { return a*a;};
80 constexpr auto timeCnv = static_cast<T>(sqr(Gaudi::Units::ns/ 1_ns));
81 return timeCnv * actsTCov;
82 }
83
85 inline constexpr double velocityToActs(const double athenaV) {
86 return athenaV / timeToActs(1.);
87 }
88
90 inline constexpr double accelerationToActs(const double athenaA) {
91 return athenaA / Acts::square(timeToActs(1.));
92 }
93
95 inline Acts::Vector3 convertDirToActs(const Amg::Vector3D& athenaDir) {
96 return athenaDir;
97 }
98
100 inline Amg::Vector3D convertDirFromActs(const Acts::Vector3& actsDir) {
101 return actsDir;
102 }
103
106 inline Acts::Vector4 convertPosToActs(const Amg::Vector3D& athenaPos,
107 const double athenaTime =0.) {
108 Acts::Vector4 pos{Acts::Vector4::Zero()};
109 pos[Acts::eTime] = timeToActs(athenaTime);
110 pos[Acts::ePos0] = lengthToActs(athenaPos.x());
111 pos[Acts::ePos1] = lengthToActs(athenaPos.y());
112 pos[Acts::ePos2] = lengthToActs(athenaPos.z());
113 return pos;
114 }
115
118 inline std::pair<Amg::Vector3D, double> convertPosFromActs(const Acts::Vector4& actsPos) {
119 Amg::Vector3D pos{Amg::Vector3D::Zero()};
120 pos[Amg::x] = lengthToAthena(actsPos[Acts::ePos0]);
121 pos[Amg::y] = lengthToAthena(actsPos[Acts::ePos1]);
122 pos[Amg::z] = lengthToAthena(actsPos[Acts::ePos2]);
123 return std::make_pair(std::move(pos), timeToAthena(actsPos[Acts::eTime]));
124 }
125
129 inline Acts::Vector4 convertMomToActs(const Amg::Vector3D& threeMom, const double mass = 0.) {
130 using namespace Acts::UnitLiterals;
131 Acts::Vector4 fourMom{Acts::Vector4::Zero()};
132 fourMom[Acts::eEnergy] = energyToActs(std::sqrt(threeMom.dot(threeMom) + mass*mass));
133 fourMom[Acts::eMom0] = energyToActs(threeMom.x());
134 fourMom[Acts::eMom1] = energyToActs(threeMom.y());
135 fourMom[Acts::eMom2] = energyToActs(threeMom.z());
136 return fourMom;
137 }
138
141 inline std::pair<Amg::Vector3D, double> convertMomFromActs(const Acts::Vector4& actsMom) {
142 Amg::Vector3D threeMom{Amg::Vector3D::Zero()};
143 threeMom[Amg::x] = energyToAthena(actsMom[Acts::eMom0]);
144 threeMom[Amg::y] = energyToAthena(actsMom[Acts::eMom1]);
145 threeMom[Amg::z] = energyToAthena(actsMom[Acts::eMom2]);
146 return std::make_pair(std::move(threeMom), energyToAthena(actsMom[Acts::eEnergy]));
147 }
148}
149#endif
static Double_t a
#define sqr(t)
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
constexpr double energyToActs(const double athenaE)
Converts an energy scalar from Athena to Acts units.
constexpr double lengthToActs(const double athenaL)
Converts a length scalar from Acts to Athena units.
constexpr double velocityToActs(const double athenaV)
Converts a velocity from Athena to Acts units.
constexpr double accelerationToActs(const double athenaA)
Converts an acceleration from Athena to Acts units.
Amg::Vector3D convertDirFromActs(const Acts::Vector3 &actsDir)
Converts a direction vector from acts units into athena units.
constexpr auto timeCovToActs(T athenaTCov)
Converts a time covariance element from Athena to Acts units.
constexpr double energyToAthena(const double actsE)
Converts an energy scalar from Acts to Athena units.
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...
constexpr double timeCovToAthena(T actsTCov)
Converts a time covariance element from Acts to Athena units.
constexpr double timeToAthena(T actsT)
Converts a time unit from Acts to Athena units.
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.
constexpr double lengthToAthena(const double actsL)
Converts a length scalar from Acts to Athena units.
constexpr auto timeToActs(T athenaT)
Converts a time unit from Athena to Acts units.
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 ...
Acts::Vector3 convertDirToActs(const Amg::Vector3D &athenaDir)
Converts a direction vector from athena units into acts units.
Acts::Vector4 convertPosToActs(const Amg::Vector3D &athenaPos, const double athenaTime=0.)
Converts a position vector & time from Athena units into Acts units.
Eigen::Matrix< double, 3, 1 > Vector3D