ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::UnitConstants Namespace Reference

Constants and helper literals for physical units. More...

Variables

constexpr double cm = 1e1 * mm
 Centimeter - 1e-2 meter.
constexpr double cm2 = cm * cm
 Square centimeter.
constexpr double cm3 = cm * cm * cm
 Cubic centimeter.
constexpr double degree = std::numbers::pi / 180. / rad
 Degree - pi/180 radians.
constexpr double e = 1.0
 Charge, native unit e (elementary charge).
constexpr double eV = 1e-9 * GeV
 Electronvolt - 1e-9 GeV.
constexpr double fm = 1e-12 * mm
 Femtometer - 1e-15 meter.
constexpr double fs = 1e-15 * s
 Femtosecond - 1e-15 second.
constexpr double g = 1.0 / 1.782662e-24
 Gram in GeV/c²
constexpr double Gauss = 1e-4 * T
 Gauss - 1e-4 Tesla.
constexpr double GeV = 1.0
 Gigaelectronvolt - native unit for energy/mass/momentum.
constexpr double h = 3600.0 * s
 Hour - 3600 seconds.
constexpr double J = 6241509074.460763 * GeV
 Joule in GeV.
constexpr double keV = 1e-6 * GeV
 Kiloelectronvolt - 1e-6 GeV.
constexpr double kg = 1.0 / 1.782662e-27
 Kilogram in GeV/c²
constexpr double kGauss = 1e-1 * T
 Kilogauss - 1e-1 Tesla.
constexpr double km = 1e6 * mm
 Kilometer - 1e3 meter.
constexpr double m = 1e3 * mm
 Meter.
constexpr double m2 = m * m
 Square meter.
constexpr double m3 = m * m * m
 Cubic meter.
constexpr double MeV = 1e-3 * GeV
 Megaelectronvolt - 1e-3 GeV.
constexpr double min = 60.0 * s
 Minute - 60 seconds.
constexpr double mm = 1.0
 Millimeter - native unit for length.
constexpr double mm2 = mm * mm
 Square millimeter - native unit for area.
constexpr double mm3 = mm * mm * mm
 Cubic millimeter - native unit for volume.
constexpr double mol = 1.0
 Amount of substance, native unit mol.
constexpr double mrad = 1e-3
 Milliradian - 1e-3 radian.
constexpr double ms = 1e-3 * s
 Millisecond - 1e-3 second.
constexpr double nm = 1e-6 * mm
 Nanometer - 1e-9 meter.
constexpr double ns = 1e-9 * s
 Nanosecond - 1e-9 second.
constexpr double pm = 1e-9 * mm
 Picometer - 1e-12 meter.
constexpr double ps = 1e-12 * s
 Picosecond - 1e-12 second.
constexpr double rad = 1.0
 Radian - native unit for angle.
constexpr double s = 299792458000.0
constexpr double T = 0.000299792458
 Magnetic field, native unit (eV*s)/(e*m²).
constexpr double TeV = 1e3 * GeV
 Teraelectronvolt - 1e3 GeV.
constexpr double u = 0.93149410242
 atomic mass unit u
constexpr double um = 1e-3 * mm
 Micrometer - 1e-6 meter.
constexpr double us = 1e-6 * s
 Microsecond - 1e-6 second.

Detailed Description

Constants and helper literals for physical units.

All physical quantities have both a numerical value and a unit. For the computations we always choose a particular unit for a given physical quantity so we only need to consider the numerical values as such. The chosen base unit for a particular physical dimension, e.g. length, time, or energy, within this code base is called the native unit. The base units should be chosen such that they are internally consistent, require the least amount of explicit conversion factors (ideally none at all), and have typical numerical values close to unity to reduce numerical issues.

Here, the following native units are used:

  • Length is expressed in mm.
  • Time is expressed in [speed-of-light * time] == mm. A consequence of this choice is that the speed-of-light expressed in native units is 1.
  • Angles are expressed in radian.
  • Energy, mass, and momentum are all expressed in GeV (consistent with speed-of-light == 1).
  • Electric charge is expressed in e, i.e. units of the elementary charge.
  • The magnetic field is expressed in GeV/(e*mm). The magnetic field connects momentum to length, e.g. in SI units the radius of a charged particle trajectory in a constant magnetic field is given by

    \( \text{radius} = - \frac{\text{momentum} }{ \text{charge} } / \text{field} \)

