Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:16

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