Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:05

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