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