forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleTests.cpp
More file actions
108 lines (90 loc) · 4.24 KB
/
ParticleTests.cpp
File metadata and controls
108 lines (90 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include <boost/test/unit_test.hpp>
#include "Acts/Definitions/PdgParticle.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/Utilities/MathHelpers.hpp"
#include "ActsFatras/EventData/Barcode.hpp"
#include "ActsFatras/EventData/Particle.hpp"
#include "ActsFatras/EventData/SimulationOutcome.hpp"
#include "ActsTests/CommonHelpers/FloatComparisons.hpp"
#include <limits>
using Acts::PdgParticle;
using ActsFatras::Barcode;
using ActsFatras::Particle;
using namespace Acts;
using namespace Acts::UnitLiterals;
using namespace ActsFatras;
namespace {
constexpr auto eps = std::numeric_limits<double>::epsilon();
}
namespace ActsTests {
BOOST_AUTO_TEST_SUITE(EventDataSuite)
BOOST_AUTO_TEST_CASE(Construct) {
const auto pid = Barcode().withVertexPrimary(1).withParticle(42);
const auto particle = Particle(pid, PdgParticle::eProton, 1_e, 1_GeV);
BOOST_CHECK_EQUAL(particle.particleId(), pid);
BOOST_CHECK_EQUAL(particle.pdg(), PdgParticle::eProton);
// particle is at rest at the origin
BOOST_CHECK_EQUAL(particle.fourPosition(), Vector4::Zero());
BOOST_CHECK_EQUAL(particle.position(), Vector3::Zero());
BOOST_CHECK_EQUAL(particle.time(), 0.);
BOOST_CHECK_EQUAL(particle.fourPosition().x(), particle.position().x());
BOOST_CHECK_EQUAL(particle.fourPosition().y(), particle.position().y());
BOOST_CHECK_EQUAL(particle.fourPosition().z(), particle.position().z());
BOOST_CHECK_EQUAL(particle.fourPosition().w(), particle.time());
// particle direction is undefined, but must be normalized
CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
BOOST_CHECK_EQUAL(particle.transverseMomentum(), 0.);
BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 0.);
}
BOOST_AUTO_TEST_CASE(CorrectEnergy) {
const auto pid = Barcode().withVertexPrimary(1).withParticle(42);
auto particle = Particle(pid, PdgParticle::eProton, 1_e, 1_GeV)
.setDirection(Vector3::UnitX())
.setAbsoluteMomentum(2_GeV);
BOOST_CHECK_EQUAL(particle.mass(), 1_GeV);
// check that the particle has some input energy
BOOST_CHECK_EQUAL(particle.fourMomentum().x(), 2_GeV);
BOOST_CHECK_EQUAL(particle.fourMomentum().y(), 0_GeV);
BOOST_CHECK_EQUAL(particle.fourMomentum().z(), 0_GeV);
BOOST_CHECK_EQUAL(particle.fourMomentum().w(), Acts::fastHypot(1_GeV, 2_GeV));
BOOST_CHECK_EQUAL(particle.transverseMomentum(), 2_GeV);
BOOST_CHECK_EQUAL(particle.absoluteMomentum(), 2_GeV);
BOOST_CHECK_EQUAL(particle.energy(), Acts::fastHypot(1_GeV, 2_GeV));
// particle direction must be normalized
CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
// lose some energy
particle.loseEnergy(100_MeV);
BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
BOOST_CHECK_GT(particle.transverseMomentum(), 0_GeV);
BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
BOOST_CHECK_GT(particle.absoluteMomentum(), 0_GeV);
CHECK_CLOSE_REL(particle.energy(), Acts::fastHypot(1_GeV, 2_GeV) - 100_MeV,
eps);
CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
// lose some more energy
particle.loseEnergy(200_MeV);
BOOST_CHECK_LT(particle.transverseMomentum(), 2_GeV);
BOOST_CHECK_GT(particle.transverseMomentum(), 0_GeV);
BOOST_CHECK_LT(particle.absoluteMomentum(), 2_GeV);
BOOST_CHECK_GT(particle.absoluteMomentum(), 0_GeV);
CHECK_CLOSE_REL(particle.energy(), Acts::fastHypot(1_GeV, 2_GeV) - 300_MeV,
eps);
CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
// lose too much energy without a stopping strategy
BOOST_CHECK_THROW(particle.loseEnergy(10_GeV), std::invalid_argument);
// lose too much energy with a stopping strategy
particle.loseEnergy(10_GeV, SimulationOutcome::KilledInteraction);
BOOST_CHECK_GT(particle.transverseMomentum(), 0.);
BOOST_CHECK_GT(particle.absoluteMomentum(), 0.);
CHECK_CLOSE_REL(particle.direction().norm(), 1, eps);
BOOST_CHECK_EQUAL(particle.outcome(), SimulationOutcome::KilledInteraction);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace ActsTests