Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EnergyLossTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EnergyLossTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 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 
10 #define BOOST_TEST_MODULE AbortList Tests
11 
12 #include <boost/test/included/unit_test.hpp>
13 // leave blank line
14 
15 #include <boost/test/data/test_case.hpp>
16 // leave blank line
17 
18 #include <boost/test/output_test_stream.hpp>
19 // leave blank line
20 
22 #include "Acts/Material/MaterialProperties.hpp"
27 #include "Particle.hpp"
28 #include <fstream>
29 #include <random>
30 
31 namespace bdata = boost::unit_test::data;
32 namespace tt = boost::test_tools;
33 namespace au = Acts::units;
34 
35 namespace Fatras {
36 
37 namespace Test {
38 
39 // the generator
40 typedef std::mt19937 Generator;
41 
42 // standard generator
44 
45 // some material
46 Acts::Material berilium = Acts::Material(352.8, 407., 9.012, 4.,
47  1.848 / (au::_cm * au::_cm * au::_cm));
48 
50 struct Selector {
51 
53  template <typename detector_t, typename particle_t>
54  bool operator()(const detector_t, const particle_t &) const {
55  return true;
56  }
57 };
58 
60 bool write_csv = true;
61 
62 std::ofstream os("EnergyLoss.csv", std::ofstream::out | std::ofstream::trunc);
63 
66  EnergyLoss_test_,
67  bdata::random(
68  (bdata::seed = 20,
69  bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
70  bdata::random(
71  (bdata::seed = 21,
72  bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
73  bdata::random(
74  (bdata::seed = 22,
75  bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
76  bdata::random((bdata::seed = 23,
77  bdata::distribution =
78  std::uniform_real_distribution<>(1.5, 10.5))) ^
79  bdata::xrange(10000),
80  x, y, z, p, index) {
81 
82  Acts::MaterialProperties detector(berilium, 10. * Acts::units::_mm);
83 
84  // create the particle and set the momentum
86  Acts::Vector3D position{0., 0., 0.};
87  // p of 1 GeV
88  Acts::Vector3D momentum =
89  p * Acts::units::_GeV * Acts::Vector3D(x, y, z).normalized();
90  // positively charged
91  double q = -1.;
92  double m = 105.658367 * Acts::units::_MeV; // muon mass
93  const double me = 0.51099891 * Acts::units::_MeV; // electron mass
94 
95  // create the particle
96  Particle particle(position, momentum, m, q, 13, 1);
97  BOOST_CHECK_EQUAL(particle.m(), m);
98  BOOST_CHECK_EQUAL(particle.pdg(), 13);
99 
100  // make the highland scatterer
101  BetheBloch bbloch;
102  BetheHeitler bheitler;
103  double E = particle.E();
104 
105  auto bbr = bbloch(generator, detector, particle);
106  double eloss_io = E - particle.E();
107 
108  // Check if the particle actually lost energy
109  BOOST_CHECK(E >= particle.E());
110  BOOST_CHECK(bbr.size() == 0);
111 
112  // recreate the particle as an electron
113  particle = Particle(position, momentum, me, q, 11, 1);
114  BOOST_CHECK_EQUAL(particle.m(), me);
115  BOOST_CHECK_EQUAL(particle.pdg(), 11);
116 
117  E = particle.E();
118 
119  auto bhr = bheitler(generator, detector, particle);
120  double eloss_rad = E - particle.E();
121  BOOST_CHECK(E >= particle.E());
122  BOOST_CHECK(bhr.size() == 0);
123 
124  // write out a csv file
125  if (write_csv) {
126  if (!index)
127  os << "p,bethe_bloch,bethe_heitler" << '\n';
128  os << particle.p() << "," << eloss_io << "," << eloss_rad << '\n';
129  }
130 
131  // Accept everything
132  typedef Selector All;
133  // Define the processes with selectors
134  typedef Process<BetheBloch, All, All, All> BetheBlochProcess;
135  typedef Process<BetheHeitler, All, All, All> BetheHeitlerProcess;
136 
137  // now check the EnergyLoss as a PhysicsList
139  EnergyLoss eLossPhysicsList;
140 
141  std::vector<Particle> outgoing;
142  BOOST_CHECK(!eLossPhysicsList(generator, detector, particle, outgoing));
143  BOOST_CHECK(!outgoing.size());
144 }
145 
146 } // namespace Test
147 } // namespace Fatras