Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UnitsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file UnitsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
13 
14 #include <cmath>
15 #include <limits>
16 
17 using namespace Acts::UnitLiterals;
18 
19 static constexpr auto eps = std::numeric_limits<double>::epsilon();
20 
21 BOOST_AUTO_TEST_SUITE(DefinitionsUnits)
22 
24  CHECK_CLOSE_REL(1_m, 1e-3_km, eps);
25  CHECK_CLOSE_REL(1_m, 1e2_cm, eps);
26  CHECK_CLOSE_REL(1_m, 1e3_mm, eps);
27  CHECK_CLOSE_REL(1_m, 1e6_um, eps);
28  CHECK_CLOSE_REL(1_m, 1e9_nm, eps);
29  CHECK_CLOSE_REL(1_m, 1e12_pm, eps);
30  CHECK_CLOSE_REL(1_m, 1e15_fm, eps);
31 }
32 
34  CHECK_CLOSE_REL(1_mm * 1_mm, 1_mm2, eps);
35  CHECK_CLOSE_REL(1_mm * 1_mm, 0.01_cm2, eps);
36  CHECK_CLOSE_REL(1_mm * 1_mm, 0.000001_m2, eps);
37  CHECK_CLOSE_REL(1_cm * 1_cm, 100_mm2, eps);
38  CHECK_CLOSE_REL(1_cm * 1_cm, 1_cm2, eps);
39  CHECK_CLOSE_REL(1_cm * 1_cm, 0.0001_m2, eps);
40  CHECK_CLOSE_REL(1_m * 1_m, 1000000_mm2, eps);
41  CHECK_CLOSE_REL(1_m * 1_m, 10000_cm2, eps);
42  CHECK_CLOSE_REL(1_m * 1_m, 1_m2, eps);
43 }
44 
46  CHECK_CLOSE_REL(1_mm * 1_mm * 1_mm, 1_mm3, eps);
47  CHECK_CLOSE_REL(1_mm2 * 1_mm, 1_mm3, eps);
48  CHECK_CLOSE_REL(1_cm * 1_cm * 1_cm, 1_cm3, eps);
49  CHECK_CLOSE_REL(1_cm2 * 1_cm, 1_cm3, eps);
50  CHECK_CLOSE_REL(1_m * 1_m * 1_m, 1_m3, eps);
51  CHECK_CLOSE_REL(1_m2 * 1_m, 1_m3, eps);
52 }
53 
55  CHECK_CLOSE_REL(1_h, 60_min, eps);
56  CHECK_CLOSE_REL(1_h, 3600_s, eps);
57  CHECK_CLOSE_REL(1_min, 60_s, eps);
58  CHECK_CLOSE_REL(1_s, 1e3_ms, eps);
59  CHECK_CLOSE_REL(1_s, 1e6_us, eps);
60  CHECK_CLOSE_REL(1_s, 1e9_ns, eps);
61  CHECK_CLOSE_REL(1_s, 1e12_ps, eps);
62  CHECK_CLOSE_REL(1_s, 1e15_fs, eps);
63 }
64 
66  CHECK_CLOSE_REL(45_degree, M_PI / 4 * 1_rad, eps);
67  CHECK_CLOSE_REL(90_degree, M_PI / 2 * 1_rad, eps);
68  CHECK_CLOSE_REL(180_degree, M_PI * 1_rad, eps);
69  CHECK_CLOSE_REL(360_degree, 2 * M_PI * 1_rad, eps);
70  CHECK_CLOSE_REL(1_mm / 1_m, 1_mrad, eps);
71  CHECK_CLOSE_REL(1_um / 1_mm, 1_mrad, eps);
72 }
73 
75  CHECK_CLOSE_REL(1_MeV, 1e6_eV, eps);
76  CHECK_CLOSE_REL(1_MeV, 1e3_keV, eps);
77  CHECK_CLOSE_REL(1_MeV, 1e-3_GeV, eps);
78  CHECK_CLOSE_REL(1_MeV, 1e-6_TeV, eps);
79 }
80 
82  // always assume c == 1
83  CHECK_CLOSE_REL(1_kg, 1000_g, eps);
84  CHECK_CLOSE_REL(0.001_kg, 1_g, eps);
85  CHECK_CLOSE_REL(1_u, 931.49410242_MeV, eps);
86  CHECK_CLOSE_REL(1_u, 1.66053906660e-24_g, 1e-7);
87 }
88 
89 BOOST_AUTO_TEST_CASE(MassEnergy) {
90  // always assume c == 1
91  CHECK_CLOSE_REL(1.782662e-36_kg, 1_eV, eps);
92  CHECK_CLOSE_REL(1.782662e-33_kg, 1_keV, eps);
93  CHECK_CLOSE_REL(1.782662e-30_kg, 1_MeV, eps);
94  CHECK_CLOSE_REL(1.782662e-27_kg, 1_GeV, eps);
95  CHECK_CLOSE_REL(1.782662e-33_g, 1_eV, eps);
96  CHECK_CLOSE_REL(1.782662e-30_g, 1_keV, eps);
97  CHECK_CLOSE_REL(1.782662e-27_g, 1_MeV, eps);
98  CHECK_CLOSE_REL(1.782662e-24_g, 1_GeV, eps);
99 }
100 
101 BOOST_AUTO_TEST_CASE(DecayWidthTime) {
103  // lifetime is hbar / decay-width
104  // pion
105  CHECK_CLOSE_REL(hbar / 2.5284e-17_GeV, 26.032746062598505_ns, 1e-7);
106  // muon
107  CHECK_CLOSE_REL(hbar / 2.9959847e-19_GeV, 2.1969803498887713_us, 1e-7);
108  // top
109  CHECK_CLOSE_REL(hbar / 1.42_GeV, 4.635295432723526e-10_fs, 1e-7);
110 }
111 
113  CHECK_CLOSE_REL(10_kGauss, 1_T, eps);
114  CHECK_CLOSE_REL(1_kGauss, 1000_Gauss, eps);
115 }
116 
117 BOOST_AUTO_TEST_CASE(MomentumRadius) {
118  // note: no conversion factors necessary
119  CHECK_CLOSE_REL(1_GeV / (1_e * 1_T), 3.3336_m, 1e-3);
120  CHECK_CLOSE_REL(1_GeV / (1_e * 2_T), 166.8_cm, 1e-3);
121  CHECK_CLOSE_REL(1_GeV / (2_e * 1_T), 166.8_cm, 1e-3);
122  CHECK_CLOSE_REL(1_GeV / (1_e * 4_T), 83.39_cm, 1e-3);
123  CHECK_CLOSE_REL(1_GeV / (2_e * 2_T), 83.39_cm, 1e-3);
124 }
125 
126 BOOST_AUTO_TEST_CASE(PhysicalConstants) {
128  // see https://en.wikipedia.org/wiki/Planck_constant
129  CHECK_CLOSE_REL(hbar, 6.62607015e-34 * 1_J * 1_s / (2 * M_PI), 1e-6);
130  CHECK_CLOSE_REL(hbar, 4.135667696e-15 * 1_eV * 1_s / (2 * M_PI), 1e-7);
131 
133  // we really want c to be 1
134  BOOST_CHECK(c == 1.0);
135 }
136 
137 BOOST_AUTO_TEST_SUITE_END()