ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AccumulatedMaterialPropertiesTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AccumulatedMaterialPropertiesTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 
9 #include <boost/test/unit_test.hpp>
10 
11 #include <climits>
12 
16 
17 namespace Acts {
18 namespace Test {
19 
21 BOOST_AUTO_TEST_CASE(AccumulatedMaterialProperties_construction_test) {
22  // Default constructor
24 
25  // Default copy constructor
27 
28  // Default assignment
30 
32  AccumulatedMaterialProperties bMoved(std::move(b));
33 
35  AccumulatedMaterialProperties cMovedAssigned = std::move(c);
36 
38  auto averageA = a.totalAverage();
39  BOOST_CHECK_EQUAL(bool(averageA.first), false);
40  BOOST_CHECK_EQUAL(averageA.second, 0u);
41 
43  auto averageB = bMoved.totalAverage();
44  BOOST_CHECK_EQUAL(bool(averageB.first), false);
45  BOOST_CHECK_EQUAL(averageB.second, 0u);
46 
48  auto averageC = cMovedAssigned.totalAverage();
49  BOOST_CHECK_EQUAL(bool(averageC.first), false);
50  BOOST_CHECK_EQUAL(averageC.second, 0u);
51 }
52 
54 BOOST_AUTO_TEST_CASE(AccumulatedMaterialProperties_trackaverage_test) {
55  // These are our material properties
56  MaterialProperties a(1., 2., 6., 3., 5., 1.);
57  MaterialProperties b(2., 4., 12., 6., 10., 2.);
58  MaterialProperties c(4., 8., 16., 8., 20., 3.);
59 
60  // Collect per event
62  abc.accumulate(a);
63  abc.accumulate(b);
64  abc.accumulate(c);
65  abc.trackAverage();
66 
67  // Now get back the total average - without unit thickness
68  auto averageAbc = abc.totalAverage();
69 
70  // Both should have one event
71  BOOST_CHECK_EQUAL(averageAbc.second, 1u);
72  auto mpAbc = averageAbc.first;
73 
74  // Thickness must be one for mapping
75  // Thickness in X0 is additive
76  CHECK_CLOSE_REL(mpAbc.thickness(), 1., 0.0001);
77  // A/Z should be 0.5 roughly for both
78  CHECK_CLOSE_REL(mpAbc.material().Z() / mpAbc.material().Ar(), 0.5, 0.0001);
79  // Thickness in X0 is additive
80  CHECK_CLOSE_REL(mpAbc.thicknessInX0(),
82  0.0001);
83  // Consistency check : X0
84  CHECK_CLOSE_REL(mpAbc.thickness() / mpAbc.material().X0(),
85  mpAbc.thicknessInX0(), 0.0001);
86  // Consistency check : L0
87  CHECK_CLOSE_REL(mpAbc.thicknessInL0(),
89  0.0001);
90  // The density scales with the thickness then
91  double rhoTmapped = mpAbc.material().massDensity() * mpAbc.thickness();
92  double rhoTadded = (a.thickness() * a.material().massDensity() +
93  b.thickness() * b.material().massDensity() +
94  c.thickness() * c.material().massDensity());
95  CHECK_CLOSE_REL(rhoTmapped, rhoTadded, 0.0001);
96 }
97 
99 BOOST_AUTO_TEST_CASE(AccumulatedMaterialProperties_totalaverage_test) {
100  MaterialProperties a(1., 2., 6., 3., 5., 1.);
101  MaterialProperties a3(1., 2., 6., 3., 5., 3.);
102 
103  MaterialProperties v(1.);
104 
105  // Test is the average of a and a is a
107  aa.accumulate(a);
108  aa.trackAverage();
109  aa.accumulate(a);
110  aa.trackAverage();
111  auto averageAA = aa.totalAverage();
112 
113  BOOST_CHECK_EQUAL(a, averageAA.first);
114  BOOST_CHECK_EQUAL(averageAA.second, 2u);
115 
116  // Test:
117  // that the average of a and a vacuum
118  // step of same length is half a
119  MaterialProperties halfA(a.material(), a.thickness() / 2);
121  av.accumulate(a);
122  av.trackAverage();
123  av.accumulate(v);
124  av.trackAverage();
125  auto averageAV = av.totalAverage();
126  auto matAV = averageAV.first;
127 
128  BOOST_CHECK_EQUAL(halfA.thicknessInX0(), matAV.thicknessInX0());
129  BOOST_CHECK_EQUAL(halfA.thicknessInL0(), matAV.thicknessInL0());
130  CHECK_CLOSE_REL(halfA.material().massDensity() * halfA.thickness(),
131  matAV.material().massDensity() * matAV.thickness(), 0.0001);
132  BOOST_CHECK_EQUAL(averageAV.second, 2u);
133 
134  // Test:
135  // average of a + 3*a -> 2*a
136  MaterialProperties doubleA(a.material(), 2 * a.thickness());
138  aa3.accumulate(a);
139  aa3.trackAverage();
140  aa3.accumulate(a3);
141  aa3.trackAverage();
142  auto averageAA3 = aa3.totalAverage();
143  auto matAA3 = averageAA3.first;
144 
145  BOOST_CHECK_EQUAL(doubleA.thicknessInX0(), matAA3.thicknessInX0());
146  BOOST_CHECK_EQUAL(doubleA.thicknessInL0(), matAA3.thicknessInL0());
147  CHECK_CLOSE_REL(doubleA.material().massDensity() * doubleA.thickness(),
148  matAA3.material().massDensity() * matAA3.thickness(), 0.0001);
149  BOOST_CHECK_EQUAL(averageAA3.second, 2u);
150 
154  aa3v.accumulate(a);
155  aa3v.trackAverage();
156  aa3v.accumulate(a3);
157  aa3v.trackAverage();
158  aa3v.accumulate(v);
159  aa3v.trackAverage();
160  auto averageAA3V = aa3v.totalAverage();
161  auto matAA3V = averageAA3V.first;
162 
163  CHECK_CLOSE_REL(4. / 3., matAA3V.thicknessInX0(), 0.00001);
164  BOOST_CHECK_EQUAL(averageAA3V.second, 3u);
165 
169  a4v.accumulate(a);
170  a4v.accumulate(a3);
171  a4v.trackAverage();
172  a4v.accumulate(v);
173  a4v.trackAverage();
174  auto averageA4V = a4v.totalAverage();
175  auto matA4V = averageA4V.first;
176 
177  CHECK_CLOSE_REL(doubleA.thicknessInX0(), matA4V.thicknessInX0(), 0.00001);
178  BOOST_CHECK_EQUAL(averageA4V.second, 2u);
179 
183  aa3e.accumulate(a);
184  aa3e.trackAverage();
185  aa3e.accumulate(a3);
186  aa3e.trackAverage();
187  aa3e.trackAverage(true);
188  auto averageAA3E = aa3e.totalAverage();
189  auto matAA3E = averageAA3E.first;
190 
191  CHECK_CLOSE_REL(4. / 3., matAA3E.thicknessInX0(), 0.00001);
192  BOOST_CHECK_EQUAL(averageAA3E.second, 3u);
193 }
194 
195 } // namespace Test
196 } // namespace Acts