Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChargeTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ChargeTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-2023 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 
14 
15 #include <limits>
16 #include <type_traits>
17 
18 using namespace Acts::UnitLiterals;
19 
20 static auto eps = std::numeric_limits<double>::epsilon();
21 
22 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::Neutral)
23 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::SinglyCharged)
24 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::NonNeutralCharge)
25 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::AnyCharge)
26 
27 BOOST_AUTO_TEST_SUITE(EventDataCharge)
28 
29 BOOST_AUTO_TEST_CASE(Constructibility) {
30  BOOST_CHECK(std::is_trivially_default_constructible_v<Acts::Neutral>);
31  BOOST_CHECK(std::is_trivially_default_constructible_v<Acts::SinglyCharged>);
32  BOOST_CHECK(std::is_nothrow_default_constructible_v<Acts::Neutral>);
33  BOOST_CHECK(std::is_nothrow_default_constructible_v<Acts::SinglyCharged>);
34  BOOST_CHECK(std::is_trivially_constructible_v<Acts::Neutral>);
35  BOOST_CHECK(std::is_trivially_constructible_v<Acts::SinglyCharged>);
36  // BOOST_CHECK(std::is_trivially_constructible_v<Acts::NonNeutralCharge>);
37  // BOOST_CHECK(std::is_trivially_constructible_v<Acts::AnyCharge>);
38  BOOST_CHECK(std::is_nothrow_constructible_v<Acts::Neutral>);
39  BOOST_CHECK(std::is_nothrow_constructible_v<Acts::SinglyCharged>);
40  // BOOST_CHECK(std::is_nothrow_constructible_v<Acts::NonNeutralCharge>);
41  // BOOST_CHECK(std::is_nothrow_constructible_v<Acts::AnyCharge>);
42 }
43 
45  Acts::Neutral q;
46 
47  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
48  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
49  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
50  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
51  CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
52  CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
53 
54  // negative inputs should not occur for neutral particles
55  // the result is not defined, but we check it anyway
56  // update: this is asserted now
57  // CHECK_CLOSE_REL(q.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
58 
59  BOOST_CHECK_EQUAL(q, Acts::Neutral());
60  BOOST_CHECK_EQUAL(Acts::Neutral(), q);
61  BOOST_CHECK_EQUAL(q, Acts::Neutral(0_e));
62  BOOST_CHECK_EQUAL(Acts::Neutral(0_e), q);
63 }
64 
65 BOOST_AUTO_TEST_CASE(SinglyCharged) {
67 
68  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
69  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
70  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
71  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
72  CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
73  CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
74  CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
75 
76  BOOST_CHECK_EQUAL(q, Acts::SinglyCharged());
77  BOOST_CHECK_EQUAL(Acts::SinglyCharged(), q);
78  BOOST_CHECK_EQUAL(q, Acts::SinglyCharged(1_e));
79  BOOST_CHECK_EQUAL(Acts::SinglyCharged(1_e), q);
80 }
81 
82 BOOST_AUTO_TEST_CASE(NonNeutralChargeSingle) {
84 
85  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
86  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
87  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
88  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
89  CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
90  CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
91  CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
92 
93  BOOST_CHECK_EQUAL(q, Acts::NonNeutralCharge(1_e));
94  BOOST_CHECK_EQUAL(Acts::NonNeutralCharge(1_e), q);
95 }
96 
97 BOOST_AUTO_TEST_CASE(NonNeutralChargeMultiple) {
99 
100  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 3_e);
101  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 3_e);
102  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -3_e);
103  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -3_e);
104  CHECK_CLOSE_REL(q.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
105  CHECK_CLOSE_REL(q.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
106  CHECK_CLOSE_REL(q.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
107 
108  BOOST_CHECK(!(q == Acts::NonNeutralCharge(1_e)));
109  BOOST_CHECK(!(Acts::NonNeutralCharge(1_e) == q));
110  BOOST_CHECK(!(q == Acts::NonNeutralCharge(2_e)));
111  BOOST_CHECK(!(Acts::NonNeutralCharge(2_e) == q));
112  BOOST_CHECK(q == Acts::NonNeutralCharge(3_e));
113  BOOST_CHECK(Acts::NonNeutralCharge(3_e) == q);
114 }
115 
116 BOOST_AUTO_TEST_CASE(AnyChargeNeutral) {
117  Acts::AnyCharge q(0_e);
118 
119  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
120  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
121  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
122  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
123  CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
124  CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
125 
126  // negative inputs should not occur for neutral particles
127  // the result is not defined, but we check it anyway
128  CHECK_CLOSE_REL(q.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
129 
130  BOOST_CHECK(q == Acts::AnyCharge(0_e));
131  BOOST_CHECK(Acts::AnyCharge(0_e) == q);
132  BOOST_CHECK(!(q == Acts::AnyCharge(1_e)));
133  BOOST_CHECK(!(Acts::AnyCharge(1_e) == q));
134  BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
135  BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
136 }
137 
138 BOOST_AUTO_TEST_CASE(AnyChargeSingle) {
139  Acts::AnyCharge q(1_e);
140 
141  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
142  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
143  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
144  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
145  CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
146  CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
147  CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
148 
149  BOOST_CHECK(!(q == Acts::AnyCharge(0_e)));
150  BOOST_CHECK(!(Acts::AnyCharge(0_e) == q));
151  BOOST_CHECK(q == Acts::AnyCharge(1_e));
152  BOOST_CHECK(Acts::AnyCharge(1_e) == q);
153  BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
154  BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
155 }
156 
157 BOOST_AUTO_TEST_CASE(AnyChargeMultiple) {
158  Acts::AnyCharge q(3_e);
159 
160  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 3_e);
161  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 3_e);
162  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -3_e);
163  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -3_e);
164  CHECK_CLOSE_REL(q.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
165  CHECK_CLOSE_REL(q.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
166  CHECK_CLOSE_REL(q.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
167 
168  BOOST_CHECK(!(q == Acts::AnyCharge(0_e)));
169  BOOST_CHECK(!(Acts::AnyCharge(0_e) == q));
170  BOOST_CHECK(!(q == Acts::AnyCharge(1_e)));
171  BOOST_CHECK(!(Acts::AnyCharge(1_e) == q));
172  BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
173  BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
174  BOOST_CHECK(q == Acts::AnyCharge(3_e));
175  BOOST_CHECK(Acts::AnyCharge(3_e) == q);
176 }
177 
178 BOOST_AUTO_TEST_SUITE_END()