Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ScatteringTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ScatteringTests.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"
23 
30 #include "Particle.hpp"
31 #include <fstream>
32 #include <random>
33 
34 namespace bdata = boost::unit_test::data;
35 namespace tt = boost::test_tools;
36 
37 namespace Fatras {
38 
39 namespace Test {
40 
41 // the generator
42 typedef std::mt19937 Generator;
43 
44 // standard generator
46 
48 struct Selector {
49 
51  template <typename detector_t, typename particle_t>
52  bool operator()(const detector_t &, const particle_t &) const {
53  return true;
54  }
55 };
56 
57 // some material
58 Acts::Material berilium = Acts::Material(352.8, 407., 9.012, 4., 1.848e-3);
59 
60 bool write_csv = true;
61 
62 std::ofstream os("ScatteringAngles.csv",
63  std::ofstream::out | std::ofstream::trunc);
64 
67  HighlandScattering_test_,
68  bdata::random(
69  (bdata::seed = 20,
70  bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
71  bdata::random(
72  (bdata::seed = 21,
73  bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
74  bdata::random(
75  (bdata::seed = 22,
76  bdata::distribution = std::uniform_real_distribution<>(0., 1.))) ^
77  bdata::random((bdata::seed = 23,
78  bdata::distribution =
79  std::uniform_real_distribution<>(0.5, 10.5))) ^
80  bdata::xrange(10000),
81  x, y, z, p, index) {
82 
83  // a detector with 1 mm Be
84  Acts::MaterialProperties detector(berilium, 1. * Acts::units::_mm);
85 
86  // create the particle and set the momentum
88  Acts::Vector3D position{0., 0., 0.};
89  // p of 1 GeV
90  Acts::Vector3D momentum =
91  p * Acts::units::_GeV * Acts::Vector3D(x, y, z).normalized();
92  // positively charged
93  double q = -1.;
94  double m = 105.658367 * Acts::units::_MeV; // muon mass
95 
96  // create the particle
97  Particle particle(position, momentum, m, q, 13, 1);
98 
99  // make the highland scatterer
100  Highland hscat;
101  GaussianMixture gamscat;
102  GeneralMixture genscat;
103 
104  double hsr = hscat(generator, detector, particle);
105  double gamr = gamscat(generator, detector, particle);
106  double genr = genscat(generator, detector, particle);
107 
108  BOOST_CHECK(hsr != 0.);
109 
110  // Run the Scatterer as a plug-in process
111  Scattering<Highland> hsScattering;
112  auto out = hsScattering(generator, detector, particle);
113  BOOST_CHECK(!out.size());
114 
115  // Run the Scatterer as a physics list
116  typedef Selector All;
117  std::vector<Particle> outgoing;
118  typedef Process<Scattering<Highland>, All, All, All> HighlandProcess;
119  PhysicsList<HighlandProcess> hsPhysicsList;
120  hsPhysicsList(generator, detector, particle, outgoing);
121  BOOST_CHECK(!outgoing.size());
122 
123  // write out a csv file
124  if (write_csv) {
125  if (!index)
126  os << "p,highland,gaussian_mixture,general_mixture" << '\n';
127  os << particle.p() << "," << hsr << "," << gamr << "," << genr << '\n';
128  }
129 }
130 
131 } // namespace Test
132 
133 } // namespace Fatras