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