Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:31

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 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Tests/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 BOOST_AUTO_TEST_SUITE(DefinitionsUnits)
0023 
0024 BOOST_AUTO_TEST_CASE(Length) {
0025   CHECK_CLOSE_REL(1_m, 1e-3_km, eps);
0026   CHECK_CLOSE_REL(1_m, 1e2_cm, eps);
0027   CHECK_CLOSE_REL(1_m, 1e3_mm, eps);
0028   CHECK_CLOSE_REL(1_m, 1e6_um, eps);
0029   CHECK_CLOSE_REL(1_m, 1e9_nm, eps);
0030   CHECK_CLOSE_REL(1_m, 1e12_pm, eps);
0031   CHECK_CLOSE_REL(1_m, 1e15_fm, eps);
0032 }
0033 
0034 BOOST_AUTO_TEST_CASE(Area) {
0035   CHECK_CLOSE_REL(1_mm * 1_mm, 1_mm2, eps);
0036   CHECK_CLOSE_REL(1_mm * 1_mm, 0.01_cm2, eps);
0037   CHECK_CLOSE_REL(1_mm * 1_mm, 0.000001_m2, eps);
0038   CHECK_CLOSE_REL(1_cm * 1_cm, 100_mm2, eps);
0039   CHECK_CLOSE_REL(1_cm * 1_cm, 1_cm2, eps);
0040   CHECK_CLOSE_REL(1_cm * 1_cm, 0.0001_m2, eps);
0041   CHECK_CLOSE_REL(1_m * 1_m, 1000000_mm2, eps);
0042   CHECK_CLOSE_REL(1_m * 1_m, 10000_cm2, eps);
0043   CHECK_CLOSE_REL(1_m * 1_m, 1_m2, eps);
0044 }
0045 
0046 BOOST_AUTO_TEST_CASE(Volume) {
0047   CHECK_CLOSE_REL(1_mm * 1_mm * 1_mm, 1_mm3, eps);
0048   CHECK_CLOSE_REL(1_mm2 * 1_mm, 1_mm3, eps);
0049   CHECK_CLOSE_REL(1_cm * 1_cm * 1_cm, 1_cm3, eps);
0050   CHECK_CLOSE_REL(1_cm2 * 1_cm, 1_cm3, eps);
0051   CHECK_CLOSE_REL(1_m * 1_m * 1_m, 1_m3, eps);
0052   CHECK_CLOSE_REL(1_m2 * 1_m, 1_m3, eps);
0053 }
0054 
0055 BOOST_AUTO_TEST_CASE(Time) {
0056   CHECK_CLOSE_REL(1_h, 60_min, eps);
0057   CHECK_CLOSE_REL(1_h, 3600_s, eps);
0058   CHECK_CLOSE_REL(1_min, 60_s, eps);
0059   CHECK_CLOSE_REL(1_s, 1e3_ms, eps);
0060   CHECK_CLOSE_REL(1_s, 1e6_us, eps);
0061   CHECK_CLOSE_REL(1_s, 1e9_ns, eps);
0062   CHECK_CLOSE_REL(1_s, 1e12_ps, eps);
0063   CHECK_CLOSE_REL(1_s, 1e15_fs, eps);
0064 }
0065 
0066 BOOST_AUTO_TEST_CASE(Angle) {
0067   CHECK_CLOSE_REL(45_degree, std::numbers::pi / 4. * 1_rad, eps);
0068   CHECK_CLOSE_REL(90_degree, std::numbers::pi / 2. * 1_rad, eps);
0069   CHECK_CLOSE_REL(180_degree, std::numbers::pi * 1_rad, eps);
0070   CHECK_CLOSE_REL(360_degree, 2 * std::numbers::pi * 1_rad, eps);
0071   CHECK_CLOSE_REL(1_mm / 1_m, 1_mrad, eps);
0072   CHECK_CLOSE_REL(1_um / 1_mm, 1_mrad, eps);
0073 }
0074 
0075 BOOST_AUTO_TEST_CASE(Energy) {
0076   CHECK_CLOSE_REL(1_MeV, 1e6_eV, eps);
0077   CHECK_CLOSE_REL(1_MeV, 1e3_keV, eps);
0078   CHECK_CLOSE_REL(1_MeV, 1e-3_GeV, eps);
0079   CHECK_CLOSE_REL(1_MeV, 1e-6_TeV, eps);
0080 }
0081 
0082 BOOST_AUTO_TEST_CASE(Mass) {
0083   // always assume c == 1
0084   CHECK_CLOSE_REL(1_kg, 1000_g, eps);
0085   CHECK_CLOSE_REL(0.001_kg, 1_g, eps);
0086   CHECK_CLOSE_REL(1_u, 931.49410242_MeV, eps);
0087   CHECK_CLOSE_REL(1_u, 1.66053906660e-24_g, 1e-7);
0088 }
0089 
0090 BOOST_AUTO_TEST_CASE(MassEnergy) {
0091   // always assume c == 1
0092   CHECK_CLOSE_REL(1.782662e-36_kg, 1_eV, eps);
0093   CHECK_CLOSE_REL(1.782662e-33_kg, 1_keV, eps);
0094   CHECK_CLOSE_REL(1.782662e-30_kg, 1_MeV, eps);
0095   CHECK_CLOSE_REL(1.782662e-27_kg, 1_GeV, eps);
0096   CHECK_CLOSE_REL(1.782662e-33_g, 1_eV, eps);
0097   CHECK_CLOSE_REL(1.782662e-30_g, 1_keV, eps);
0098   CHECK_CLOSE_REL(1.782662e-27_g, 1_MeV, eps);
0099   CHECK_CLOSE_REL(1.782662e-24_g, 1_GeV, eps);
0100 }
0101 
0102 BOOST_AUTO_TEST_CASE(DecayWidthTime) {
0103   using Acts::PhysicalConstants::hbar;
0104   // lifetime is hbar / decay-width
0105   // pion
0106   CHECK_CLOSE_REL(hbar / 2.5284e-17_GeV, 26.032746062598505_ns, 1e-7);
0107   // muon
0108   CHECK_CLOSE_REL(hbar / 2.9959847e-19_GeV, 2.1969803498887713_us, 1e-7);
0109   // top
0110   CHECK_CLOSE_REL(hbar / 1.42_GeV, 4.635295432723526e-10_fs, 1e-7);
0111 }
0112 
0113 BOOST_AUTO_TEST_CASE(MagneticField) {
0114   CHECK_CLOSE_REL(10_kGauss, 1_T, eps);
0115   CHECK_CLOSE_REL(1_kGauss, 1000_Gauss, eps);
0116 }
0117 
0118 BOOST_AUTO_TEST_CASE(MomentumRadius) {
0119   // note: no conversion factors necessary
0120   CHECK_CLOSE_REL(1_GeV / (1_e * 1_T), 3.3336_m, 1e-3);
0121   CHECK_CLOSE_REL(1_GeV / (1_e * 2_T), 166.8_cm, 1e-3);
0122   CHECK_CLOSE_REL(1_GeV / (2_e * 1_T), 166.8_cm, 1e-3);
0123   CHECK_CLOSE_REL(1_GeV / (1_e * 4_T), 83.39_cm, 1e-3);
0124   CHECK_CLOSE_REL(1_GeV / (2_e * 2_T), 83.39_cm, 1e-3);
0125 }
0126 
0127 BOOST_AUTO_TEST_CASE(PhysicalConstants) {
0128   using Acts::PhysicalConstants::hbar;
0129   // see https://en.wikipedia.org/wiki/Planck_constant
0130   CHECK_CLOSE_REL(hbar, 6.62607015e-34 * 1_J * 1_s / (2 * std::numbers::pi),
0131                   1e-6);
0132   CHECK_CLOSE_REL(hbar, 4.135667696e-15 * 1_eV * 1_s / (2 * std::numbers::pi),
0133                   1e-7);
0134 
0135   using Acts::PhysicalConstants::c;
0136   // we really want c to be 1
0137   BOOST_CHECK_EQUAL(c, 1.0);
0138 }
0139 
0140 BOOST_AUTO_TEST_SUITE_END()