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) 2018-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/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<Particle::Scalar>::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(), Particle::Vector4::Zero());
0039   BOOST_CHECK_EQUAL(particle.position(), Particle::Vector3::Zero());
0040   BOOST_CHECK_EQUAL(particle.time(), Particle::Scalar(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(), Particle::Scalar(0));
0048   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), Particle::Scalar(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(Particle::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   // loose 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(),
0076                     Particle::Scalar(std::hypot(1_GeV, 2_GeV) - 100_MeV));
0077   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0078   // particle is still alive
0079   BOOST_CHECK(particle.isAlive());
0080 
0081   // loose some more energy
0082   particle.correctEnergy(-200_MeV);
0083   BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
0084   BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
0085   BOOST_CHECK_EQUAL(particle.energy(),
0086                     Particle::Scalar(std::hypot(1_GeV, 2_GeV) - 300_MeV));
0087   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0088   // particle is still alive
0089   BOOST_CHECK(particle.isAlive());
0090 
0091   // loose a lot of energy
0092   particle.correctEnergy(-3_GeV);
0093   BOOST_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
0094   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), Particle::Scalar(0));
0095   BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
0096   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0097   // particle is not alive anymore
0098   BOOST_CHECK(!particle.isAlive());
0099 
0100   // lossing even more energy does nothing
0101   particle.correctEnergy(-10_GeV);
0102   BOOST_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
0103   BOOST_CHECK_EQUAL(particle.absoluteMomentum(), Particle::Scalar(0));
0104   BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
0105   CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
0106   // particle is still not alive
0107   BOOST_CHECK(!particle.isAlive());
0108 }
0109 
0110 BOOST_AUTO_TEST_SUITE_END()