Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeMaterialInteractionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeMaterialInteractionTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
23 
24 #include <memory>
25 
26 namespace tt = boost::test_tools;
27 using namespace Acts::UnitLiterals;
28 
29 namespace Acts {
30 namespace Test {
31 
33 struct StepperState {
35  Vector3 pos, dir;
36  double t = 0, p = 0, q = 0;
37  bool covTransport = false;
38  double absCharge = UnitConstants::e;
39 };
40 
43  TrackingVolume* currentVolume = nullptr;
44 };
45 
47 struct State {
48  struct {
50  } options;
51 
54 };
55 
57 struct Stepper {
58  Stepper() = default;
59 
60  Vector3 position(const StepperState& state) const { return state.pos; }
61 
62  double time(const StepperState& state) const { return state.t; }
63 
64  Vector3 direction(const StepperState& state) const { return state.dir; }
65 
66  double qOverP(const StepperState& state) const { return state.q / state.p; }
67 
68  double absoluteMomentum(const StepperState& state) const { return state.p; }
69 
70  double charge(const StepperState& state) const { return state.q; };
71 
73  return state.particleHypothesis;
74  };
75 };
76 
78 struct Navigator {
80  return state.currentVolume;
81  }
82 };
83 
84 BOOST_AUTO_TEST_CASE(volume_material_interaction_test) {
85  // Create a Tracking Volume
86  auto htrans = Transform3(Translation3{-10., -10., 0.});
87  auto bound = std::make_shared<const CuboidVolumeBounds>(1_m, 1_m, 1_m);
88  auto mat = makeSilicon();
89  auto volMat = std::make_shared<const HomogeneousVolumeMaterial>(mat);
90  auto volume = TrackingVolume::create(htrans, bound, volMat);
91 
92  // Create a propagator state
93  State state;
95  ParticleHypothesis(static_cast<PdgParticle>(11), 10., 9.);
96  state.stepping.pos = Vector3(1., 2., 3.);
97  state.stepping.dir = Vector3(4., 5., 6.);
98  state.stepping.t = 7.;
99  state.stepping.p = 8.;
100  state.stepping.q = 9.;
101  state.stepping.absCharge = std::abs(state.stepping.q);
102  state.stepping.covTransport = true;
104  state.navigation.currentVolume = volume.get();
105 
108 
109  // Build the VolumeMaterialInteraction & test assignments
110  detail::VolumeMaterialInteraction volMatInt(volume.get(), state, stepper);
111  BOOST_CHECK_EQUAL(volMatInt.volume.trackingVolume, volume.get());
112  BOOST_CHECK_EQUAL(volMatInt.pos, stepper.position(state.stepping));
113  BOOST_CHECK_EQUAL(volMatInt.time, stepper.time(state.stepping));
114  BOOST_CHECK_EQUAL(volMatInt.dir, stepper.direction(state.stepping));
115  BOOST_CHECK_EQUAL(volMatInt.momentum,
116  stepper.absoluteMomentum(state.stepping));
117  BOOST_CHECK_EQUAL(volMatInt.absQ, std::abs(stepper.charge(state.stepping)));
118  CHECK_CLOSE_ABS(volMatInt.qOverP, stepper.qOverP(state.stepping), 1e-6);
119  BOOST_CHECK_EQUAL(volMatInt.mass, state.stepping.particleHypothesis.mass());
120  BOOST_CHECK_EQUAL(volMatInt.absPdg,
121  state.stepping.particleHypothesis.absolutePdg());
122  BOOST_CHECK_EQUAL(volMatInt.performCovarianceTransport,
123  state.stepping.covTransport);
124  BOOST_CHECK_EQUAL(volMatInt.navDir, state.options.direction);
125 
126  // Evaluate the material
127  bool result = volMatInt.evaluateMaterialSlab(state, navigator);
128  BOOST_CHECK(result);
129  BOOST_CHECK_EQUAL(volMatInt.slab.material(), mat);
130  BOOST_CHECK_EQUAL(volMatInt.slab.thickness(), 1.);
131  BOOST_CHECK_EQUAL(volMatInt.pathCorrection, 0.);
132 
133  // Evaluate the material without a tracking volume
134  state.navigation.currentVolume = nullptr;
135  result = volMatInt.evaluateMaterialSlab(state, navigator);
136  BOOST_CHECK(!result);
137  BOOST_CHECK_EQUAL(volMatInt.pathCorrection, 0.);
138 }
139 
140 } // namespace Test
141 } // namespace Acts