Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:46

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/Definitions/PdgParticle.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "ActsFatras/EventData/Barcode.hpp"
0014 #include "ActsFatras/EventData/Particle.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <cmath>
0018 #include <limits>
0019 
0020 using Acts::PdgParticle;
0021 using ActsFatras::Barcode;
0022 using ActsFatras::Particle;
0023 
0024 using namespace Acts;
0025 using namespace Acts::UnitLiterals;
0026 using namespace ActsFatras;
0027 
0028 namespace {
0029 constexpr auto eps = std::numeric_limits<double>::epsilon();
0030 }
0031 
0032 namespace ActsTests {
0033 
0034 BOOST_AUTO_TEST_SUITE(EventDataSuite)
0035 
0036 BOOST_AUTO_TEST_CASE(Construct) {
0037   const auto pid = Barcode().withVertexPrimary(1).withParticle(42);
0038   const auto particle = Particle(pid, PdgParticle::eProton, 1_e, 1_GeV);
0039 
0040   BOOST_CHECK_EQUAL(particle.particleId(), pid);
0041   BOOST_CHECK_EQUAL(particle.pdg(), PdgParticle::eProton);
0042   // particle is at rest at the origin
0043   BOOST_CHECK_EQUAL(particle.fourPosition(), Vector4::Zero());
0044   BOOST_CHECK_EQUAL(particle.position(), Vector3::Zero());
0045   BOOST_CHECK_EQUAL(particle.time(), 0.);
0046   BOOST_CHECK_EQUAL(particle.fourPosition().x(), particle.position().x());
0047   BOOST_CHECK_EQUAL(particle.fourPosition().y(), particle.position().y());
0048   BOOST_CHECK_EQUAL(particle.fourPosition().z(), particle.position().z());
0049   BOOST_CHECK_EQUAL(particle.fourPosition().w(), particle.time());
0050   // particle direction is undefined, but must be normalized
0051   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0052   BOOST_CHECK_EQUAL(particle.transverseMomentum(), 0.);
0053   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 0.);
0054   // particle is created at rest and thus not alive
0055   BOOST_CHECK(!particle.isAlive());
0056 }
0057 
0058 BOOST_AUTO_TEST_CASE(CorrectEnergy) {
0059   const auto pid = Barcode().withVertexPrimary(1).withParticle(42);
0060   auto particle = Particle(pid, PdgParticle::eProton, 1_e, 1_GeV)
0061                       .setDirection(Vector3::UnitX())
0062                       .setAbsoluteMomentum(2_GeV);
0063 
0064   BOOST_CHECK_EQUAL(particle.mass(), 1_GeV);
0065   // check that the particle has some input energy
0066   BOOST_CHECK_EQUAL(particle.fourMomentum().x(), 2_GeV);
0067   BOOST_CHECK_EQUAL(particle.fourMomentum().y(), 0_GeV);
0068   BOOST_CHECK_EQUAL(particle.fourMomentum().z(), 0_GeV);
0069   BOOST_CHECK_EQUAL(particle.fourMomentum().w(), std::hypot(1_GeV, 2_GeV));
0070   BOOST_CHECK_EQUAL(particle.transverseMomentum(), 2_GeV);
0071   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 2_GeV);
0072   BOOST_CHECK_EQUAL(particle.energy(), std::hypot(1_GeV, 2_GeV));
0073   // particle direction must be normalized
0074   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0075 
0076   // lose some energy
0077   particle.correctEnergy(-100_MeV);
0078   BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
0079   BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
0080   BOOST_CHECK_EQUAL(particle.energy(), std::hypot(1_GeV, 2_GeV) - 100_MeV);
0081   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0082   // particle is still alive
0083   BOOST_CHECK(particle.isAlive());
0084 
0085   // lose some more energy
0086   particle.correctEnergy(-200_MeV);
0087   BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
0088   BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
0089   BOOST_CHECK_EQUAL(particle.energy(), std::hypot(1_GeV, 2_GeV) - 300_MeV);
0090   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0091   // particle is still alive
0092   BOOST_CHECK(particle.isAlive());
0093 
0094   // lose a lot of energy
0095   particle.correctEnergy(-3_GeV);
0096   BOOST_CHECK_EQUAL(particle.transverseMomentum(), 0.);
0097   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 0.);
0098   BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
0099   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0100   // particle is not alive anymore
0101   BOOST_CHECK(!particle.isAlive());
0102 
0103   // losing even more energy does nothing
0104   particle.correctEnergy(-10_GeV);
0105   BOOST_CHECK_EQUAL(particle.transverseMomentum(), 0.);
0106   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 0.);
0107   BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
0108   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0109   // particle is still not alive
0110   BOOST_CHECK(!particle.isAlive());
0111 }
0112 
0113 BOOST_AUTO_TEST_SUITE_END()
0114 
0115 }  // namespace ActsTests