Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:39

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0013 #include "ActsFatras/EventData/Barcode.hpp"
0014 #include "ActsFatras/EventData/Hit.hpp"
0015 
0016 #include <limits>
0017 
0018 using namespace ActsFatras;
0019 
0020 namespace {
0021 constexpr auto eps = std::numeric_limits<Hit::Scalar>::epsilon();
0022 const auto pid = Barcode().setVertexPrimary(12).setParticle(23);
0023 const auto gid =
0024     Acts::GeometryIdentifier().setVolume(1).setLayer(2).setSensitive(3);
0025 }  // namespace
0026 
0027 BOOST_AUTO_TEST_SUITE(FatrasHit)
0028 
0029 BOOST_AUTO_TEST_CASE(WithoutInteraction) {
0030   // some hit position
0031   auto p4 = Hit::Vector4(1, 2, 3, 4);
0032   // before/after four-momenta are the same
0033   auto m4 = Hit::Vector4(1, 1, 1, 4);
0034   auto h = Hit(gid, pid, p4, m4, m4, 12u);
0035 
0036   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0037   BOOST_CHECK_EQUAL(h.particleId(), pid);
0038   BOOST_CHECK_EQUAL(h.index(), 12u);
0039   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0040   CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
0041   CHECK_CLOSE_REL(h.time(), 4, eps);
0042   CHECK_CLOSE_REL(h.momentum4Before(), m4, eps);
0043   CHECK_CLOSE_REL(h.momentum4After(), m4, eps);
0044   CHECK_CLOSE_REL(h.directionBefore(), Hit::Vector3(1, 1, 1).normalized(), eps);
0045   CHECK_CLOSE_REL(h.directionAfter(), Hit::Vector3(1, 1, 1).normalized(), eps);
0046   CHECK_CLOSE_REL(h.direction(), Hit::Vector3(1, 1, 1).normalized(), eps);
0047   CHECK_SMALL(h.depositedEnergy(), eps);
0048 }
0049 
0050 BOOST_AUTO_TEST_CASE(WithEnergyLoss) {
0051   // some hit position
0052   auto p4 = Hit::Vector4(1, 2, 3, 4);
0053   // before/after four-momenta differ by energy loss, use zero mass to simplify
0054   auto m40 = Hit::Vector4(2, 0, 0, 2);
0055   auto m41 = Hit::Vector4(1.5, 0, 0, 1.5);
0056   auto h = Hit(gid, pid, p4, m40, m41, 13u);
0057 
0058   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0059   BOOST_CHECK_EQUAL(h.particleId(), pid);
0060   BOOST_CHECK_EQUAL(h.index(), 13u);
0061   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0062   CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
0063   CHECK_CLOSE_REL(h.time(), 4, eps);
0064   CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
0065   CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
0066   CHECK_CLOSE_OR_SMALL(h.directionBefore(), Hit::Vector3(1, 0, 0), eps, eps);
0067   CHECK_CLOSE_OR_SMALL(h.directionAfter(), Hit::Vector3(1, 0, 0), eps, eps);
0068   CHECK_CLOSE_OR_SMALL(h.direction(), Hit::Vector3(1, 0, 0), eps, eps);
0069   CHECK_CLOSE_REL(h.depositedEnergy(), 0.5, eps);
0070 }
0071 
0072 BOOST_AUTO_TEST_CASE(WithScattering) {
0073   // some hit position
0074   auto p4 = Hit::Vector4(1, 2, 3, 4);
0075   // before/after four-momenta differ only by direction
0076   auto m40 = Hit::Vector4(2, 0, 2, 5);
0077   auto m41 = Hit::Vector4(0, -2, 2, 5);
0078   auto h = Hit(gid, pid, p4, m40, m41, 42u);
0079 
0080   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0081   BOOST_CHECK_EQUAL(h.particleId(), pid);
0082   BOOST_CHECK_EQUAL(h.index(), 42u);
0083   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0084   CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
0085   CHECK_CLOSE_REL(h.time(), 4, eps);
0086   CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
0087   CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
0088   CHECK_CLOSE_OR_SMALL(h.directionBefore(), Hit::Vector3(1, 0, 1).normalized(),
0089                        eps, eps);
0090   CHECK_CLOSE_OR_SMALL(h.directionAfter(), Hit::Vector3(0, -1, 1).normalized(),
0091                        eps, eps);
0092   CHECK_CLOSE_REL(h.direction(), Hit::Vector3(1, -1, 2).normalized(), eps);
0093   CHECK_SMALL(h.depositedEnergy(), eps);
0094 }
0095 
0096 BOOST_AUTO_TEST_CASE(WithEverything) {
0097   // some hit position
0098   auto p4 = Hit::Vector4(1, 2, 3, 4);
0099   // before/after four-momenta differ by direction and norm
0100   auto m40 = Hit::Vector4(3, 2, 2, 5);
0101   auto m41 = Hit::Vector4(2, 1, 2, 4);
0102   auto h = Hit(gid, pid, p4, m40, m41, 1u);
0103 
0104   BOOST_CHECK_EQUAL(h.geometryId(), gid);
0105   BOOST_CHECK_EQUAL(h.particleId(), pid);
0106   BOOST_CHECK_EQUAL(h.index(), 1u);
0107   CHECK_CLOSE_REL(h.fourPosition(), p4, eps);
0108   CHECK_CLOSE_REL(h.position(), Hit::Vector3(1, 2, 3), eps);
0109   CHECK_CLOSE_REL(h.time(), 4, eps);
0110   CHECK_CLOSE_OR_SMALL(h.momentum4Before(), m40, eps, eps);
0111   CHECK_CLOSE_OR_SMALL(h.momentum4After(), m41, eps, eps);
0112   CHECK_CLOSE_REL(h.directionBefore(), Hit::Vector3(3, 2, 2).normalized(), eps);
0113   CHECK_CLOSE_REL(h.directionAfter(), Hit::Vector3(2, 1, 2).normalized(), eps);
0114   CHECK_CLOSE_REL(
0115       h.direction(),
0116       Hit::Vector3(0.7023994590205035, 0.41229136135810396, 0.5802161953247991),
0117       eps);
0118   CHECK_CLOSE_REL(h.depositedEnergy(), 1, eps);
0119 }
0120 
0121 BOOST_AUTO_TEST_SUITE_END()