File indexing completed on 2025-01-18 09:12:34
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/EventData/Charge.hpp"
0013 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0014
0015 #include <limits>
0016 #include <type_traits>
0017
0018 using namespace Acts::UnitLiterals;
0019
0020 static auto eps = std::numeric_limits<double>::epsilon();
0021
0022 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::Neutral)
0023 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::SinglyCharged)
0024 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::NonNeutralCharge)
0025 BOOST_TEST_DONT_PRINT_LOG_VALUE(Acts::AnyCharge)
0026
0027 BOOST_AUTO_TEST_SUITE(EventDataCharge)
0028
0029 BOOST_AUTO_TEST_CASE(Constructibility) {
0030 BOOST_CHECK(std::is_trivially_default_constructible_v<Acts::Neutral>);
0031 BOOST_CHECK(std::is_trivially_default_constructible_v<Acts::SinglyCharged>);
0032 BOOST_CHECK(std::is_nothrow_default_constructible_v<Acts::Neutral>);
0033 BOOST_CHECK(std::is_nothrow_default_constructible_v<Acts::SinglyCharged>);
0034 BOOST_CHECK(std::is_trivially_constructible_v<Acts::Neutral>);
0035 BOOST_CHECK(std::is_trivially_constructible_v<Acts::SinglyCharged>);
0036
0037
0038 BOOST_CHECK(std::is_nothrow_constructible_v<Acts::Neutral>);
0039 BOOST_CHECK(std::is_nothrow_constructible_v<Acts::SinglyCharged>);
0040
0041
0042 }
0043
0044 BOOST_AUTO_TEST_CASE(Neutral) {
0045 Acts::Neutral q;
0046
0047 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
0048 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
0049 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
0050 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
0051 CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
0052 CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
0053
0054
0055
0056
0057
0058
0059 BOOST_CHECK_EQUAL(q, Acts::Neutral());
0060 BOOST_CHECK_EQUAL(Acts::Neutral(), q);
0061 BOOST_CHECK_EQUAL(q, Acts::Neutral(0_e));
0062 BOOST_CHECK_EQUAL(Acts::Neutral(0_e), q);
0063 }
0064
0065 BOOST_AUTO_TEST_CASE(SinglyCharged) {
0066 Acts::SinglyCharged q;
0067
0068 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
0069 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
0070 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
0071 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
0072 CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0073 CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0074 CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0075
0076 BOOST_CHECK_EQUAL(q, Acts::SinglyCharged());
0077 BOOST_CHECK_EQUAL(Acts::SinglyCharged(), q);
0078 BOOST_CHECK_EQUAL(q, Acts::SinglyCharged(1_e));
0079 BOOST_CHECK_EQUAL(Acts::SinglyCharged(1_e), q);
0080 }
0081
0082 BOOST_AUTO_TEST_CASE(NonNeutralChargeSingle) {
0083 Acts::NonNeutralCharge q(1_e);
0084
0085 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
0086 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
0087 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
0088 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
0089 CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0090 CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0091 CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0092
0093 BOOST_CHECK_EQUAL(q, Acts::NonNeutralCharge(1_e));
0094 BOOST_CHECK_EQUAL(Acts::NonNeutralCharge(1_e), q);
0095 }
0096
0097 BOOST_AUTO_TEST_CASE(NonNeutralChargeMultiple) {
0098 Acts::NonNeutralCharge q(3_e);
0099
0100 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 3_e);
0101 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 3_e);
0102 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -3_e);
0103 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -3_e);
0104 CHECK_CLOSE_REL(q.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
0105 CHECK_CLOSE_REL(q.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
0106 CHECK_CLOSE_REL(q.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
0107
0108 BOOST_CHECK(!(q == Acts::NonNeutralCharge(1_e)));
0109 BOOST_CHECK(!(Acts::NonNeutralCharge(1_e) == q));
0110 BOOST_CHECK(!(q == Acts::NonNeutralCharge(2_e)));
0111 BOOST_CHECK(!(Acts::NonNeutralCharge(2_e) == q));
0112 BOOST_CHECK(q == Acts::NonNeutralCharge(3_e));
0113 BOOST_CHECK(Acts::NonNeutralCharge(3_e) == q);
0114 }
0115
0116 BOOST_AUTO_TEST_CASE(AnyChargeNeutral) {
0117 Acts::AnyCharge q(0_e);
0118
0119 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
0120 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
0121 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
0122 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
0123 CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
0124 CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
0125
0126
0127
0128 CHECK_CLOSE_REL(q.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
0129
0130 BOOST_CHECK(q == Acts::AnyCharge(0_e));
0131 BOOST_CHECK(Acts::AnyCharge(0_e) == q);
0132 BOOST_CHECK(!(q == Acts::AnyCharge(1_e)));
0133 BOOST_CHECK(!(Acts::AnyCharge(1_e) == q));
0134 BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
0135 BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
0136 }
0137
0138 BOOST_AUTO_TEST_CASE(AnyChargeSingle) {
0139 Acts::AnyCharge q(1_e);
0140
0141 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
0142 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
0143 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
0144 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
0145 CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0146 CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0147 CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0148
0149 BOOST_CHECK(!(q == Acts::AnyCharge(0_e)));
0150 BOOST_CHECK(!(Acts::AnyCharge(0_e) == q));
0151 BOOST_CHECK(q == Acts::AnyCharge(1_e));
0152 BOOST_CHECK(Acts::AnyCharge(1_e) == q);
0153 BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
0154 BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
0155 }
0156
0157 BOOST_AUTO_TEST_CASE(AnyChargeMultiple) {
0158 Acts::AnyCharge q(3_e);
0159
0160 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 3_e);
0161 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 3_e);
0162 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -3_e);
0163 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -3_e);
0164 CHECK_CLOSE_REL(q.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
0165 CHECK_CLOSE_REL(q.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
0166 CHECK_CLOSE_REL(q.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
0167
0168 BOOST_CHECK(!(q == Acts::AnyCharge(0_e)));
0169 BOOST_CHECK(!(Acts::AnyCharge(0_e) == q));
0170 BOOST_CHECK(!(q == Acts::AnyCharge(1_e)));
0171 BOOST_CHECK(!(Acts::AnyCharge(1_e) == q));
0172 BOOST_CHECK(!(q == Acts::AnyCharge(2_e)));
0173 BOOST_CHECK(!(Acts::AnyCharge(2_e) == q));
0174 BOOST_CHECK(q == Acts::AnyCharge(3_e));
0175 BOOST_CHECK(Acts::AnyCharge(3_e) == q);
0176 }
0177
0178 BOOST_AUTO_TEST_SUITE_END()