Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AccumulatedSurfaceMaterialTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AccumulatedSurfaceMaterialTests.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 
18 
19 #include <array>
20 #include <cstddef>
21 #include <memory>
22 #include <vector>
23 
24 namespace Acts {
25 namespace Test {
26 
28 BOOST_AUTO_TEST_CASE(AccumulatedSurfaceMaterial_construction_test) {
29  // Test:
30  // HomogeneousSurfaceMaterial accumulation
31  AccumulatedSurfaceMaterial material0D{};
32  auto accMat0D = material0D.accumulatedMaterial();
33  BOOST_CHECK_EQUAL(accMat0D.size(), 1u);
34  BOOST_CHECK_EQUAL(accMat0D[0].size(), 1u);
35  BOOST_CHECK_EQUAL(material0D.splitFactor(), 0.);
36 
37  // Test:
38  // BinsSurfaceMaterial accumulation - 1D
39  BinUtility binUtility1D(10, -5., 5., open, binX);
40  AccumulatedSurfaceMaterial material1D{binUtility1D};
41  auto accMat1D = material1D.accumulatedMaterial();
42  BOOST_CHECK_EQUAL(accMat1D.size(), 1u);
43  BOOST_CHECK_EQUAL(accMat1D[0].size(), 10u);
44 
45  // Test:
46  // BinsSurfaceMaterial accumulation - 2D
47  BinUtility binUtility2D(10, -5., 5., open, binX);
48  binUtility2D += BinUtility(20, -10., 10., open, binY);
49  AccumulatedSurfaceMaterial material2D{binUtility2D};
50  auto accMat2D = material2D.accumulatedMaterial();
51  BOOST_CHECK_EQUAL(accMat2D.size(), 20u);
52  for (size_t ib = 0; ib < accMat2D.size(); ++ib) {
53  BOOST_CHECK_EQUAL(accMat2D[ib].size(), 10u);
54  }
55 }
56 
58 BOOST_AUTO_TEST_CASE(AccumulatedSurfaceMaterial_fill_convert_0D) {
59  Material mat = Material::fromMolarDensity(1., 1., 1., 1., 1.);
60  MaterialSlab one(mat, 1.);
61  MaterialSlab two(mat, 2.);
62 
63  AccumulatedSurfaceMaterial material0D{};
64  const std::vector<std::array<size_t, 3>> bin;
65  // assign 2 one steps
66  material0D.accumulate(Vector2{0., 0.}, one);
67  material0D.accumulate(Vector2{0., 0.}, one);
68  material0D.trackVariance(bin, one);
69  material0D.trackAverage();
70  // assign 1 double step
71  material0D.accumulate(Vector3(0., 0., 0.), two);
72  material0D.trackVariance(bin, one);
73  material0D.trackAverage();
74  // get the single matrix
75  auto accMat0D = material0D.accumulatedMaterial();
76  auto accMatProp0D = accMat0D[0][0];
77  auto [matProp0D, trackCount] = accMatProp0D.totalAverage();
78  auto [matVar0D, trackCount2] = accMatProp0D.totalVariance();
79 
80  BOOST_CHECK_EQUAL(matVar0D, 0.0);
81  BOOST_CHECK_EQUAL(matProp0D.thicknessInX0(), two.thicknessInX0());
82  BOOST_CHECK_EQUAL(trackCount, trackCount2);
83  BOOST_CHECK_EQUAL(trackCount, 2u);
84 }
85 
87 BOOST_AUTO_TEST_CASE(AccumulatedSurfaceMaterial_fill_convert_1D) {
88  Material mat = Material::fromMolarDensity(1., 1., 1., 1., 1.);
89  MaterialSlab one(mat, 1.);
90  MaterialSlab two(mat, 2.);
91  MaterialSlab three(mat, 3.);
92  MaterialSlab four(mat, 4.);
93 
94  // BinsSurfaceMaterial accumulation - 2D
95  BinUtility binUtility2D(2, -1., 1., open, binX);
96  binUtility2D += BinUtility(2, -1., 1., open, binY);
97  AccumulatedSurfaceMaterial material2D{binUtility2D};
98  const std::vector<std::array<size_t, 3>> bin;
99 
100  // assign in the different bins
101  // event 0
102  material2D.accumulate(Vector2{-0.5, -0.5}, one);
103  material2D.accumulate(Vector2{0.5, -0.5}, two);
104  material2D.accumulate(Vector2{-0.5, 0.5}, three);
105  material2D.accumulate(Vector2{0.5, 0.5}, four);
106  material2D.trackVariance(bin, one);
107  material2D.trackAverage();
108  // event 1
109  material2D.accumulate(Vector2{0.5, -0.5}, two);
110  material2D.accumulate(Vector2{-0.5, 0.5}, three);
111  material2D.accumulate(Vector2{0.5, 0.5}, four);
112  material2D.trackVariance(bin, one);
113  material2D.trackAverage();
114  // event 2
115  material2D.accumulate(Vector2{-0.5, 0.5}, three);
116  material2D.accumulate(Vector2{0.5, 0.5}, four);
117  material2D.trackVariance(bin, one);
118  material2D.trackAverage();
119  // event 2
120  material2D.accumulate(Vector2{0.5, 0.5}, four);
121  material2D.trackVariance(bin, one);
122  material2D.trackAverage();
123  // get the single matrix
124  auto accMat2D = material2D.accumulatedMaterial();
125  // the accumulated properties
126  auto [accMatProp00, trackCount00] = accMat2D[0][0].totalAverage();
127  auto [accMatProp01, trackCount01] = accMat2D[0][1].totalAverage();
128  auto [accMatProp10, trackCount10] = accMat2D[1][0].totalAverage();
129  auto [accMatProp11, trackCount11] = accMat2D[1][1].totalAverage();
130 
131  auto [matVar00, trackCount200] = accMat2D[0][0].totalVariance();
132  auto [matVar01, trackCount201] = accMat2D[0][1].totalVariance();
133  auto [matVar10, trackCount210] = accMat2D[1][0].totalVariance();
134  auto [matVar11, trackCount211] = accMat2D[1][1].totalVariance();
135 
136  BOOST_CHECK_EQUAL(accMatProp00.thicknessInX0(), one.thicknessInX0());
137  BOOST_CHECK_EQUAL(accMatProp01.thicknessInX0(), two.thicknessInX0());
138  BOOST_CHECK_EQUAL(accMatProp10.thicknessInX0(), three.thicknessInX0());
139  BOOST_CHECK_EQUAL(accMatProp11.thicknessInX0(), four.thicknessInX0());
140 
141  BOOST_CHECK_EQUAL(matVar11, 0.0);
142  BOOST_CHECK_EQUAL(matVar11, 0.0);
143  BOOST_CHECK_EQUAL(matVar11, 0.0);
144  BOOST_CHECK_EQUAL(matVar11, 0.0);
145 
146  BOOST_CHECK_EQUAL(trackCount00, trackCount200);
147  BOOST_CHECK_EQUAL(trackCount01, trackCount201);
148  BOOST_CHECK_EQUAL(trackCount10, trackCount210);
149  BOOST_CHECK_EQUAL(trackCount11, trackCount211);
150 
151  BOOST_CHECK_EQUAL(trackCount00, 1u);
152  BOOST_CHECK_EQUAL(trackCount01, 2u);
153  BOOST_CHECK_EQUAL(trackCount10, 3u);
154  BOOST_CHECK_EQUAL(trackCount11, 4u);
155 }
156 
158 BOOST_AUTO_TEST_CASE(AccumulatedSurfaceMaterial_variance_0D) {
159  Material mat1 = Material::fromMolarDensity(1.0 / 3, 1., 1., 1., 1.);
160  Material mat2 = Material::fromMolarDensity(1, 1., 1., 1., 1.);
161  Material matAvg = Material::fromMolarDensity(0.5, 1., 1., 1., 1.);
162 
163  MaterialSlab one(mat1, 1.);
164  MaterialSlab two(mat2, 1.);
165  MaterialSlab avg(matAvg, 1.);
166 
167  AccumulatedSurfaceMaterial material0D{};
168  const std::vector<std::array<size_t, 3>> bin;
169  // assign 2 one steps
170  material0D.accumulate(Vector2{0., 0.}, one);
171  material0D.trackVariance(bin, avg);
172  material0D.trackAverage();
173  // assign 1 double step
174  material0D.accumulate(Vector3(0., 0., 0.), two);
175  material0D.trackVariance(bin, avg);
176  material0D.trackAverage();
177  // get the single matrix
178  auto accMat0D = material0D.accumulatedMaterial();
179  auto accMatProp0D = accMat0D[0][0];
180  auto [matProp0D, trackCount] = accMatProp0D.totalAverage();
181  auto [matVar0D, trackCount2] = accMatProp0D.totalVariance();
182 
183  BOOST_CHECK_EQUAL(matVar0D, 1.0);
184  BOOST_CHECK_EQUAL(matProp0D.thicknessInX0(), avg.thicknessInX0());
185  BOOST_CHECK_EQUAL(trackCount, trackCount2);
186  BOOST_CHECK_EQUAL(trackCount, 2u);
187 }
188 
189 } // namespace Test
190 } // namespace Acts