ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Units.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Units.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 namespace Acts {
12 
84 
85 namespace UnitConstants {
86 // Length, native unit mm
87 constexpr double fm = 1e-12;
88 constexpr double pm = 1e-9;
89 constexpr double um = 1e-3;
90 constexpr double nm = 1e-6;
91 constexpr double mm = 1.0;
92 constexpr double cm = 10.0;
93 constexpr double m = 1e3;
94 constexpr double km = 1e6;
95 // Shortcuts for commonly used area and volume units. This intentionally
96 // contains not all possible combinations to avoid cluttering the namespace.
97 // Missing area or volume units can always be defined on the fly using the
98 // existing length units e.g. 1fm³ -> 1fm * 1fm * 1fm
99 // Area, native unit mm²
100 constexpr double mm2 = mm * mm;
101 constexpr double cm2 = cm * cm;
102 constexpr double m2 = m * m;
103 // Volume, native unit mm³
104 constexpr double mm3 = mm * mm * mm;
105 constexpr double cm3 = cm * cm * cm;
106 constexpr double m3 = m * m * m;
107 // Time, native unit mm = [speed-of-light * time] = mm/s * s
108 constexpr double s = 299792458000.0;
109 constexpr double fs = 1e-15 * s;
110 constexpr double ps = 1e-12 * s;
111 constexpr double ns = 1e-9 * s;
112 constexpr double us = 1e-6 * s;
113 constexpr double ms = 1e-3 * s;
114 constexpr double min = 60.0 * s;
115 constexpr double h = 3600.0 * s;
116 // Angles, native unit radian
117 constexpr double mrad = 1e-3;
118 constexpr double rad = 1.0;
119 constexpr double degree = 0.017453292519943295; // pi / 180
120 // Energy/mass/momentum, native unit GeV
121 constexpr double eV = 1e-9;
122 constexpr double keV = 1e-6;
123 constexpr double MeV = 1e-3;
124 constexpr double GeV = 1.0;
125 constexpr double TeV = 1e3;
126 // atomic mass unit u
127 constexpr double u = 0.93149410242;
128 // 1eV/c² == 1.782662e-36kg
129 // 1GeV/c² == 1.782662e-27kg
130 // -> 1kg == (1/1.782662e-27)GeV/c²
131 // -> 1g == (1/(1e3*1.782662e-27))GeV/c²
132 constexpr double g = 1.0 / 1.782662e-24;
133 constexpr double kg = 1.0 / 1.782662e-27;
134 // Charge, native unit e (elementary charge)
135 constexpr double e = 1.0;
136 constexpr double C = 1.602176634e19;
137 // Magnetic field, native unit GeV/(e*mm)
138 constexpr double T = 0.000299792458; // equivalent to c in appropriate SI units
139 constexpr double Gauss = 1e-4 * T;
140 constexpr double kGauss = 1e-1 * T;
141 } // namespace UnitConstants
142 
143 namespace UnitLiterals {
144 // define user literal functions for the given unit constant
145 #define ACTS_DEFINE_UNIT_LITERAL(name) \
146  constexpr double operator"" _##name(long double x) { \
147  return ::Acts::UnitConstants::name * x; \
148  } \
149  constexpr double operator"" _##name(unsigned long long x) { \
150  return ::Acts::UnitConstants::name * x; \
151  }
190 // not needed anymore. undef to prevent littering the namespace
191 #undef ACTS_DEFINE_UNIT_LITERAL
192 } // namespace UnitLiterals
193 
195 namespace units {
196 
199 constexpr double _km = UnitConstants::km;
200 constexpr double _m = UnitConstants::m;
201 constexpr double _cm = UnitConstants::cm;
202 constexpr double _mm = UnitConstants::mm;
203 constexpr double _um = UnitConstants::um;
204 constexpr double _nm = UnitConstants::nm;
205 constexpr double _pm = UnitConstants::pm;
206 constexpr double _fm = UnitConstants::fm;
208 constexpr double _mm2 = _mm * _mm;
210 
213 constexpr double _h = UnitConstants::h;
214 constexpr double _s = UnitConstants::s;
215 constexpr double _ms = UnitConstants::ms;
217 
220 constexpr double _GeV = UnitConstants::GeV;
221 constexpr double _TeV = UnitConstants::TeV;
222 constexpr double _MeV = UnitConstants::MeV;
223 constexpr double _keV = UnitConstants::keV;
224 constexpr double _eV = UnitConstants::eV;
225 constexpr double _g = UnitConstants::g;
226 constexpr double _kg = UnitConstants::kg;
228 
231 constexpr double _C = UnitConstants::C;
232 constexpr double _e = UnitConstants::e;
234 constexpr double _e2 = _e * _e;
236 
239 constexpr double _T = UnitConstants::T;
240 constexpr double _Gauss = UnitConstants::Gauss;
241 constexpr double _kGauss = UnitConstants::kGauss;
243 
244 } // namespace units
245 } // namespace Acts