Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-01 07:55:22

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "ActsFatras/EventData/Barcode.hpp"
0013 #include "ActsFatras/EventData/Hit.hpp"
0014 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0015 
0016 #include <limits>
0017 
0018 using namespace Acts;
0019 using namespace ActsFatras;
0020 
0021 namespace {
0022 constexpr auto eps = std::numeric_limits<double>::epsilon();
0023 const auto pid = Barcode().withVertexPrimary(12).withParticle(23);
0024 const auto gid =
0025     GeometryIdentifier().withVolume(1).withLayer(2).withSensitive(3);
0026 }  // namespace
0027 
0028 namespace ActsTests {
0029 
0030 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0031 
0032 BOOST_AUTO_TEST_CASE(WithoutInteraction) {
0033   // some hit position
0034   auto p4 = Vector4(1, 2, 3, 4);
0035   // before/after four-momenta are the same
0036   auto m4 = Vector4(1, 1, 1, 4);
0037   auto h = Hit(gid, pid, p4, m4, m4, 12u);
0038 
0039   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0040   BOOST_CHECK_EQUAL(h.particleId(), pid);
0041   BOOST_CHECK_EQUAL(h.index(), 12u);
0042   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0043   CHECK_CLOSE_REL(h.position(), Vector3(1, 2, 3), eps);
0044   CHECK_CLOSE_REL(h.time(), 4, eps);
0045   CHECK_CLOSE_REL(h.momentum4Before(), m4, eps);
0046   CHECK_CLOSE_REL(h.momentum4After(), m4, eps);
0047   CHECK_CLOSE_REL(h.directionBefore(), Vector3(1, 1, 1).normalized(), eps);
0048   CHECK_CLOSE_REL(h.directionAfter(), Vector3(1, 1, 1).normalized(), eps);
0049   CHECK_CLOSE_REL(h.direction(), Vector3(1, 1, 1).normalized(), eps);
0050   CHECK_SMALL(h.depositedEnergy(), eps);
0051 }
0052 
0053 BOOST_AUTO_TEST_CASE(WithEnergyLoss) {
0054   // some hit position
0055   auto p4 = Vector4(1, 2, 3, 4);
0056   // before/after four-momenta differ by energy loss, use zero mass to simplify
0057   auto m40 = Vector4(2, 0, 0, 2);
0058   auto m41 = Vector4(1.5, 0, 0, 1.5);
0059   auto h = Hit(gid, pid, p4, m40, m41, 13u);
0060 
0061   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0062   BOOST_CHECK_EQUAL(h.particleId(), pid);
0063   BOOST_CHECK_EQUAL(h.index(), 13u);
0064   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0065   CHECK_CLOSE_REL(h.position(), Vector3(1, 2, 3), eps);
0066   CHECK_CLOSE_REL(h.time(), 4, eps);
0067   CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
0068   CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
0069   CHECK_CLOSE_OR_SMALL(h.directionBefore(), Vector3(1, 0, 0), eps, eps);
0070   CHECK_CLOSE_OR_SMALL(h.directionAfter(), Vector3(1, 0, 0), eps, eps);
0071   CHECK_CLOSE_OR_SMALL(h.direction(), Vector3(1, 0, 0), eps, eps);
0072   CHECK_CLOSE_REL(h.depositedEnergy(), 0.5, eps);
0073 }
0074 
0075 BOOST_AUTO_TEST_CASE(WithScattering) {
0076   // some hit position
0077   auto p4 = Vector4(1, 2, 3, 4);
0078   // before/after four-momenta differ only by direction
0079   auto m40 = Vector4(2, 0, 2, 5);
0080   auto m41 = Vector4(0, -2, 2, 5);
0081   auto h = Hit(gid, pid, p4, m40, m41, 42u);
0082 
0083   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0084   BOOST_CHECK_EQUAL(h.particleId(), pid);
0085   BOOST_CHECK_EQUAL(h.index(), 42u);
0086   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0087   CHECK_CLOSE_REL(h.position(), Vector3(1, 2, 3), eps);
0088   CHECK_CLOSE_REL(h.time(), 4, eps);
0089   CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
0090   CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
0091   CHECK_CLOSE_OR_SMALL(h.directionBefore(), Vector3(1, 0, 1).normalized(), eps,
0092                        eps);
0093   CHECK_CLOSE_OR_SMALL(h.directionAfter(), Vector3(0, -1, 1).normalized(), eps,
0094                        eps);
0095   CHECK_CLOSE_REL(h.direction(), Vector3(1, -1, 2).normalized(), eps);
0096   CHECK_SMALL(h.depositedEnergy(), eps);
0097 }
0098 
0099 BOOST_AUTO_TEST_CASE(WithEverything) {
0100   // some hit position
0101   auto p4 = Vector4(1, 2, 3, 4);
0102   // before/after four-momenta differ by direction and norm
0103   auto m40 = Vector4(3, 2, 2, 5);
0104   auto m41 = Vector4(2, 1, 2, 4);
0105   auto h = Hit(gid, pid, p4, m40, m41, 1u);
0106 
0107   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0108   BOOST_CHECK_EQUAL(h.particleId(), pid);
0109   BOOST_CHECK_EQUAL(h.index(), 1u);
0110   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0111   CHECK_CLOSE_REL(h.position(), Vector3(1, 2, 3), eps);
0112   CHECK_CLOSE_REL(h.time(), 4, eps);
0113   CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
0114   CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
0115   CHECK_CLOSE_REL(h.directionBefore(), Vector3(3, 2, 2).normalized(), eps);
0116   CHECK_CLOSE_REL(h.directionAfter(), Vector3(2, 1, 2).normalized(), eps);
0117   CHECK_CLOSE_REL(
0118       h.direction(),
0119       Vector3(0.7023994590205035, 0.41229136135810396, 0.5802161953247991),
0120       eps);
0121   CHECK_CLOSE_REL(h.depositedEnergy(), 1, eps);
0122 }
0123 
0124 BOOST_AUTO_TEST_SUITE_END()
0125 
0126 }  // namespace ActsTests