File indexing completed on 2026-05-18 07:49:25
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/ParticleHypothesis.hpp"
0013 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0014
0015 #include <limits>
0016
0017 using namespace Acts;
0018 using namespace Acts::UnitLiterals;
0019
0020 static auto eps = std::numeric_limits<double>::epsilon();
0021
0022 namespace ActsTests {
0023
0024 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0025
0026 BOOST_AUTO_TEST_CASE(ChargeHypothesisNeutral) {
0027 ChargeHypothesis q(0_e);
0028
0029 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 0_e);
0030 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 0_e);
0031 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), 0_e);
0032 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), 0_e);
0033 CHECK_CLOSE_REL(q.extractMomentum(1 / 64_GeV), 64_GeV, eps);
0034 CHECK_CLOSE_REL(q.extractMomentum(1 / 128_MeV), 128_MeV, eps);
0035
0036
0037
0038 CHECK_CLOSE_REL(q.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
0039
0040 BOOST_CHECK(q == ChargeHypothesis(0_e));
0041 BOOST_CHECK(ChargeHypothesis(0_e) == q);
0042 BOOST_CHECK(!(q == ChargeHypothesis(1_e)));
0043 BOOST_CHECK(!(ChargeHypothesis(1_e) == q));
0044 BOOST_CHECK(!(q == ChargeHypothesis(2_e)));
0045 BOOST_CHECK(!(ChargeHypothesis(2_e) == q));
0046 }
0047
0048 BOOST_AUTO_TEST_CASE(ChargeHypothesisSingle) {
0049 ChargeHypothesis q(1_e);
0050
0051 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 1_e);
0052 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 1_e);
0053 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -1_e);
0054 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -1_e);
0055 CHECK_CLOSE_REL(q.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0056 CHECK_CLOSE_REL(q.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0057 CHECK_CLOSE_REL(q.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0058
0059 BOOST_CHECK(!(q == ChargeHypothesis(0_e)));
0060 BOOST_CHECK(!(ChargeHypothesis(0_e) == q));
0061 BOOST_CHECK(q == ChargeHypothesis(1_e));
0062 BOOST_CHECK(ChargeHypothesis(1_e) == q);
0063 BOOST_CHECK(!(q == ChargeHypothesis(2_e)));
0064 BOOST_CHECK(!(ChargeHypothesis(2_e) == q));
0065 }
0066
0067 BOOST_AUTO_TEST_CASE(ChargeHypothesisMultiple) {
0068 ChargeHypothesis q(3_e);
0069
0070 BOOST_CHECK_EQUAL(q.extractCharge(1.23), 3_e);
0071 BOOST_CHECK_EQUAL(q.extractCharge(2.54), 3_e);
0072 BOOST_CHECK_EQUAL(q.extractCharge(-1.98), -3_e);
0073 BOOST_CHECK_EQUAL(q.extractCharge(-2.23), -3_e);
0074 CHECK_CLOSE_REL(q.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
0075 CHECK_CLOSE_REL(q.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
0076 CHECK_CLOSE_REL(q.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
0077
0078 BOOST_CHECK(!(q == ChargeHypothesis(0_e)));
0079 BOOST_CHECK(!(ChargeHypothesis(0_e) == q));
0080 BOOST_CHECK(!(q == ChargeHypothesis(1_e)));
0081 BOOST_CHECK(!(ChargeHypothesis(1_e) == q));
0082 BOOST_CHECK(!(q == ChargeHypothesis(2_e)));
0083 BOOST_CHECK(!(ChargeHypothesis(2_e) == q));
0084 BOOST_CHECK(q == ChargeHypothesis(3_e));
0085 BOOST_CHECK(ChargeHypothesis(3_e) == q);
0086 }
0087
0088 BOOST_AUTO_TEST_CASE(AnyChargeNeutral) {
0089 auto p = ParticleHypothesis::pion0();
0090
0091 BOOST_CHECK_EQUAL(p.extractCharge(1.23), 0_e);
0092 BOOST_CHECK_EQUAL(p.extractCharge(2.54), 0_e);
0093 BOOST_CHECK_EQUAL(p.extractCharge(-1.98), 0_e);
0094 BOOST_CHECK_EQUAL(p.extractCharge(-2.23), 0_e);
0095 CHECK_CLOSE_REL(p.extractMomentum(1 / 64_GeV), 64_GeV, eps);
0096 CHECK_CLOSE_REL(p.extractMomentum(1 / 128_MeV), 128_MeV, eps);
0097
0098
0099
0100 CHECK_CLOSE_REL(p.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
0101 }
0102
0103 BOOST_AUTO_TEST_CASE(AnyChargeSingle) {
0104 auto p = ParticleHypothesis::pion();
0105
0106 BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
0107 BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
0108 BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
0109 BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
0110 CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
0111 CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
0112 CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
0113 }
0114
0115 BOOST_AUTO_TEST_CASE(AnyChargeMultiple) {
0116 auto p = ParticleHypothesis::pionLike(3_e);
0117
0118 BOOST_CHECK_EQUAL(p.extractCharge(1.23), 3_e);
0119 BOOST_CHECK_EQUAL(p.extractCharge(2.54), 3_e);
0120 BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -3_e);
0121 BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -3_e);
0122 CHECK_CLOSE_REL(p.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
0123 CHECK_CLOSE_REL(p.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
0124 CHECK_CLOSE_REL(p.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
0125 }
0126
0127 BOOST_AUTO_TEST_SUITE_END()
0128
0129 }