EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AverageMaterialsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AverageMaterialsTests.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 
14 
15 #include <limits>
16 
17 namespace {
18 
20 
21 constexpr auto eps = std::numeric_limits<float>::epsilon();
22 
23 // vacuum w/ different thickness
24 const Acts::MaterialSlab zeroVacuum = Acts::MaterialSlab(0.0f);
25 const Acts::MaterialSlab unitVacuum = Acts::MaterialSlab(1.0f);
26 // same material corresponding to 0%, 1% and 100% radiation/interaction length
30 
31 } // namespace
32 
33 BOOST_AUTO_TEST_SUITE(AverageMaterials)
34 
35 // average two identical slabs
36 
37 BOOST_AUTO_TEST_CASE(CombineSlabsVacuum) {
38  // vacuum with zero thickness
39  {
40  auto slab = combineSlabs(zeroVacuum, zeroVacuum);
41  BOOST_CHECK(not slab.material());
42  BOOST_CHECK_EQUAL(slab.thickness(), 0.0f);
43  BOOST_CHECK_EQUAL(slab.thicknessInX0(), 0.0f);
44  BOOST_CHECK_EQUAL(slab.thicknessInL0(), 0.0f);
45  }
46  // vacuum with unit thickness
47  {
48  auto slab = combineSlabs(unitVacuum, unitVacuum);
49  BOOST_CHECK(not slab.material());
50  BOOST_CHECK_EQUAL(slab.thickness(), 2.0f);
51  BOOST_CHECK_EQUAL(slab.thicknessInX0(), 0.0f);
52  BOOST_CHECK_EQUAL(slab.thicknessInL0(), 0.0f);
53  }
54 }
55 
56 BOOST_AUTO_TEST_CASE(CombineSlabsPercent) {
57  auto slab = combineSlabs(percent, percent);
58  // combining two identical slabs must give the same average material
59  BOOST_CHECK(slab.material());
60  BOOST_CHECK_EQUAL(slab.material(), percent);
61  // thickness-like properties must double
62  BOOST_CHECK_EQUAL(slab.thickness(), 2 * percent.thickness());
63  BOOST_CHECK_EQUAL(slab.thicknessInX0(), 2 * percent.thicknessInX0());
64  BOOST_CHECK_EQUAL(slab.thicknessInL0(), 2 * percent.thicknessInL0());
65 }
66 
67 BOOST_AUTO_TEST_CASE(CombineSlabsUnit) {
68  auto slab = combineSlabs(unit, unit);
69  // combining two identical slabs must give the same average material
70  BOOST_CHECK(slab.material());
71  BOOST_CHECK_EQUAL(slab.material(), unit);
72  // thickness-like properties must double
73  BOOST_CHECK_EQUAL(slab.thickness(), 2 * unit.thickness());
74  BOOST_CHECK_EQUAL(slab.thicknessInX0(), 2 * unit.thicknessInX0());
75  BOOST_CHECK_EQUAL(slab.thicknessInL0(), 2 * unit.thicknessInL0());
76 }
77 
78 // average a non-vacuum slab and a zero-thickness vacuum slab
79 
80 BOOST_AUTO_TEST_CASE(CombineSlabsPercentZeroVacuum) {
81  {
82  auto slab = combineSlabs(percent, zeroVacuum);
83  BOOST_CHECK(slab.material());
84  BOOST_CHECK_EQUAL(slab.material(), percent);
85  BOOST_CHECK_EQUAL(slab.thickness(), percent.thickness());
86  BOOST_CHECK_EQUAL(slab.thicknessInX0(), percent.thicknessInX0());
87  BOOST_CHECK_EQUAL(slab.thicknessInL0(), percent.thicknessInL0());
88  }
89  // reverse input order
90  {
91  auto slab = combineSlabs(zeroVacuum, percent);
92  BOOST_CHECK(slab.material());
93  BOOST_CHECK_EQUAL(slab.material(), percent);
94  BOOST_CHECK_EQUAL(slab.thickness(), percent.thickness());
95  BOOST_CHECK_EQUAL(slab.thicknessInX0(), percent.thicknessInX0());
96  BOOST_CHECK_EQUAL(slab.thicknessInL0(), percent.thicknessInL0());
97  }
98 }
99 
100 BOOST_AUTO_TEST_CASE(CombineSlabsUnitZeroVacuum) {
101  {
102  auto slab = combineSlabs(unit, zeroVacuum);
103  BOOST_CHECK(slab.material());
104  BOOST_CHECK_EQUAL(slab.material(), unit);
105  BOOST_CHECK_EQUAL(slab.thickness(), unit.thickness());
106  BOOST_CHECK_EQUAL(slab.thicknessInX0(), unit.thicknessInX0());
107  BOOST_CHECK_EQUAL(slab.thicknessInL0(), unit.thicknessInL0());
108  }
109  // reverse input order
110  {
111  auto slab = combineSlabs(zeroVacuum, unit);
112  BOOST_CHECK(slab.material());
113  BOOST_CHECK_EQUAL(slab.material(), unit);
114  BOOST_CHECK_EQUAL(slab.thickness(), unit.thickness());
115  BOOST_CHECK_EQUAL(slab.thicknessInX0(), unit.thicknessInX0());
116  BOOST_CHECK_EQUAL(slab.thicknessInL0(), unit.thicknessInL0());
117  }
118 }
119 
120 // average two non-vacuum slabs with the same material but different thickness
121 
122 BOOST_AUTO_TEST_CASE(CombineSlabsPercentUnit) {
123  // the two slabs have the same material -> average should be identical
124  {
125  auto slab = combineSlabs(percent, unit);
126  BOOST_CHECK(slab.material());
127  BOOST_CHECK_EQUAL(slab.material(), percent);
128  BOOST_CHECK_EQUAL(slab.thickness(), percent.thickness() + unit.thickness());
129  BOOST_CHECK_EQUAL(slab.thicknessInX0(),
130  percent.thicknessInX0() + unit.thicknessInX0());
131  BOOST_CHECK_EQUAL(slab.thicknessInL0(),
132  percent.thicknessInL0() + unit.thicknessInL0());
133  }
134  // reverse input order
135  {
136  auto slab = combineSlabs(unit, percent);
137  BOOST_CHECK(slab.material());
138  BOOST_CHECK_EQUAL(slab.material(), unit);
139  BOOST_CHECK_EQUAL(slab.thickness(), unit.thickness() + percent.thickness());
140  BOOST_CHECK_EQUAL(slab.thicknessInX0(),
141  percent.thicknessInX0() + unit.thicknessInX0());
142  BOOST_CHECK_EQUAL(slab.thicknessInL0(),
143  percent.thicknessInL0() + unit.thicknessInL0());
144  }
145 }
146 
147 // average two non-vacuum slabs where one has zero thickness
148 
149 BOOST_AUTO_TEST_CASE(CombineSlabsUnitZero) {
150  // the two slabs have the same material -> average should be identical
151  {
152  auto slab = combineSlabs(unit, zero);
153  BOOST_CHECK(slab.material());
154  BOOST_CHECK_EQUAL(slab.material(), unit);
155  BOOST_CHECK_EQUAL(slab.thickness(), unit.thickness());
156  BOOST_CHECK_EQUAL(slab.thicknessInX0(), unit.thicknessInX0());
157  BOOST_CHECK_EQUAL(slab.thicknessInL0(), unit.thicknessInL0());
158  }
159  // reverse input order
160  {
161  auto slab = combineSlabs(zero, unit);
162  BOOST_CHECK(slab.material());
163  BOOST_CHECK_EQUAL(slab.material(), unit);
164  BOOST_CHECK_EQUAL(slab.thickness(), unit.thickness());
165  BOOST_CHECK_EQUAL(slab.thicknessInX0(), unit.thicknessInX0());
166  BOOST_CHECK_EQUAL(slab.thicknessInL0(), unit.thicknessInL0());
167  }
168 }
169 
170 // average a non-vacuum and a vacuum slab w/ equal thickness
171 
172 BOOST_AUTO_TEST_CASE(CombineSlabsEqualThicknessVacuum) {
173  const auto mat = Acts::Test::makeSilicon();
174  const auto slabMat = Acts::MaterialSlab(mat, 1.0f);
175  const auto slabVac = Acts::MaterialSlab(Acts::Material(), 1.0f);
176  {
177  auto slab = combineSlabs(slabMat, slabVac);
178  BOOST_CHECK_EQUAL(slab.thickness(), 2.0f);
179  BOOST_CHECK_EQUAL(slab.thicknessInX0(), slabMat.thicknessInX0());
180  BOOST_CHECK_EQUAL(slab.thicknessInL0(), slabMat.thicknessInL0());
181  BOOST_CHECK(slab.material());
182  // atomic mass and nuclear charge are per atom, adding any amount vacuum
183  // does not change the average atom properties only their density
184  BOOST_CHECK_EQUAL(slab.material().Ar(), mat.Ar());
185  BOOST_CHECK_EQUAL(slab.material().Z(), mat.Z());
186  // we have the same type of interactions just spread over twice the length
187  CHECK_CLOSE_REL(slab.material().X0(), 2.0f * mat.X0(), eps);
188  CHECK_CLOSE_REL(slab.material().L0(), 2.0f * mat.L0(), eps);
189  // we have the same atoms just spread over more volume
190  BOOST_CHECK_EQUAL(slab.material().molarDensity(),
191  0.5f * mat.molarDensity());
192  }
193  // reverse input order
194  {
195  auto slab = combineSlabs(slabVac, slabMat);
196  BOOST_CHECK(slab.material());
197  BOOST_CHECK_EQUAL(slab.thickness(), 2.0f);
198  BOOST_CHECK_EQUAL(slab.thicknessInX0(), slabMat.thicknessInX0());
199  BOOST_CHECK_EQUAL(slab.thicknessInL0(), slabMat.thicknessInL0());
200  // atomic mass and nuclear charge are per atom, adding any amount vacuum
201  // does not change the average atom properties only their density
202  BOOST_CHECK_EQUAL(slab.material().Ar(), mat.Ar());
203  BOOST_CHECK_EQUAL(slab.material().Z(), mat.Z());
204  // we have the same type of interactions just spread over twice the length
205  CHECK_CLOSE_REL(slab.material().X0(), 2.0f * mat.X0(), eps);
206  CHECK_CLOSE_REL(slab.material().L0(), 2.0f * mat.L0(), eps);
207  // we have the same atoms just spread over more volume
208  BOOST_CHECK_EQUAL(slab.material().molarDensity(),
209  0.5f * mat.molarDensity());
210  }
211 }
212 
213 // average two non-vacuum slabs w/ different material and different thickness
214 
215 BOOST_AUTO_TEST_CASE(CombineSlabs) {
216  const auto mat0 = Acts::Material::fromMolarDensity(1, 1, 8, 12, 2);
217  const auto mat1 = Acts::Material::fromMolarDensity(2, 2, 2, 6, 5);
218  const auto slabMat0 = Acts::MaterialSlab(mat0, 0.5f);
219  const auto slabMat1 = Acts::MaterialSlab(mat1, 1.0f);
220  // verify derived quantities for the input slabs. these tests are not really
221  // needed, but to show the input values for the tests below.
222  BOOST_CHECK_EQUAL(slabMat0.thickness(), 0.5f);
223  BOOST_CHECK_EQUAL(slabMat0.thicknessInX0(), 0.5f);
224  BOOST_CHECK_EQUAL(slabMat0.thicknessInL0(), 0.5f);
225  BOOST_CHECK_EQUAL(slabMat1.thickness(), 1.0f);
226  BOOST_CHECK_EQUAL(slabMat1.thicknessInX0(), 0.5f);
227  BOOST_CHECK_EQUAL(slabMat1.thicknessInL0(), 0.5f);
228  // check combined slabs
229  {
230  auto slab = combineSlabs(slabMat0, slabMat1);
231  BOOST_CHECK(slab.material());
232  BOOST_CHECK_EQUAL(slab.thickness(), 1.5f);
233  BOOST_CHECK_EQUAL(slab.thicknessInX0(), 1.0f);
234  BOOST_CHECK_EQUAL(slab.thicknessInL0(), 1.0f);
235  BOOST_CHECK_EQUAL(slab.material().X0(), 1.5f);
236  BOOST_CHECK_EQUAL(slab.material().L0(), 1.5f);
237  BOOST_CHECK_EQUAL(slab.material().Ar(), 3.0f);
238  BOOST_CHECK_EQUAL(slab.material().Z(), 7.0f);
239  BOOST_CHECK_EQUAL(slab.material().molarDensity(), 4.0f);
240  }
241  // reverse input order
242  {
243  auto slab = combineSlabs(slabMat0, slabMat1);
244  BOOST_CHECK(slab.material());
245  BOOST_CHECK_EQUAL(slab.thickness(), 1.5f);
246  BOOST_CHECK_EQUAL(slab.thicknessInX0(), 1.0f);
247  BOOST_CHECK_EQUAL(slab.thicknessInL0(), 1.0f);
248  BOOST_CHECK_EQUAL(slab.material().X0(), 1.5f);
249  BOOST_CHECK_EQUAL(slab.material().L0(), 1.5f);
250  BOOST_CHECK_EQUAL(slab.material().Ar(), 3.0f);
251  BOOST_CHECK_EQUAL(slab.material().Z(), 7.0f);
252  BOOST_CHECK_EQUAL(slab.material().molarDensity(), 4.0f);
253  }
254 }
255 
256 BOOST_AUTO_TEST_SUITE_END()