Skip to content

Use a consistent system of units

Disclaimer: Originally, I only wanted to add a reasonable unit definition for time. After looking through the code, I decided to fix this properly. I might have gone a bit overboard.

This reworks the unit systems to use a single set of consistent base units. All internal calculations are assumed to happen with those units and the conversion to them happens only at the input and output level. Within this system, no additional conversion factors are needed, e.g. converting momentum and magnetic field to radius. Most internal units stay the same, but the following (non-obvious) changes are needed:

  • Time is stored as speed-of-light * time with the same units as lengths. All components in four-vectors can be treated the same, and the numerical values are directly comparable.
  • Magnetic fields are stored as GeV/(e*mm). The conversion factors that are needed when calculating in Tesla have been effectively moved into the unit definition itself.
  • Speed-of-light in those units is 1 and mass, energy, momentum all use the same unit, i.e. GeV.

The resulting main changes in the code:

  • SI2Nat and Nat2SI become obsolete and have been removed.

  • New unit constants are defined in namespace UnitConstants to be consistent with the naming convention in the rest of the code base.

  • C++11 user literals are available in namespace UnitLiterals to simplify the definition of physical quantities. Quantities can now be defined as

    using namespace Acts::UnitLiterals;
    
    double l = 12.3_cm;
    double t = 12_ns;
    double p = 123.45_MeV;
    double m = 511_keV;
    double q_over_p = 1_e / 12.5_GeV;
  • Switch all code in core and tests to use either the UnitConstants when no namespace importing is possible, e.g. in headers, or UnitLiterals, where namespace importing is possible, e.g. in the tests .cpp files. The old units namespace is left as-is for now and should be removed after the downstream projects acts-framework and acts-fatras have been adjusted.

A detailed description can also be found in the Acts/Utilities/Units.hpp file itself.

There is one problem with the current solution which needs to addressed in a separate issue. The SI masses kg and g are defined in terms of GeV for consistency which results in large conversion factors. The only place where I saw them used is in the material description to define mass densities. The mass densities are not used directly, but are converted back into a particle density by multiplying with some mass factor and only the resulting constants are actually used in the computations. All tests seem to run fine, but revisiting which material properties are stored and in what units might be a good task for the future.

Closes longstanding issue #478 (closed). The necessary follow-up change is tracked in #608 (closed).

Edited by Moritz Kiehn

Merge request reports