Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PhotonConversionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PhotonConversionTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 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/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
11 
19 
20 #include <cmath>
21 #include <limits>
22 #include <memory>
23 #include <random>
24 #include <utility>
25 #include <vector>
26 
27 #include "Dataset.hpp"
28 
29 using Generator = std::ranlux48;
30 
31 BOOST_AUTO_TEST_SUITE(FatrasPhotonConversion)
32 
34  seed) {
36  using namespace Acts::UnitLiterals;
37 
38  Generator gen(seed);
39 
43  ActsFatras::Particle particleInit = particle;
44 
46 
47  // No limits should be set
48  std::pair<Scalar, Scalar> limits;
49  limits = pc.generatePathLimits(gen, particle);
50  BOOST_CHECK_EQUAL(limits.first, std::numeric_limits<Scalar>::infinity());
51  BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<Scalar>::infinity());
52 
53  // No particles should be generated
54  std::vector<ActsFatras::Particle> generated;
55  BOOST_CHECK(!pc.run(gen, particle, generated));
56  BOOST_CHECK(generated.empty());
57  // Particle shouldn't be modified
58  BOOST_CHECK_EQUAL(particle.fourPosition(), particleInit.fourPosition());
59  BOOST_CHECK_EQUAL(particle.fourMomentum(), particleInit.fourMomentum());
60  BOOST_CHECK_EQUAL(particle.process(), particleInit.process());
61  BOOST_CHECK_EQUAL(particle.properTime(), particleInit.properTime());
62  BOOST_CHECK_EQUAL(particle.pathInX0(), particleInit.pathInX0());
63  BOOST_CHECK_EQUAL(particle.pathInL0(), particleInit.pathInL0());
64 }
65 
67  lambda, seed) {
69  using namespace Acts::UnitLiterals;
70 
72 
76  ActsFatras::Particle particleInit = particle;
77 
79 
80  // No limits should be set - momentum too low
81  std::pair<Scalar, Scalar> limits = pc.generatePathLimits(gen, particle);
82  BOOST_CHECK_EQUAL(limits.first, std::numeric_limits<Scalar>::infinity());
83  BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<Scalar>::infinity());
84 
85  // No particles should be generated - momentum too low
86  std::vector<ActsFatras::Particle> generated;
87  BOOST_CHECK(!pc.run(gen, particle, generated));
88  BOOST_CHECK(generated.empty());
89  // Particle shouldn't be modified
90  BOOST_CHECK_EQUAL(particle.fourPosition(), particleInit.fourPosition());
91  BOOST_CHECK_EQUAL(particle.fourMomentum(), particleInit.fourMomentum());
92  BOOST_CHECK_EQUAL(particle.process(), particleInit.process());
93  BOOST_CHECK_EQUAL(particle.properTime(), particleInit.properTime());
94  BOOST_CHECK_EQUAL(particle.pathInX0(), particleInit.pathInX0());
95  BOOST_CHECK_EQUAL(particle.pathInL0(), particleInit.pathInL0());
96 }
97 
99  phi, lambda, seed) {
101  using namespace Acts::UnitLiterals;
102 
103  Generator gen(seed);
104 
108  ActsFatras::Particle particleInit = particle;
109 
111 
112  // No limits should be set - momentum too low
113  std::pair<Scalar, Scalar> limits = pc.generatePathLimits(gen, particle);
114  BOOST_CHECK_EQUAL(limits.first, std::numeric_limits<Scalar>::infinity());
115  BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<Scalar>::infinity());
116 
117  // No particles should be generated - momentum too low
118  std::vector<ActsFatras::Particle> generated;
119  BOOST_CHECK(!pc.run(gen, particle, generated));
120  BOOST_CHECK(generated.empty());
121  // Particle shouldn't be modified
122  BOOST_CHECK_EQUAL(particle.fourPosition(), particleInit.fourPosition());
123  BOOST_CHECK_EQUAL(particle.fourMomentum(), particleInit.fourMomentum());
124  BOOST_CHECK_EQUAL(particle.process(), particleInit.process());
125  BOOST_CHECK_EQUAL(particle.properTime(), particleInit.properTime());
126  BOOST_CHECK_EQUAL(particle.pathInX0(), particleInit.pathInX0());
127  BOOST_CHECK_EQUAL(particle.pathInL0(), particleInit.pathInL0());
128 }
129 
131  phi, lambda, seed) {
133  using namespace Acts::UnitLiterals;
134 
135  Generator gen(seed);
136 
140  ActsFatras::Particle particleInit = particle;
141 
143 
144  // No limits should be set - momentum too low
145  std::pair<Scalar, Scalar> limits = pc.generatePathLimits(gen, particle);
146  BOOST_CHECK_NE(limits.first, std::numeric_limits<Scalar>::infinity());
147  BOOST_CHECK_EQUAL(limits.second, std::numeric_limits<Scalar>::infinity());
148 
149  // No particles should be generated - momentum too low
150  std::vector<ActsFatras::Particle> generated;
151  BOOST_CHECK(pc.run(gen, particle, generated));
152  BOOST_CHECK_EQUAL(generated.size(), 2);
153 
154  // Test the children
155  BOOST_CHECK((generated[0].pdg() == Acts::PdgParticle::eElectron) ||
156  (generated[0].pdg() == Acts::PdgParticle::ePositron));
157  BOOST_CHECK((generated[1].pdg() == Acts::PdgParticle::eElectron) ||
158  (generated[1].pdg() == Acts::PdgParticle::ePositron));
159  BOOST_CHECK_NE(generated[0].pdg(), generated[1].pdg());
160  BOOST_CHECK_NE(generated[0].fourMomentum(), Acts::Vector4::Zero());
161  BOOST_CHECK_NE(generated[1].fourMomentum(), Acts::Vector4::Zero());
162 
163  // Test for similar invariant masses
164  Acts::Vector4 momSum =
165  generated[0].fourMomentum() + generated[1].fourMomentum();
166  Acts::Vector3 momVector = momSum.template segment<3>(Acts::eMom0);
167  double sSum = momSum[Acts::eEnergy] * momSum[Acts::eEnergy] -
168  momVector.norm() * momVector.norm();
169  BOOST_CHECK(std::isfinite(sSum));
170 
171  double sParticle =
172  particleInit.energy() * particleInit.energy() -
173  particleInit.absoluteMomentum() * particleInit.absoluteMomentum();
174  BOOST_CHECK(std::isfinite(sParticle));
175  CHECK_CLOSE_OR_SMALL(sSum, sParticle, 1e-2, 1e-2);
176 }
177 
178 BOOST_AUTO_TEST_SUITE_END()