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 
12 #include "Acts/Utilities/Units.hpp"
14 
15 #include <limits>
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_CHECK_EQUAL(particle.particleId(), pid);
33  BOOST_CHECK_EQUAL(particle.pdg(), PdgParticle::eProton);
34  // particle is at rest at the origin
35  BOOST_CHECK_EQUAL(particle.position4(), Particle::Vector4::Zero());
36  BOOST_CHECK_EQUAL(particle.position(), Particle::Vector3::Zero());
37  BOOST_CHECK_EQUAL(particle.time(), Particle::Scalar(0));
38  BOOST_CHECK_EQUAL(particle.position4().x(), particle.position().x());
39  BOOST_CHECK_EQUAL(particle.position4().y(), particle.position().y());
40  BOOST_CHECK_EQUAL(particle.position4().z(), particle.position().z());
41  BOOST_CHECK_EQUAL(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_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
45  BOOST_CHECK_EQUAL(particle.absMomentum(), Particle::Scalar(0));
46  // particle is created at rest and thus not alive
47  BOOST_CHECK(not particle);
48 }
49 
50 BOOST_AUTO_TEST_CASE(CorrectEnergy) {
51  const auto pid = Barcode().setVertexPrimary(1).setParticle(42);
52  auto particle = Particle(pid, PdgParticle::eProton, 1_GeV, 1_e)
53  .setDirection(Particle::Vector3::UnitX())
54  .setAbsMomentum(2_GeV);
55 
56  BOOST_CHECK_EQUAL(particle.mass(), 1_GeV);
57  // check that the particle has some input energy
58  BOOST_CHECK_EQUAL(particle.momentum4().x(), 2_GeV);
59  BOOST_CHECK_EQUAL(particle.momentum4().y(), 0_GeV);
60  BOOST_CHECK_EQUAL(particle.momentum4().z(), 0_GeV);
61  BOOST_CHECK_EQUAL(particle.momentum4().w(), std::hypot(1_GeV, 2_GeV));
62  BOOST_CHECK_EQUAL(particle.transverseMomentum(), 2_GeV);
63  BOOST_CHECK_EQUAL(particle.absMomentum(), 2_GeV);
64  BOOST_CHECK_EQUAL(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_CHECK_LT(particle.transverseMomentum(), 2_GeV);
70  BOOST_CHECK_LT(particle.absMomentum(), 2_GeV);
71  BOOST_CHECK_EQUAL(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_CHECK(particle);
76  // loose a lot of energy
77  particle.correctEnergy(-3_GeV);
78  BOOST_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
79  BOOST_CHECK_EQUAL(particle.absMomentum(), Particle::Scalar(0));
80  BOOST_CHECK_EQUAL(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_CHECK_EQUAL(particle.transverseMomentum(), Particle::Scalar(0));
85  BOOST_CHECK_EQUAL(particle.absMomentum(), Particle::Scalar(0));
86  BOOST_CHECK_EQUAL(particle.energy(), particle.mass());
87  CHECK_CLOSE_REL(particle.unitDirection().norm(), 1, eps);
88  // particle is not alive anymore
89  BOOST_CHECK(not particle);
90 }
91 
92 BOOST_AUTO_TEST_SUITE_END()