Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
16 
17 #include <cmath>
18 #include <limits>
19 
20 using Acts::PdgParticle;
23 using namespace Acts::UnitLiterals;
24 
25 namespace {
26 constexpr auto eps = std::numeric_limits<Particle::Scalar>::epsilon();
27 }
28 
29 BOOST_AUTO_TEST_SUITE(FatrasParticle)
30 
32  const auto pid = Barcode().setVertexPrimary(1).setParticle(42);
33  const auto particle = Particle(pid, PdgParticle::eProton, 1_e, 1_GeV);
34 
35  BOOST_CHECK_EQUAL(particle.particleId(), pid);
36  BOOST_CHECK_EQUAL(particle.pdg(), PdgParticle::eProton);
37  // particle is at rest at the origin
38  BOOST_CHECK_EQUAL(particle.fourPosition(), Particle::Vector4::Zero());
39  BOOST_CHECK_EQUAL(particle.position(), Particle::Vector3::Zero());
40  BOOST_CHECK_EQUAL(particle.time(), Particle::Scalar(0));
41  BOOST_CHECK_EQUAL(particle.fourPosition().x(), particle.position().x());
42  BOOST_CHECK_EQUAL(particle.fourPosition().y(), particle.position().y());
43  BOOST_CHECK_EQUAL(particle.fourPosition().z(), particle.position().z());
44  BOOST_CHECK_EQUAL(particle.fourPosition().w(), particle.time());
45  // particle direction is undefined, but must be normalized
46  CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
47  BOOST_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
48  BOOST_CHECK_EQUAL(particle.absoluteMomentum(), Particle::Scalar(0));
49  // particle is created at rest and thus not alive
50  BOOST_CHECK(not particle.isAlive());
51 }
52 
53 BOOST_AUTO_TEST_CASE(CorrectEnergy) {
54  const auto pid = Barcode().setVertexPrimary(1).setParticle(42);
55  auto particle = Particle(pid, PdgParticle::eProton, 1_e, 1_GeV)
56  .setDirection(Particle::Vector3::UnitX())
57  .setAbsoluteMomentum(2_GeV);
58 
59  BOOST_CHECK_EQUAL(particle.mass(), 1_GeV);
60  // check that the particle has some input energy
61  BOOST_CHECK_EQUAL(particle.fourMomentum().x(), 2_GeV);
62  BOOST_CHECK_EQUAL(particle.fourMomentum().y(), 0_GeV);
63  BOOST_CHECK_EQUAL(particle.fourMomentum().z(), 0_GeV);
64  BOOST_CHECK_EQUAL(particle.fourMomentum().w(), std::hypot(1_GeV, 2_GeV));
65  BOOST_CHECK_EQUAL(particle.transverseMomentum(), 2_GeV);
66  BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 2_GeV);
67  BOOST_CHECK_EQUAL(particle.energy(), std::hypot(1_GeV, 2_GeV));
68  // particle direction must be normalized
69  CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
70 
71  // loose some energy
72  particle.correctEnergy(-100_MeV);
73  BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
74  BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
75  BOOST_CHECK_EQUAL(particle.energy(),
76  Particle::Scalar(std::hypot(1_GeV, 2_GeV) - 100_MeV));
77  CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
78  // particle is still alive
79  BOOST_CHECK(particle.isAlive());
80 
81  // loose some more energy
82  particle.correctEnergy(-200_MeV);
83  BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
84  BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
85  BOOST_CHECK_EQUAL(particle.energy(),
86  Particle::Scalar(std::hypot(1_GeV, 2_GeV) - 300_MeV));
87  CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
88  // particle is still alive
89  BOOST_CHECK(particle.isAlive());
90 
91  // loose a lot of energy
92  particle.correctEnergy(-3_GeV);
93  BOOST_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
94  BOOST_CHECK_EQUAL(particle.absoluteMomentum(), Particle::Scalar(0));
95  BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
96  CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
97  // particle is not alive anymore
98  BOOST_CHECK(not particle.isAlive());
99 
100  // lossing even more energy does nothing
101  particle.correctEnergy(-10_GeV);
102  BOOST_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
103  BOOST_CHECK_EQUAL(particle.absoluteMomentum(), Particle::Scalar(0));
104  BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
105  CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
106  // particle is still not alive
107  BOOST_CHECK(not particle.isAlive());
108 }
109 
110 BOOST_AUTO_TEST_SUITE_END()