Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-07 07:47:21

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