With the chosen magnetic field unit the expression above stays the same and no additional conversion factors are necessary.

Depending on the context a physical quantity might not be given in the native units. In this case we need to convert to the native unit first before the value can be used. The necessary conversion factors are defined in Acts::UnitConstants. Multiplying a value with the unit constant produces the equivalent value in the native unit, e.g.

// Define input values using unit constants
double length = 1 * Acts::UnitConstants::m; // length == 1000.0
double momentum = 100 * Acts::UnitConstants::MeV; // momentum == 0.1
// Convert output values from native units to specific units
double lengthInMm = length / Acts::UnitConstants::mm; // == 1000.0
double lengthInM = length / Acts::UnitConstants::m; // == 1.0

To further simplify the usage, physical quantities can also be expressed via C++ user literals defined in Acts::UnitLiterals. This allows us to express quantities in a concise way:

using namespace Acts::UnitLiterals;
// Define input values using user-defined literals
double length = 1_m; // == 1000.0 (native units: mm)
double momentum = 1.25_TeV; // == 1250.0 (native units: GeV)
// Convert output values to specific units
double lengthInUm = length / 1_um; // == 1000000.0
double momentumInMeV = momentum / 1_MeV; // == 1250000.0
Warning
Since using user-defined literals requires a namespace import of Acts::UnitLiterals it should not be used in headers since it would (accidentally) modify the namespace wherever the header is included.

To ensure consistent computations and results the following guidelines must be followed when handling physical quantities with units:

using namespace Acts::UnitLiterals;
// GOOD: All input values explicitly specify units
double momentum = 100 * Acts::UnitConstants::GeV; // or 100_GeV
double distance = 5 * Acts::UnitConstants::m; // or 5_m
// GOOD: Variable names indicate non-native units
double momentumInMeV = 10.0; // would be 0.01 in native units (GeV)
// GOOD: Unqualified values are in native units
double energyGeV = 100.0; // native unit GeV, clear from context
// Output conversion
double output_in_meters = distance / 1_m;

Here's a comprehensive example showing various ways to work with units:

using namespace Acts::UnitLiterals;
// Define input values with units (via unit constants)
double width = 12 * Acts::UnitConstants::mm;
double mmuon = 105.7 * Acts::UnitConstants::MeV;
// Define input values with units (via user literals)
double length = 23_cm;
double time = 1214.2_ns;
double angle = 123_degree;
double particleMomentum = 2.5_TeV;
double mass = 511_keV;
double velocity = 345_m / 1_s;
double bfield = 3.9_T;
// All values are now in native units and can be used in calculations
// Native units: mm, GeV, radian, GeV/(e*mm), etc.

Converting output values from native units:

using namespace Acts::UnitLiterals;
// Assume trackPars is a track parameter object with methods
// that return values in native units
// Convert output values (via unit constants)
double t_in_ns = trackPars.time() / Acts::UnitConstants::ns;
// Convert output values (via user literals)
double x_in_mm = trackPars.position(gctx)[Acts::eBoundLoc0] / 1_mm;
double p_in_TeV = trackPars.absoluteMomentum() / 1_TeV;
Note
A helper script is available in Core/scripts/print_units_physical_constants.py to validate some of the numerical values.

Variable Documentation

◆ cm

double Acts::UnitConstants::cm = 1e1 * mm
constexpr

Centimeter - 1e-2 meter.

◆ cm2

double Acts::UnitConstants::cm2 = cm * cm
constexpr

Square centimeter.

◆ cm3

double Acts::UnitConstants::cm3 = cm * cm * cm
constexpr

Cubic centimeter.

◆ degree

double Acts::UnitConstants::degree = std::numbers::pi / 180. / rad
constexpr

Degree - pi/180 radians.

◆ e

double Acts::UnitConstants::e = 1.0
constexpr

Charge, native unit e (elementary charge).

◆ eV

double Acts::UnitConstants::eV = 1e-9 * GeV
constexpr

Electronvolt - 1e-9 GeV.

◆ fm

double Acts::UnitConstants::fm = 1e-12 * mm
constexpr

Femtometer - 1e-15 meter.

◆ fs

