EIC 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 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 #include "Acts/Utilities/Units.hpp"
14 
15 #include <limits>
16 #include <type_traits>
17 
18 using namespace Acts::UnitLiterals;
19 
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::AnyCharge)
25 
26 BOOST_AUTO_TEST_SUITE(EventDataCharge)
27 
28 BOOST_AUTO_TEST_CASE(Constructibility) {
29  BOOST_CHECK(std::is_trivially_default_constructible_v<Acts::Neutral>);
30  BOOST_CHECK(std::is_trivially_default_constructible_v<Acts::SinglyCharged>);
31  BOOST_CHECK(std::is_nothrow_default_constructible_v<Acts::Neutral>);
32  BOOST_CHECK(std::is_nothrow_default_constructible_v<Acts::SinglyCharged>);
33  BOOST_CHECK(std::is_trivially_constructible_v<Acts::Neutral>);
34  BOOST_CHECK(std::is_trivially_constructible_v<Acts::SinglyCharged>);
35  // BOOST_CHECK(std::is_trivially_constructible_v<Acts::AnyCharge>);
36  BOOST_CHECK(std::is_nothrow_constructible_v<Acts::Neutral>);
37  BOOST_CHECK(std::is_nothrow_constructible_v<Acts::SinglyCharged>);
38  // BOOST_CHECK(std::is_nothrow_constructible_v<Acts::AnyCharge>);
39 }
40 
42  Acts::Neutral q;
43 
44  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
45  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
46  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
47  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
48  CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
49  CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
50  // negative inputs should not occur for neutral particles
51  // ensure that result is positive even in this invalid cases
52  CHECK_CLOSE_REL(q.extractMomentum(-1 / 128_MeV), 128_MeV, eps);
53 
54  BOOST_CHECK_EQUAL(q, Acts::Neutral());
55  BOOST_CHECK_EQUAL(Acts::Neutral(), q);
56  BOOST_CHECK_EQUAL(q, Acts::Neutral(0_e));
57  BOOST_CHECK_EQUAL(Acts::Neutral(0_e), q);
58 }
59 
60 BOOST_AUTO_TEST_CASE(SinglyCharged) {
62 
63  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
64  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
65  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
66  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
67  CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
68  CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
69  CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
70 
71  BOOST_CHECK_EQUAL(q, Acts::SinglyCharged());
72  BOOST_CHECK_EQUAL(Acts::SinglyCharged(), q);
73  BOOST_CHECK_EQUAL(q, Acts::SinglyCharged(1_e));
74  BOOST_CHECK_EQUAL(Acts::SinglyCharged(1_e), q);
75 }
76 
77 BOOST_AUTO_TEST_CASE(AnyChargeNeutral) {
78  Acts::AnyCharge q(0_e);
79 
80  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
81  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
82  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
83  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
84  CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
85  CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
86  // negative inputs should not occur for neutral particles
87  // ensure that result is positive even in this invalid cases
88  CHECK_CLOSE_REL(q.extractMomentum(-1 / 128_MeV), 128_MeV, eps);
89 
90  BOOST_CHECK(q == Acts::AnyCharge(0_e));
91  BOOST_CHECK(Acts::AnyCharge(0_e) == q);
92  BOOST_CHECK(!(q == Acts::AnyCharge(1_e)));
93  BOOST_CHECK(!(Acts::AnyCharge(1_e) == q));
94  BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
95  BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
96 }
97 
98 BOOST_AUTO_TEST_CASE(AnyChargeSingle) {
99  // takes only the charge magnitude as input
100  Acts::AnyCharge q(1_e);
101 
102  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
103  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
104  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
105  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
106  CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
107  CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
108  CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
109 
110  BOOST_CHECK(!(q == Acts::AnyCharge(0_e)));
111  BOOST_CHECK(!(Acts::AnyCharge(0_e) == q));
112  BOOST_CHECK(q == Acts::AnyCharge(1_e));
113  BOOST_CHECK(Acts::AnyCharge(1_e) == q);
114  BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
115  BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
116 }
117 
118 BOOST_AUTO_TEST_CASE(AnyChargeMultiple) {
119  // takes only the charge magnitude as input
120  Acts::AnyCharge q(3_e);
121 
122  BOOST_CHECK_EQUAL(q.extractCharge(1.23), 3_e);
123  BOOST_CHECK_EQUAL(q.extractCharge(2.54), 3_e);
124  BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -3_e);
125  BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -3_e);
126  CHECK_CLOSE_REL(q.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
127  CHECK_CLOSE_REL(q.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
128  CHECK_CLOSE_REL(q.extractMomentum(-3_e / 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  BOOST_CHECK(q == Acts::AnyCharge(3_e));
137  BOOST_CHECK(Acts::AnyCharge(3_e) == q);
138 }
139 
140 BOOST_AUTO_TEST_SUITE_END()