ECCE @ EIC 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 
11 #include <limits>
12 
14 #include "Acts/Utilities/Units.hpp"
16 
17 using Acts::PdgParticle;
20 using namespace Acts::UnitLiterals;
21 
22 namespace {
24 }
25 
26 BOOST_AUTO_TEST_SUITE(FatrasParticle)
27 
29  const auto pid = Barcode().setVertexPrimary(1).setParticle(42);
30  const auto particle = Particle(pid, PdgParticle::eProton, 1_GeV, 1_e);
31 
32  BOOST_TEST(particle.particleId() == pid);
33  BOOST_TEST(particle.pdg() == PdgParticle::eProton);
34  // particle is at rest at the origin
35  BOOST_TEST(particle.position4() == Particle::Vector4::Zero());
36  BOOST_TEST(particle.position() == Particle::Vector3::Zero());
37  BOOST_TEST(particle.time() == Particle::Scalar(0));
38  BOOST_TEST(particle.position4().x() == particle.position().x());
39  BOOST_TEST(particle.position4().y() == particle.position().y());
40  BOOST_TEST(particle.position4().z() == particle.position().z());
41  BOOST_TEST(particle.position4().w() == particle.time());
42  // particle direction is undefined, but must be normalized
43  CHECK_CLOSE_REL(particle.unitDirection().norm(), 1, eps);
44  BOOST_TEST(particle.transverseMomentum() == Particle::Scalar(0));
45  BOOST_TEST(particle.absMomentum() == Particle::Scalar(0));
46  // particle is created at rest and thus not alive
47  BOOST_TEST(not particle);
48 }
49 
50 BOOST_AUTO_TEST_CASE(CorrectEnergy) {
51  const auto pid = Barcode().setVertexPrimary(1).setParticle(42);
53  .setDirection(Particle::Vector3::UnitX())
55 
56  BOOST_TEST(particle.mass() == 1_GeV);
57  // check that the particle has some input energy
58  BOOST_TEST(particle.momentum4().x() == 2_GeV);
59  BOOST_TEST(particle.momentum4().y() == 0_GeV);
60  BOOST_TEST(particle.momentum4().z() == 0_GeV);
61  BOOST_TEST(particle.momentum4().w() == std::hypot(1_GeV, 2_GeV));
62  BOOST_TEST(particle.transverseMomentum() == 2_GeV);
63  BOOST_TEST(particle.absMomentum() == 2_GeV);
64  BOOST_TEST(particle.energy() == std::hypot(1_GeV, 2_GeV));
65  // particle direction must be normalized
66  CHECK_CLOSE_REL(particle.unitDirection().norm(), 1, eps);
67  // loose some energy
68  particle.correctEnergy(-100_MeV);
69  BOOST_TEST(particle.transverseMomentum() < 2_GeV);
70  BOOST_TEST(particle.absMomentum() < 2_GeV);
71  BOOST_TEST(particle.energy() ==
72  Particle::Scalar(std::hypot(1_GeV, 2_GeV) - 100_MeV));
73  CHECK_CLOSE_REL(particle.unitDirection().norm(), 1, eps);
74  // particle is still alive
75  BOOST_TEST(particle);
76  // loose a lot of energy
77  particle.correctEnergy(-3_GeV);
78  BOOST_TEST(particle.transverseMomentum() == Particle::Scalar(0));
79  BOOST_TEST(particle.absMomentum() == Particle::Scalar(0));
80  BOOST_TEST(particle.energy() == particle.mass());
81  CHECK_CLOSE_REL(particle.unitDirection().norm(), 1, eps);
82  // lossing even more energy does nothing
83  particle.correctEnergy(-10_GeV);
84  BOOST_TEST(particle.transverseMomentum() == Particle::Scalar(0));
85  BOOST_TEST(particle.absMomentum() == Particle::Scalar(0));
86  BOOST_TEST(particle.energy() == particle.mass());
87  CHECK_CLOSE_REL(particle.unitDirection().norm(), 1, eps);
88  // particle is not alive anymore
89  BOOST_TEST(not particle);
90 }
91 
92 BOOST_AUTO_TEST_SUITE_END()