double Acts::UnitConstants::fs = 1e-15 * s
constexpr

Femtosecond - 1e-15 second.

◆ g

double Acts::UnitConstants::g = 1.0 / 1.782662e-24
constexpr

Gram in GeV/c²

Note
1eV/c² == 1.782662e-36kg 1GeV/c² == 1.782662e-27kg -> 1kg == (1/1.782662e-27)GeV/c² -> 1g == (1/(1e3*1.782662e-27))GeV/c²

◆ Gauss

double Acts::UnitConstants::Gauss = 1e-4 * T
constexpr

Gauss - 1e-4 Tesla.

◆ GeV

double Acts::UnitConstants::GeV = 1.0
constexpr

Gigaelectronvolt - native unit for energy/mass/momentum.

◆ h

double Acts::UnitConstants::h = 3600.0 * s
constexpr

Hour - 3600 seconds.

◆ J

double Acts::UnitConstants::J = 6241509074.460763 * GeV
constexpr

Joule in GeV.

◆ keV

double Acts::UnitConstants::keV = 1e-6 * GeV
constexpr

Kiloelectronvolt - 1e-6 GeV.

◆ kg

double Acts::UnitConstants::kg = 1.0 / 1.782662e-27
constexpr

Kilogram in GeV/c²

◆ kGauss

double Acts::UnitConstants::kGauss = 1e-1 * T
constexpr

Kilogauss - 1e-1 Tesla.

◆ km

double Acts::UnitConstants::km = 1e6 * mm
constexpr

Kilometer - 1e3 meter.

◆ m

double Acts::UnitConstants::m = 1e3 * mm
constexpr

Meter.

◆ m2

double Acts::UnitConstants::m2 = m * m
constexpr

Square meter.

◆ m3

double Acts::UnitConstants::m3 = m * m * m
constexpr

Cubic meter.

◆ MeV

double Acts::UnitConstants::MeV = 1e-3 * GeV
constexpr

Megaelectronvolt - 1e-3 GeV.

◆ min

double Acts::UnitConstants::min = 60.0 * s
constexpr

Minute - 60 seconds.

◆ mm

double Acts::UnitConstants::mm = 1.0
constexpr

Millimeter - native unit for length.

◆ mm2

double Acts::UnitConstants::mm2 = mm * mm
constexpr

Square millimeter - native unit for area.

◆ mm3

double Acts::UnitConstants::mm3 = mm * mm * mm
constexpr

Cubic millimeter - native unit for volume.

◆ mol

double Acts::UnitConstants::mol = 1.0
constexpr

Amount of substance, native unit mol.

◆ mrad

double Acts::UnitConstants::mrad = 1e-3
constexpr

Milliradian - 1e-3 radian.

◆ ms

double Acts::UnitConstants::ms = 1e-3 * s
constexpr

Millisecond - 1e-3 second.

◆ nm

double Acts::UnitConstants::nm = 1e-6 * mm
constexpr

Nanometer - 1e-9 meter.

◆ ns

double Acts::UnitConstants::ns = 1e-9 * s
constexpr

Nanosecond - 1e-9 second.

◆ pm

double Acts::UnitConstants::pm = 1e-9 * mm
constexpr

Picometer - 1e-12 meter.

◆ ps

double Acts::UnitConstants::ps = 1e-12 * s
constexpr

Picosecond - 1e-12 second.

◆ rad

double Acts::UnitConstants::rad = 1.0
constexpr

Radian - native unit for angle.

◆ s

double Acts::UnitConstants::s = 299792458000.0
constexpr
Note
Depends on speed of light in SI units

◆ T

double Acts::UnitConstants::T = 0.000299792458
constexpr

Magnetic field, native unit (eV*s)/(e*m²).

Note
Depends on speed of light in SI units

◆ TeV

double Acts::UnitConstants::TeV = 1e3 * GeV
constexpr

Teraelectronvolt - 1e3 GeV.

◆ u

double Acts::UnitConstants::u = 0.93149410242
constexpr

atomic mass unit u

◆ um

double Acts::UnitConstants::um = 1e-3 * mm
constexpr

Micrometer - 1e-6 meter.

◆ us

double Acts::UnitConstants::us = 1e-6 * s
constexpr

Microsecond - 1e-6 second.