|
|
|||
Warning, file /acts/Core/include/Acts/Definitions/Units.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 #include <numbers> 0012 0013 namespace Acts { 0014 0015 /// @namespace Acts::UnitConstants 0016 /// @brief Constants and helper literals for physical units. 0017 /// All physical quantities have both a numerical value and a unit. For the 0018 /// computations we always choose a particular unit for a given physical 0019 /// quantity so we only need to consider the numerical values as such. The 0020 /// chosen base unit for a particular physical dimension, e.g. length, time, or 0021 /// energy, within this code base is called the native unit. The base units 0022 /// should be chosen such that they are internally consistent, require the least 0023 /// amount of explicit conversion factors (ideally none at all), and have 0024 /// typical numerical values close to unity to reduce numerical issues. 0025 /// 0026 /// Here, the following native units are used: 0027 /// 0028 /// - Length is expressed in mm. 0029 /// - Time is expressed in [speed-of-light * time] == mm. A consequence 0030 /// of this choice is that the speed-of-light expressed in native units 0031 /// is 1. 0032 /// - Angles are expressed in radian. 0033 /// - Energy, mass, and momentum are all expressed in GeV (consistent with 0034 /// speed-of-light == 1). 0035 /// - Electric charge is expressed in e, i.e. units of the elementary charge. 0036 /// - The magnetic field is expressed in GeV/(e*mm). The magnetic field 0037 /// connects momentum to length, e.g. in SI units the radius of a charged 0038 /// particle trajectory in a constant magnetic field is given by 0039 /// 0040 /// @f$ 0041 /// \text{radius} = - \frac{\text{momentum} }{ \text{charge} } / \text{field} 0042 /// @f$ 0043 /// 0044 /// With the chosen magnetic field unit the expression above stays the 0045 /// same and no additional conversion factors are necessary. 0046 /// 0047 /// Depending on the context a physical quantity might not be given in the 0048 /// native units. In this case we need to convert to the native unit first 0049 /// before the value can be used. The necessary conversion factors are defined 0050 /// in @ref Acts::UnitConstants. Multiplying a value with the unit constant 0051 /// produces the equivalent value in the native unit, e.g. 0052 /// 0053 /// @snippet{trimleft} examples/units.cpp Using Unit Constants 0054 /// 0055 /// To further simplify the usage, physical quantities can also be expressed 0056 /// via [C++ user 0057 /// literals](https://en.cppreference.com/cpp/language/user_literal) 0058 /// defined 0059 /// in @ref Acts::UnitLiterals. This allows us to express quantities in a 0060 /// concise way: 0061 /// 0062 /// @snippet{trimleft} examples/units.cpp Using Unit Literals 0063 /// 0064 /// @warning Since using user-defined literals requires a namespace import of 0065 /// @ref Acts::UnitLiterals it should not be used in headers since it 0066 /// would (accidentally) modify the namespace wherever the header is 0067 /// included. 0068 /// 0069 /// To ensure consistent computations and results the following guidelines 0070 /// **must** be followed when handling physical quantities with units: 0071 /// 0072 /// @snippet{trimleft} examples/units.cpp Unit Best Practices 0073 /// 0074 /// Here's a comprehensive example showing various ways to work with units: 0075 /// 0076 /// @snippet{trimleft} examples/units.cpp Comprehensive Units Example 0077 /// 0078 /// Converting output values from native units: 0079 /// 0080 /// @snippet{trimleft} examples/units.cpp Converting Output Values 0081 0082 namespace UnitConstants { 0083 // Length, native unit mm 0084 /// Millimeter - native unit for length 0085 constexpr double mm = 1.0; 0086 /// Femtometer - 1e-15 meter 0087 constexpr double fm = 1e-12 * mm; 0088 /// Picometer - 1e-12 meter 0089 constexpr double pm = 1e-9 * mm; 0090 /// Nanometer - 1e-9 meter 0091 constexpr double nm = 1e-6 * mm; 0092 /// Micrometer - 1e-6 meter 0093 constexpr double um = 1e-3 * mm; 0094 /// Centimeter - 1e-2 meter 0095 constexpr double cm = 1e1 * mm; 0096 /// Meter 0097 constexpr double m = 1e3 * mm; 0098 /// Kilometer - 1e3 meter 0099 constexpr double km = 1e6 * mm; 0100 // Shortcuts for commonly used area and volume units. This intentionally 0101 // contains not all possible combinations to avoid cluttering the namespace. 0102 // Missing area or volume units can always be defined on the fly using the 0103 // existing length units e.g. 1fm³ -> 1fm * 1fm * 1fm 0104 // Area, native unit mm² 0105 /// Square millimeter - native unit for area 0106 constexpr double mm2 = mm * mm; 0107 /// Square centimeter 0108 constexpr double cm2 = cm * cm; 0109 /// Square meter 0110 constexpr double m2 = m * m; 0111 // Volume, native unit mm³ 0112 /// Cubic millimeter - native unit for volume 0113 constexpr double mm3 = mm * mm * mm; 0114 /// Cubic centimeter 0115 constexpr double cm3 = cm * cm * cm; 0116 /// Cubic meter 0117 constexpr double m3 = m * m * m; 0118 // Time, native unit mm = [speed-of-light * time] = mm/s * s 0119 /// @note Depends on speed of light in SI units 0120 constexpr double s = 299792458000.0; // = 299792458.0 * (m / 1.0) * 1.0; 0121 /// Femtosecond - 1e-15 second 0122 constexpr double fs = 1e-15 * s; 0123 /// Picosecond - 1e-12 second 0124 constexpr double ps = 1e-12 * s; 0125 /// Nanosecond - 1e-9 second 0126 constexpr double ns = 1e-9 * s; 0127 /// Microsecond - 1e-6 second 0128 constexpr double us = 1e-6 * s; 0129 /// Millisecond - 1e-3 second 0130 constexpr double ms = 1e-3 * s; 0131 /// Minute - 60 seconds 0132 constexpr double min = 60.0 * s; 0133 /// Hour - 3600 seconds 0134 constexpr double h = 3600.0 * s; 0135 // Angles, native unit radian 0136 /// Milliradian - 1e-3 radian 0137 constexpr double mrad = 1e-3; 0138 /// Radian - native unit for angle 0139 constexpr double rad = 1.0; 0140 /// Degree - pi/180 radians 0141 constexpr double degree = std::numbers::pi / 180. / rad; 0142 /// Gigaelectronvolt - native unit for energy/mass/momentum 0143 constexpr double GeV = 1.0; 0144 /// Electronvolt - 1e-9 GeV 0145 constexpr double eV = 1e-9 * GeV; 0146 /// Kiloelectronvolt - 1e-6 GeV 0147 constexpr double keV = 1e-6 * GeV; 0148 /// Megaelectronvolt - 1e-3 GeV 0149 constexpr double MeV = 1e-3 * GeV; 0150 /// Teraelectronvolt - 1e3 GeV 0151 constexpr double TeV = 1e3 * GeV; 0152 /// Joule in GeV 0153 constexpr double J = 6241509074.460763 * GeV; 0154 /// atomic mass unit u 0155 constexpr double u = 0.93149410242; 0156 /// Gram in GeV/c² 0157 /// @note 1eV/c² == 1.782662e-36kg 0158 /// 1GeV/c² == 1.782662e-27kg 0159 /// -> 1kg == (1/1.782662e-27)GeV/c² 0160 /// -> 1g == (1/(1e3*1.782662e-27))GeV/c² 0161 constexpr double g = 1.0 / 1.782662e-24; 0162 /// Kilogram in GeV/c² 0163 constexpr double kg = 1.0 / 1.782662e-27; 0164 /// Charge, native unit e (elementary charge) 0165 constexpr double e = 1.0; 0166 /// Magnetic field, native unit (eV*s)/(e*m²) 0167 /// @note Depends on speed of light in SI units 0168 constexpr double T = 0.000299792458; // = eV * s / (e * m2); 0169 /// Gauss - 1e-4 Tesla 0170 constexpr double Gauss = 1e-4 * T; 0171 /// Kilogauss - 1e-1 Tesla 0172 constexpr double kGauss = 1e-1 * T; 0173 /// Amount of substance, native unit mol 0174 constexpr double mol = 1.0; 0175 } // namespace UnitConstants 0176 0177 /// @brief Namespace for user-defined literals for physical units. See @ref 0178 /// UnitConstants for details. 0179 namespace UnitLiterals { 0180 // define user literal functions for the given unit constant 0181 #define ACTS_DEFINE_UNIT_LITERAL(name) \ 0182 constexpr double operator""_##name(long double x) { \ 0183 return ::Acts::UnitConstants::name * x; \ 0184 } \ 0185 constexpr double operator""_##name(unsigned long long x) { \ 0186 return ::Acts::UnitConstants::name * x; \ 0187 } 0188 ACTS_DEFINE_UNIT_LITERAL(fm) 0189 ACTS_DEFINE_UNIT_LITERAL(pm) 0190 ACTS_DEFINE_UNIT_LITERAL(nm) 0191 ACTS_DEFINE_UNIT_LITERAL(um) 0192 ACTS_DEFINE_UNIT_LITERAL(mm) 0193 ACTS_DEFINE_UNIT_LITERAL(cm) 0194 ACTS_DEFINE_UNIT_LITERAL(m) 0195 ACTS_DEFINE_UNIT_LITERAL(km) 0196 ACTS_DEFINE_UNIT_LITERAL(mm2) 0197 ACTS_DEFINE_UNIT_LITERAL(cm2) 0198 ACTS_DEFINE_UNIT_LITERAL(m2) 0199 ACTS_DEFINE_UNIT_LITERAL(mm3) 0200 ACTS_DEFINE_UNIT_LITERAL(cm3) 0201 ACTS_DEFINE_UNIT_LITERAL(m3) 0202 ACTS_DEFINE_UNIT_LITERAL(fs) 0203 ACTS_DEFINE_UNIT_LITERAL(ps) 0204 ACTS_DEFINE_UNIT_LITERAL(ns) 0205 ACTS_DEFINE_UNIT_LITERAL(us) 0206 ACTS_DEFINE_UNIT_LITERAL(ms) 0207 ACTS_DEFINE_UNIT_LITERAL(s) 0208 ACTS_DEFINE_UNIT_LITERAL(min) 0209 ACTS_DEFINE_UNIT_LITERAL(h) 0210 ACTS_DEFINE_UNIT_LITERAL(mrad) 0211 ACTS_DEFINE_UNIT_LITERAL(rad) 0212 ACTS_DEFINE_UNIT_LITERAL(degree) 0213 ACTS_DEFINE_UNIT_LITERAL(eV) 0214 ACTS_DEFINE_UNIT_LITERAL(keV) 0215 ACTS_DEFINE_UNIT_LITERAL(MeV) 0216 ACTS_DEFINE_UNIT_LITERAL(GeV) 0217 ACTS_DEFINE_UNIT_LITERAL(TeV) 0218 ACTS_DEFINE_UNIT_LITERAL(J) 0219 ACTS_DEFINE_UNIT_LITERAL(u) 0220 ACTS_DEFINE_UNIT_LITERAL(g) 0221 ACTS_DEFINE_UNIT_LITERAL(kg) 0222 ACTS_DEFINE_UNIT_LITERAL(e) 0223 ACTS_DEFINE_UNIT_LITERAL(T) 0224 ACTS_DEFINE_UNIT_LITERAL(Gauss) 0225 ACTS_DEFINE_UNIT_LITERAL(kGauss) 0226 ACTS_DEFINE_UNIT_LITERAL(mol) 0227 // not needed anymore. undef to prevent littering the namespace 0228 #undef ACTS_DEFINE_UNIT_LITERAL 0229 } // namespace UnitLiterals 0230 0231 /// Physical constants in native units. 0232 /// 0233 /// Unit constants are intentionally not listed. 0234 namespace PhysicalConstants { 0235 /// Speed of light in vacuum - native unit (dimensionless) 0236 constexpr double c = 1.0; 0237 /// Reduced Planck constant h/2*pi. 0238 /// 0239 /// Computed from CODATA 2018 constants to double precision. 0240 constexpr double hbar = 0241 6.582119569509066e-25 * UnitConstants::GeV * UnitConstants::s; 0242 } // namespace PhysicalConstants 0243 0244 } // namespace Acts
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|