Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AccumulatedMaterialSlabTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AccumulatedMaterialSlabTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
16 
17 #include <limits>
18 #include <utility>
19 
20 namespace {
21 
23 using Acts::Material;
24 using Acts::MaterialSlab;
27 
28 constexpr auto eps = std::numeric_limits<float>::epsilon();
29 
30 } // namespace
31 
32 BOOST_AUTO_TEST_SUITE(MaterialAccumulatedMaterialSlab)
33 
35  AccumulatedMaterialSlab a;
36  auto [average, trackCount] = a.totalAverage();
37  // material is vacuum
38  BOOST_CHECK(not(average));
39  BOOST_CHECK_EQUAL(trackCount, 0u);
40 }
41 
42 // average three empty tracks which are ignored by default
43 BOOST_AUTO_TEST_CASE(EmptyTracksIgnored) {
44  AccumulatedMaterialSlab a;
45  a.trackAverage();
46  a.trackAverage();
47  a.trackAverage();
48  auto [average, trackCount] = a.totalAverage();
49  BOOST_CHECK(not(average));
50  BOOST_CHECK_EQUAL(trackCount, 0u);
51 }
52 
53 // average three empty tracks and do not ignore them
54 BOOST_AUTO_TEST_CASE(EmptyTracks) {
55  AccumulatedMaterialSlab a;
56  a.trackAverage(true);
57  a.trackAverage(true);
58  a.trackAverage(true);
59  auto [average, trackCount] = a.totalAverage();
60  BOOST_CHECK(not(average));
61  BOOST_CHECK_EQUAL(trackCount, 3u);
62 }
63 
64 BOOST_AUTO_TEST_CASE(MultipleIdenticalThicknessTrackSteps) {
65  MaterialSlab unit = makeUnitSlab();
66  AccumulatedMaterialSlab a;
67  // accumulate three identical steps for one track
68  {
69  a.accumulate(unit);
70  a.accumulate(unit);
71  a.accumulate(unit);
72  a.trackAverage();
73  auto [average, trackCount] = a.totalAverage();
74  BOOST_CHECK_EQUAL(trackCount, 1u);
75  BOOST_CHECK_EQUAL(average.material(), unit.material());
76  BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
77  BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
78  BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
79  }
80  // accumulate three identical steps for one additional track
81  {
82  a.accumulate(unit);
83  a.accumulate(unit);
84  a.accumulate(unit);
85  a.trackAverage();
86  auto [average, trackCount] = a.totalAverage();
87  BOOST_CHECK_EQUAL(trackCount, 2u);
88  // averages must stay the same since we added the same material again
89  BOOST_CHECK_EQUAL(average.material(), unit.material());
90  BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
91  BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
92  BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
93  }
94 }
95 
96 // accumulate and average three tracks.
97 // each track contributes the same material but each in different steps.
98 BOOST_AUTO_TEST_CASE(MultipleDifferentThicknessTrackSteps) {
99  MaterialSlab unit = makeUnitSlab();
100  AccumulatedMaterialSlab a;
101  // accumulate three identical steps
102  {
103  a.accumulate(unit);
104  a.accumulate(unit);
105  a.accumulate(unit);
106  a.trackAverage();
107  auto [average, trackCount] = a.totalAverage();
108  BOOST_CHECK_EQUAL(trackCount, 1u);
109  BOOST_CHECK_EQUAL(average.material(), unit.material());
110  BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
111  BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
112  BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
113  }
114  // accumulate one step with thickness 1, one with thickness 2
115  {
116  MaterialSlab twice = unit;
117  twice.scaleThickness(2);
118  a.accumulate(unit);
119  a.accumulate(twice);
120  a.trackAverage();
121  auto [average, trackCount] = a.totalAverage();
122  BOOST_CHECK_EQUAL(trackCount, 2u);
123  // averages must stay the same
124  BOOST_CHECK_EQUAL(average.material(), unit.material());
125  BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
126  BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
127  BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
128  }
129  // accumulate one step with thickness 3
130  {
131  MaterialSlab thrice = unit;
132  thrice.scaleThickness(3);
133  a.accumulate(thrice);
134  a.trackAverage();
135  auto [average, trackCount] = a.totalAverage();
136  BOOST_CHECK_EQUAL(trackCount, 3u);
137  // averages must stay the same
138  BOOST_CHECK_EQUAL(average.material(), unit.material());
139  BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
140  BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
141  BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
142  }
143 }
144 
145 // average multiple tracks w/ one step each but different materials
146 BOOST_AUTO_TEST_CASE(MultipleDifferentTracks) {
147  MaterialSlab unit = makeUnitSlab();
148  AccumulatedMaterialSlab a;
149  // add material w/ given thickness
150  {
151  a.accumulate(unit);
152  a.trackAverage();
153  auto [average, trackCount] = a.totalAverage();
154  BOOST_CHECK_EQUAL(trackCount, 1u);
155  BOOST_CHECK_EQUAL(average.material(), unit.material());
156  BOOST_CHECK_EQUAL(average.thickness(), unit.thickness());
157  BOOST_CHECK_EQUAL(average.thicknessInX0(), unit.thicknessInX0());
158  BOOST_CHECK_EQUAL(average.thicknessInL0(), unit.thicknessInL0());
159  }
160  // add material w/ given three times the initial thickness
161  {
162  MaterialSlab three = unit;
163  three.scaleThickness(3);
164  a.accumulate(three);
165  a.trackAverage();
166  auto [average, trackCount] = a.totalAverage();
167  BOOST_CHECK_EQUAL(trackCount, 2);
168  // average thickness should now be 2*initial, average material unchanged
169  BOOST_CHECK_EQUAL(average.material(), unit.material());
170  BOOST_CHECK_EQUAL(average.thickness(), 2 * unit.thickness());
171  BOOST_CHECK_EQUAL(average.thicknessInX0(), 2 * unit.thicknessInX0());
172  BOOST_CHECK_EQUAL(average.thicknessInL0(), 2 * unit.thicknessInL0());
173  }
174  // add vacuum w/ given the same thickness as the current average
175  {
176  MaterialSlab vac(2 * unit.thickness());
177  // add vacuum twice to counteract the existing two tracks stored
178  a.accumulate(vac);
179  a.trackAverage();
180  a.accumulate(vac);
181  a.trackAverage();
182  auto [average, trackCount] = a.totalAverage();
183  BOOST_CHECK_EQUAL(trackCount, 4u);
184  // average material density halved
185  CHECK_CLOSE_REL(average.material().X0(), 2 * unit.material().X0(), eps);
186  CHECK_CLOSE_REL(average.material().L0(), 2 * unit.material().L0(), eps);
187  CHECK_CLOSE_REL(average.material().molarDensity(),
188  0.5f * unit.material().molarDensity(), eps);
189  // average atom is still the same species
190  CHECK_CLOSE_REL(average.material().Ar(), unit.material().Ar(), eps);
191  // average atomic number proportional to the thickness
192  CHECK_CLOSE_REL(average.material().Z(), 0.5 * unit.material().Z(), eps);
193  // thickness in x0/l0 depends on density and thus halved as well
194  BOOST_CHECK_EQUAL(average.thicknessInX0(), 1 * unit.thicknessInX0());
195  BOOST_CHECK_EQUAL(average.thicknessInL0(), 1 * unit.thicknessInL0());
196  // average real thickness stays the same
197  BOOST_CHECK_EQUAL(average.thickness(), 2 * unit.thickness());
198  }
199 }
200 
201 BOOST_AUTO_TEST_SUITE_END()