File indexing completed on 2025-10-22 07:53:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0013
0014 #include <cmath>
0015 #include <limits>
0016 #include <numbers>
0017
0018 using namespace Acts::UnitLiterals;
0019
0020 static constexpr auto eps = std::numeric_limits<double>::epsilon();
0021
0022 namespace ActsTests {
0023
0024 BOOST_AUTO_TEST_SUITE(DefinitionsUnits)
0025
0026 BOOST_AUTO_TEST_CASE(Length) {
0027 CHECK_CLOSE_REL(1_m, 1e-3_km, eps);
0028 CHECK_CLOSE_REL(1_m, 1e2_cm, eps);
0029 CHECK_CLOSE_REL(1_m, 1e3_mm, eps);
0030 CHECK_CLOSE_REL(1_m, 1e6_um, eps);
0031 CHECK_CLOSE_REL(1_m, 1e9_nm, eps);
0032 CHECK_CLOSE_REL(1_m, 1e12_pm, eps);
0033 CHECK_CLOSE_REL(1_m, 1e15_fm, eps);
0034 }
0035
0036 BOOST_AUTO_TEST_CASE(Area) {
0037 CHECK_CLOSE_REL(1_mm * 1_mm, 1_mm2, eps);
0038 CHECK_CLOSE_REL(1_mm * 1_mm, 0.01_cm2, eps);
0039 CHECK_CLOSE_REL(1_mm * 1_mm, 0.000001_m2, eps);
0040 CHECK_CLOSE_REL(1_cm * 1_cm, 100_mm2, eps);
0041 CHECK_CLOSE_REL(1_cm * 1_cm, 1_cm2, eps);
0042 CHECK_CLOSE_REL(1_cm * 1_cm, 0.0001_m2, eps);
0043 CHECK_CLOSE_REL(1_m * 1_m, 1000000_mm2, eps);
0044 CHECK_CLOSE_REL(1_m * 1_m, 10000_cm2, eps);
0045 CHECK_CLOSE_REL(1_m * 1_m, 1_m2, eps);
0046 }
0047
0048 BOOST_AUTO_TEST_CASE(Volume) {
0049 CHECK_CLOSE_REL(1_mm * 1_mm * 1_mm, 1_mm3, eps);
0050 CHECK_CLOSE_REL(1_mm2 * 1_mm, 1_mm3, eps);
0051 CHECK_CLOSE_REL(1_cm * 1_cm * 1_cm, 1_cm3, eps);
0052 CHECK_CLOSE_REL(1_cm2 * 1_cm, 1_cm3, eps);
0053 CHECK_CLOSE_REL(1_m * 1_m * 1_m, 1_m3, eps);
0054 CHECK_CLOSE_REL(1_m2 * 1_m, 1_m3, eps);
0055 }
0056
0057 BOOST_AUTO_TEST_CASE(Time) {
0058 CHECK_CLOSE_REL(1_h, 60_min, eps);
0059 CHECK_CLOSE_REL(1_h, 3600_s, eps);
0060 CHECK_CLOSE_REL(1_min, 60_s, eps);
0061 CHECK_CLOSE_REL(1_s, 1e3_ms, eps);
0062 CHECK_CLOSE_REL(1_s, 1e6_us, eps);
0063 CHECK_CLOSE_REL(1_s, 1e9_ns, eps);
0064 CHECK_CLOSE_REL(1_s, 1e12_ps, eps);
0065 CHECK_CLOSE_REL(1_s, 1e15_fs, eps);
0066 }
0067
0068 BOOST_AUTO_TEST_CASE(Angle) {
0069 CHECK_CLOSE_REL(45_degree, std::numbers::pi / 4. * 1_rad, eps);
0070 CHECK_CLOSE_REL(90_degree, std::numbers::pi / 2. * 1_rad, eps);
0071 CHECK_CLOSE_REL(180_degree, std::numbers::pi * 1_rad, eps);
0072 CHECK_CLOSE_REL(360_degree, 2 * std::numbers::pi * 1_rad, eps);
0073 CHECK_CLOSE_REL(1_mm / 1_m, 1_mrad, eps);
0074 CHECK_CLOSE_REL(1_um / 1_mm, 1_mrad, eps);
0075 }
0076
0077 BOOST_AUTO_TEST_CASE(Energy) {
0078 CHECK_CLOSE_REL(1_MeV, 1e6_eV, eps);
0079 CHECK_CLOSE_REL(1_MeV, 1e3_keV, eps);
0080 CHECK_CLOSE_REL(1_MeV, 1e-3_GeV, eps);
0081 CHECK_CLOSE_REL(1_MeV, 1e-6_TeV, eps);
0082 }
0083
0084 BOOST_AUTO_TEST_CASE(Mass) {
0085
0086 CHECK_CLOSE_REL(1_kg, 1000_g, eps);
0087 CHECK_CLOSE_REL(0.001_kg, 1_g, eps);
0088 CHECK_CLOSE_REL(1_u, 931.49410242_MeV, eps);
0089 CHECK_CLOSE_REL(1_u, 1.66053906660e-24_g, 1e-7);
0090 }
0091
0092 BOOST_AUTO_TEST_CASE(MassEnergy) {
0093
0094 CHECK_CLOSE_REL(1.782662e-36_kg, 1_eV, eps);
0095 CHECK_CLOSE_REL(1.782662e-33_kg, 1_keV, eps);
0096 CHECK_CLOSE_REL(1.782662e-30_kg, 1_MeV, eps);
0097 CHECK_CLOSE_REL(1.782662e-27_kg, 1_GeV, eps);
0098 CHECK_CLOSE_REL(1.782662e-33_g, 1_eV, eps);
0099 CHECK_CLOSE_REL(1.782662e-30_g, 1_keV, eps);
0100 CHECK_CLOSE_REL(1.782662e-27_g, 1_MeV, eps);
0101 CHECK_CLOSE_REL(1.782662e-24_g, 1_GeV, eps);
0102 }
0103
0104 BOOST_AUTO_TEST_CASE(DecayWidthTime) {
0105 using Acts::PhysicalConstants::hbar;
0106
0107
0108 CHECK_CLOSE_REL(hbar / 2.5284e-17_GeV, 26.032746062598505_ns, 1e-7);
0109
0110 CHECK_CLOSE_REL(hbar / 2.9959847e-19_GeV, 2.1969803498887713_us, 1e-7);
0111
0112 CHECK_CLOSE_REL(hbar / 1.42_GeV, 4.635295432723526e-10_fs, 1e-7);
0113 }
0114
0115 BOOST_AUTO_TEST_CASE(MagneticField) {
0116 CHECK_CLOSE_REL(10_kGauss, 1_T, eps);
0117 CHECK_CLOSE_REL(1_kGauss, 1000_Gauss, eps);
0118 }
0119
0120 BOOST_AUTO_TEST_CASE(MomentumRadius) {
0121
0122 CHECK_CLOSE_REL(1_GeV / (1_e * 1_T), 3.3336_m, 1e-3);
0123 CHECK_CLOSE_REL(1_GeV / (1_e * 2_T), 166.8_cm, 1e-3);
0124 CHECK_CLOSE_REL(1_GeV / (2_e * 1_T), 166.8_cm, 1e-3);
0125 CHECK_CLOSE_REL(1_GeV / (1_e * 4_T), 83.39_cm, 1e-3);
0126 CHECK_CLOSE_REL(1_GeV / (2_e * 2_T), 83.39_cm, 1e-3);
0127 }
0128
0129 BOOST_AUTO_TEST_CASE(PhysicalConstants) {
0130 using Acts::PhysicalConstants::hbar;
0131
0132 CHECK_CLOSE_REL(hbar, 6.62607015e-34 * 1_J * 1_s / (2 * std::numbers::pi),
0133 1e-6);
0134 CHECK_CLOSE_REL(hbar, 4.135667696e-15 * 1_eV * 1_s / (2 * std::numbers::pi),
0135 1e-7);
0136
0137 using Acts::PhysicalConstants::c;
0138
0139 BOOST_CHECK_EQUAL(c, 1.0);
0140 }
0141
0142 BOOST_AUTO_TEST_SUITE_END()
0143
0144 }