EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AccumulatedVolumeMaterialTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AccumulatedVolumeMaterialTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 namespace Acts {
16 namespace Test {
17 
18 BOOST_AUTO_TEST_SUITE(accumulated_material)
19 
22 
23  // averaging over nothing is vacuum
24  BOOST_CHECK(not avm.average());
25 
26  // averaging over vacuum is still vacuum
27  avm.accumulate(MaterialSlab(1));
28  BOOST_CHECK(not avm.average());
29 }
30 
31 BOOST_AUTO_TEST_CASE(single_material) {
32  Material mat = Material::fromMolarDensity(1., 2., 3., 4., 5.);
33  MaterialSlab matprop(mat, 1);
35  // mean of a single material should be the same material again for a thickness
36  // of 1
37  avm.accumulate(matprop);
38  {
39  auto result = avm.average();
40  CHECK_CLOSE_REL(result.parameters(), mat.parameters(), 1e-4);
41  CHECK_CLOSE_REL(result.L0(), mat.L0(), 1e-4);
42  CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
43  CHECK_CLOSE_REL(result.Z(), mat.Z(), 1e-4);
44  CHECK_CLOSE_REL(result.molarDensity(), mat.molarDensity(), 1e-4);
45  CHECK_CLOSE_REL(result.massDensity(), mat.massDensity(), 1e-4);
46  }
47  // adding a vacuum step changes the average
48  avm.accumulate(MaterialSlab(1));
49  {
50  auto result = avm.average();
51  // less scattering in vacuum, larger radiation length
52  CHECK_CLOSE_REL(result.X0(), 2 * mat.X0(), 1e-4);
53  CHECK_CLOSE_REL(result.L0(), 2 * mat.L0(), 1e-4);
54  // less material, lower density
55  CHECK_CLOSE_REL(result.molarDensity(), 0.5 * mat.molarDensity(), 1e-4);
56  CHECK_CLOSE_REL(result.massDensity(), 0.5 * mat.massDensity(), 1e-4);
57  // but atom species stays the same
58  CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
59  CHECK_CLOSE_REL(result.Z(), mat.Z(), 1e-4);
60  }
61 }
62 
63 BOOST_AUTO_TEST_CASE(two_materials) {
64  Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
65  Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
66 
67  MaterialSlab matprop1(mat1, 1);
68  MaterialSlab matprop2(mat2, 1);
69 
71  avm.accumulate(matprop1);
72  avm.accumulate(matprop2);
73  auto result = avm.average();
74  CHECK_CLOSE_REL(result.X0(), 2. / (1. / 1. + 1. / 6.), 1e-4);
75  CHECK_CLOSE_REL(result.L0(), 2. / (1. / 2. + 1. / 7.), 1e-4);
76  CHECK_CLOSE_REL(result.Ar(), (5 * 3. + 10 * 8.) / (5 + 10), 1e-4);
77  CHECK_CLOSE_REL(result.Z(), (5 * 4. + 10 * 9.) / (5 + 10), 1e-4);
78  CHECK_CLOSE_REL(result.molarDensity(), 0.5 * (5. + 10.), 1e-4);
79 }
80 
81 BOOST_AUTO_TEST_CASE(two_materials_different_lengh) {
82  Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
83  Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
84 
85  MaterialSlab matprop1(mat1, 0.5);
86  MaterialSlab matprop2(mat2, 2);
87 
89  avm.accumulate(matprop1);
90  avm.accumulate(matprop2);
91  auto result = avm.average();
92  CHECK_CLOSE_REL(result.X0(), 2.5 / (0.5 / 1. + 2. / 6.), 1e-4);
93  CHECK_CLOSE_REL(result.L0(), 2.5 / (0.5 / 2. + 2. / 7.), 1e-4);
94  CHECK_CLOSE_REL(result.Ar(),
95  (0.5 * 5 * 3. + 2 * 10 * 8.) / (0.5 * 5 + 2 * 10), 1e-4);
96  CHECK_CLOSE_REL(result.Z(), (0.5 * 5 * 4. + 2 * 10 * 9.) / (0.5 * 5 + 2 * 10),
97  1e-4);
98  CHECK_CLOSE_REL(result.molarDensity(), (0.5 * 5. + 2 * 10.) / (0.5 + 2),
99  1e-4);
100 }
101 
102 BOOST_AUTO_TEST_SUITE_END()
103 
104 } // namespace Test
105 } // namespace Acts