Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:58

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/definitions/algebra.hpp"
0013 
0014 // System include(s)
0015 #include <cmath>
0016 #include <numbers>
0017 
0018 namespace detray {
0019 
0020 /// Unit conversion factors
0021 template <concepts::scalar scalar_t>
0022 struct unit {
0023   /// Length, native unit mm
0024   /// @{
0025   static constexpr scalar_t um{static_cast<scalar_t>(1e-3)};
0026   static constexpr scalar_t mm{static_cast<scalar_t>(1.0)};
0027   static constexpr scalar_t cm{static_cast<scalar_t>(1e1)};
0028   static constexpr scalar_t m{static_cast<scalar_t>(1e3)};
0029   /// @}
0030 
0031   /// Area, native unit mm2
0032   /// @{
0033   /// mm²
0034   static constexpr scalar_t mm2{static_cast<scalar_t>(1.0)};
0035   /// cm²
0036   static constexpr scalar_t cm2{static_cast<scalar_t>(1e2)};
0037   /// m²
0038   static constexpr scalar_t m2{static_cast<scalar_t>(1e6)};
0039   /// @}
0040 
0041   /// Volume, native unit mm3
0042   /// @{
0043   /// mm³
0044   static constexpr scalar_t mm3{static_cast<scalar_t>(1.0)};
0045   /// cm³
0046   static constexpr scalar_t cm3{static_cast<scalar_t>(1e3)};
0047   /// m³
0048   static constexpr scalar_t m3{static_cast<scalar_t>(1e9)};
0049   /// @}
0050 
0051   /// Time, native unit mm{[speed-of-light * time]{mm/s * s}}
0052   /// @{
0053   static constexpr scalar_t s{static_cast<scalar_t>(299792458000.0)};
0054   static constexpr scalar_t fs{static_cast<scalar_t>(1e-15 * 299792458000.0)};
0055   static constexpr scalar_t ps{static_cast<scalar_t>(1e-12 * 299792458000.0)};
0056   static constexpr scalar_t ns{static_cast<scalar_t>(1e-9 * 299792458000.0)};
0057   static constexpr scalar_t us{static_cast<scalar_t>(1e-6 * 299792458000.0)};
0058   static constexpr scalar_t ms{static_cast<scalar_t>(1e-3 * 299792458000.0)};
0059   static constexpr scalar_t min{static_cast<scalar_t>(60.0 * 299792458000.0)};
0060   static constexpr scalar_t h{static_cast<scalar_t>(3600.0 * 299792458000.0)};
0061   /// @}
0062 
0063   /// Energy, native unit GeV
0064   /// @{
0065   static constexpr scalar_t eV{static_cast<scalar_t>(1e-9)};
0066   static constexpr scalar_t keV{static_cast<scalar_t>(1e-6)};
0067   static constexpr scalar_t MeV{static_cast<scalar_t>(1e-3)};
0068   static constexpr scalar_t GeV{static_cast<scalar_t>(1.0)};
0069   static constexpr scalar_t TeV{static_cast<scalar_t>(1e3)};
0070   /// @}
0071 
0072   /// Atomic mass unit u
0073   /// 1u == 0.93149410242 GeV/c
0074   static constexpr scalar_t u{static_cast<scalar_t>(0.93149410242)};
0075 
0076   /// Mass
0077   ///     1eV/c² == 1.782662e-36kg
0078   ///    1GeV/c² == 1.782662e-27kg
0079   /// ->     1kg == (1/1.782662e-27)GeV/c²
0080   /// ->      1g == (1/(1e3*1.782662e-27))GeV/c²
0081   /// @{
0082   static constexpr scalar_t g{static_cast<scalar_t>(1.0 / 1.782662e-24)};
0083   static constexpr scalar_t kg{static_cast<scalar_t>(1.0 / 1.782662e-27)};
0084   /// @}
0085 
0086   /// Amount of substance, native unit mol
0087   static constexpr scalar_t mol{static_cast<scalar_t>(1.0)};
0088 
0089   /// Charge, native unit e (elementary charge)
0090   static constexpr scalar_t e{static_cast<scalar_t>(1.0)};
0091 
0092   /// Magnetic field, native unit GeV/(e*mm)
0093   static constexpr scalar_t T{static_cast<scalar_t>(
0094       0.000299792458)};  // equivalent to c in appropriate SI units
0095 
0096   // Angles, native unit radian
0097   static constexpr scalar_t mrad{static_cast<scalar_t>(1e-3)};
0098   static constexpr scalar_t rad{static_cast<scalar_t>(1.0)};
0099   static constexpr scalar_t degree{
0100       static_cast<scalar_t>(0.017453292519943295)};  // pi / 180
0101 };
0102 
0103 /// Physical and mathematical constants
0104 template <concepts::scalar scalar_t>
0105 struct constant {
0106   /// Euler's number
0107   static constexpr scalar_t e{static_cast<scalar_t>(std::numbers::e)};
0108   /// Base 2 logarithm of e
0109   static constexpr scalar_t log2e{static_cast<scalar_t>(std::numbers::log2e)};
0110   /// Base 10 logarithm of e
0111   static constexpr scalar_t log10e{static_cast<scalar_t>(std::numbers::log10e)};
0112   /// Natural logarithm of 2
0113   static constexpr scalar_t ln2{static_cast<scalar_t>(std::numbers::ln2)};
0114   /// Natural logarithm of 10
0115   static constexpr scalar_t ln10{static_cast<scalar_t>(std::numbers::ln10)};
0116 
0117   /// π
0118   static constexpr scalar_t pi{static_cast<scalar_t>(std::numbers::pi)};
0119   /// π/2
0120   static constexpr scalar_t pi_2{static_cast<scalar_t>(std::numbers::pi / 2.)};
0121   /// π/4
0122   static constexpr scalar_t pi_4{static_cast<scalar_t>(std::numbers::pi / 4.)};
0123   /// 1/π
0124   static constexpr scalar_t inv_pi{
0125       static_cast<scalar_t>(1. / std::numbers::pi)};
0126   /// 2/π
0127   static constexpr scalar_t inv_2_pi{
0128       static_cast<scalar_t>(2. / std::numbers::pi)};
0129 
0130   /// √2
0131   static constexpr scalar_t sqrt2{static_cast<scalar_t>(std::numbers::sqrt2)};
0132   /// 1/(√2)
0133   static constexpr scalar_t inv_sqrt2{
0134       static_cast<scalar_t>(1. / std::numbers::sqrt2)};
0135 
0136   /// Avogadro constant
0137   static constexpr scalar_t avogadro{
0138       static_cast<scalar_t>(6.02214076e23 / unit<scalar_t>::mol)};
0139 
0140   /// Reduced Planck constant h/2*pi.
0141   ///
0142   /// Computed from CODATA 2018 constants to double precision.
0143   static constexpr scalar_t hbar{static_cast<scalar_t>(
0144       6.582119569509066e-25 * unit<scalar_t>::GeV * unit<scalar_t>::s)};
0145 
0146   // electron mass
0147   // https://physics.nist.gov/cgi-bin/cuu/Value?eqmec2mev (Visited Aug 1st,
0148   // 2024)
0149   static constexpr scalar_t m_e{
0150       static_cast<scalar_t>(0.51099895069 * unit<scalar_t>::MeV)};
0151 };
0152 
0153 }  // namespace detray