Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleHypothesisTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleHypothesisTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
15 
16 #include <limits>
17 #include <type_traits>
18 
19 using namespace Acts::UnitLiterals;
20 
21 static auto eps = std::numeric_limits<double>::epsilon();
22 
23 BOOST_AUTO_TEST_SUITE(EventDataParticleHypothesis)
24 
26  auto p = Acts::NeutralParticleHypothesis::pion0();
27 
28  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 0_e);
29  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 0_e);
30  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), 0_e);
31  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), 0_e);
32  CHECK_CLOSE_REL(p.extractMomentum(1 / 64_GeV), 64_GeV, eps);
33  CHECK_CLOSE_REL(p.extractMomentum(1 / 128_MeV), 128_MeV, eps);
34 }
35 
36 BOOST_AUTO_TEST_CASE(SinglyCharged) {
38 
39  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
40  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
41  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
42  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
43  CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
44  CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
45  CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
46 }
47 
48 BOOST_AUTO_TEST_CASE(NonNeutralChargeSingle) {
50 
51  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
52  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
53  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
54  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
55  CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
56  CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
57  CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
58 }
59 
60 BOOST_AUTO_TEST_CASE(NonNeutralChargeMultiple) {
62 
63  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 3_e);
64  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 3_e);
65  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -3_e);
66  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -3_e);
67  CHECK_CLOSE_REL(p.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
68  CHECK_CLOSE_REL(p.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
69  CHECK_CLOSE_REL(p.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
70 }
71 
72 BOOST_AUTO_TEST_CASE(AnyChargeNeutral) {
74 
75  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 0_e);
76  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 0_e);
77  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), 0_e);
78  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), 0_e);
79  CHECK_CLOSE_REL(p.extractMomentum(1 / 64_GeV), 64_GeV, eps);
80  CHECK_CLOSE_REL(p.extractMomentum(1 / 128_MeV), 128_MeV, eps);
81 
82  // negative inputs should not occur for neutral particles
83  // the result is not defined, but we check it anyway
84  CHECK_CLOSE_REL(p.extractMomentum(-1 / 128_MeV), -128_MeV, eps);
85 }
86 
87 BOOST_AUTO_TEST_CASE(AnyChargeSingle) {
89 
90  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 1_e);
91  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 1_e);
92  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -1_e);
93  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -1_e);
94  CHECK_CLOSE_REL(p.extractMomentum(1_e / 64_GeV), 64_GeV, eps);
95  CHECK_CLOSE_REL(p.extractMomentum(1_e / 128_MeV), 128_MeV, eps);
96  CHECK_CLOSE_REL(p.extractMomentum(-1_e / 128_MeV), 128_MeV, eps);
97 }
98 
99 BOOST_AUTO_TEST_CASE(AnyChargeMultiple) {
101 
102  BOOST_CHECK_EQUAL(p.extractCharge(1.23), 3_e);
103  BOOST_CHECK_EQUAL(p.extractCharge(2.54), 3_e);
104  BOOST_CHECK_EQUAL(p.extractCharge(-1.98), -3_e);
105  BOOST_CHECK_EQUAL(p.extractCharge(-2.23), -3_e);
106  CHECK_CLOSE_REL(p.extractMomentum(3_e / 64_GeV), 64_GeV, eps);
107  CHECK_CLOSE_REL(p.extractMomentum(3_e / 128_MeV), 128_MeV, eps);
108  CHECK_CLOSE_REL(p.extractMomentum(-3_e / 128_MeV), 128_MeV, eps);
109 }
110 
111 BOOST_AUTO_TEST_SUITE_END()