EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HitTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HitTests.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 
14 #include <limits>
15 
16 using namespace ActsFatras;
17 
18 namespace {
20 const auto pid = Barcode().setVertexPrimary(12).setParticle(23);
21 const auto gid =
23 } // namespace
24 
25 BOOST_AUTO_TEST_SUITE(FatrasHit)
26 
27 BOOST_AUTO_TEST_CASE(WithoutInteraction) {
28  // some hit position
29  auto p4 = Hit::Vector4(1, 2, 3, 4);
30  // before/after four-momenta are the same
31  auto m4 = Hit::Vector4(1, 1, 1, 4);
32  auto h = Hit(gid, pid, p4, m4, m4, 12u);
33 
34  BOOST_CHECK_EQUAL(h.geometryId(), gid);
35  BOOST_CHECK_EQUAL(h.particleId(), pid);
36  BOOST_CHECK_EQUAL(h.index(), 12u);
37  CHECK_CLOSE_REL(h.position4(), p4, eps);
38  CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
39  CHECK_CLOSE_REL(h.time(), 4, eps);
40  CHECK_CLOSE_REL(h.momentum4Before(), m4, eps);
41  CHECK_CLOSE_REL(h.momentum4After(), m4, eps);
42  CHECK_CLOSE_REL(h.unitDirectionBefore(), Hit::Vector3(1, 1, 1).normalized(),
43  eps);
44  CHECK_CLOSE_REL(h.unitDirectionAfter(), Hit::Vector3(1, 1, 1).normalized(),
45  eps);
46  CHECK_CLOSE_REL(h.unitDirection(), Hit::Vector3(1, 1, 1).normalized(), eps);
47  CHECK_SMALL(h.depositedEnergy(), eps);
48 }
49 
50 BOOST_AUTO_TEST_CASE(WithEnergyLoss) {
51  // some hit position
52  auto p4 = Hit::Vector4(1, 2, 3, 4);
53  // before/after four-momenta differ by energy loss, use zero mass to simplify
54  auto m40 = Hit::Vector4(2, 0, 0, 2);
55  auto m41 = Hit::Vector4(1.5, 0, 0, 1.5);
56  auto h = Hit(gid, pid, p4, m40, m41, 13u);
57 
58  BOOST_CHECK_EQUAL(h.geometryId(), gid);
59  BOOST_CHECK_EQUAL(h.particleId(), pid);
60  BOOST_CHECK_EQUAL(h.index(), 13u);
61  CHECK_CLOSE_REL(h.position4(), p4, eps);
62  CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
63  CHECK_CLOSE_REL(h.time(), 4, eps);
64  CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
65  CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
66  CHECK_CLOSE_OR_SMALL(h.unitDirectionBefore(), Hit::Vector3(1, 0, 0), eps,
67  eps);
68  CHECK_CLOSE_OR_SMALL(h.unitDirectionAfter(), Hit::Vector3(1, 0, 0), eps, eps);
69  CHECK_CLOSE_OR_SMALL(h.unitDirection(), Hit::Vector3(1, 0, 0), eps, eps);
70  CHECK_CLOSE_REL(h.depositedEnergy(), 0.5, eps);
71 }
72 
73 BOOST_AUTO_TEST_CASE(WithScattering) {
74  // some hit position
75  auto p4 = Hit::Vector4(1, 2, 3, 4);
76  // before/after four-momenta differ only by direction
77  auto m40 = Hit::Vector4(2, 0, 2, 5);
78  auto m41 = Hit::Vector4(0, -2, 2, 5);
79  auto h = Hit(gid, pid, p4, m40, m41, 42u);
80 
81  BOOST_CHECK_EQUAL(h.geometryId(), gid);
82  BOOST_CHECK_EQUAL(h.particleId(), pid);
83  BOOST_CHECK_EQUAL(h.index(), 42u);
84  CHECK_CLOSE_REL(h.position4(), p4, eps);
85  CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
86  CHECK_CLOSE_REL(h.time(), 4, eps);
87  CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
88  CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
89  CHECK_CLOSE_OR_SMALL(h.unitDirectionBefore(),
90  Hit::Vector3(1, 0, 1).normalized(), eps, eps);
91  CHECK_CLOSE_OR_SMALL(h.unitDirectionAfter(),
92  Hit::Vector3(0, -1, 1).normalized(), eps, eps);
93  CHECK_CLOSE_REL(h.unitDirection(), Hit::Vector3(1, -1, 2).normalized(), eps);
94  CHECK_SMALL(h.depositedEnergy(), eps);
95 }
96 
97 BOOST_AUTO_TEST_CASE(WithEverything) {
98  // some hit position
99  auto p4 = Hit::Vector4(1, 2, 3, 4);
100  // before/after four-momenta differ by direction and norm
101  auto m40 = Hit::Vector4(3, 2, 2, 5);
102  auto m41 = Hit::Vector4(2, 1, 2, 4);
103  auto h = Hit(gid, pid, p4, m40, m41, 1u);
104 
105  BOOST_CHECK_EQUAL(h.geometryId(), gid);
106  BOOST_CHECK_EQUAL(h.particleId(), pid);
107  BOOST_CHECK_EQUAL(h.index(), 1u);
108  CHECK_CLOSE_REL(h.position4(), p4, eps);
109  CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
110  CHECK_CLOSE_REL(h.time(), 4, eps);
111  CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
112  CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
113  CHECK_CLOSE_REL(h.unitDirectionBefore(), Hit::Vector3(3, 2, 2).normalized(),
114  eps);
115  CHECK_CLOSE_REL(h.unitDirectionAfter(), Hit::Vector3(2, 1, 2).normalized(),
116  eps);
118  h.unitDirection(),
119  Hit::Vector3(0.7023994590205035, 0.41229136135810396, 0.5802161953247991),
120  eps);
121  CHECK_CLOSE_REL(h.depositedEnergy(), 1, eps);
122 }
123 
124 BOOST_AUTO_TEST_SUITE_END()