Analysis Software
Documentation for sPHENIX simulation 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 
15 
16 #include <cmath>
17 
18 namespace Acts {
19 namespace Test {
20 
21 BOOST_AUTO_TEST_SUITE(accumulated_material)
22 
25 
26  // averaging over nothing is vacuum
27  BOOST_CHECK(not avm.average());
28 
29  // averaging over vacuum is still vacuum
30  avm.accumulate(MaterialSlab(1));
31  BOOST_CHECK(not avm.average());
32 }
33 
34 BOOST_AUTO_TEST_CASE(single_material) {
35  Material mat = Material::fromMolarDensity(1., 2., 3., 4., 5.);
36  MaterialSlab matprop(mat, 1);
38  // mean of a single material should be the same material again for a thickness
39  // of 1
40  avm.accumulate(matprop);
41  {
42  auto result = avm.average();
43  CHECK_CLOSE_REL(result.parameters(), mat.parameters(), 1e-4);
44  CHECK_CLOSE_REL(result.L0(), mat.L0(), 1e-4);
45  CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
46  CHECK_CLOSE_REL(result.Z(), mat.Z(), 1e-4);
47  CHECK_CLOSE_REL(result.molarDensity(), mat.molarDensity(), 1e-4);
48  CHECK_CLOSE_REL(result.massDensity(), mat.massDensity(), 1e-4);
49  }
50  // adding a vacuum step changes the average
51  avm.accumulate(MaterialSlab(1));
52  {
53  auto result = avm.average();
54  // less scattering in vacuum, larger radiation length
55  CHECK_CLOSE_REL(result.X0(), 2 * mat.X0(), 1e-4);
56  CHECK_CLOSE_REL(result.L0(), 2 * mat.L0(), 1e-4);
57  // less material, lower density
58  CHECK_CLOSE_REL(result.molarDensity(), 0.5 * mat.molarDensity(), 1e-4);
59  CHECK_CLOSE_REL(result.massDensity(), 0.5 * mat.massDensity(), 1e-4);
60  // but atom species stays the same
61  CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
62  CHECK_CLOSE_REL(result.Z(), 0.5 * mat.Z(), 1e-4);
63  }
64 }
65 
66 BOOST_AUTO_TEST_CASE(two_materials) {
67  Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
68  Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
69 
70  MaterialSlab matprop1(mat1, 1);
71  MaterialSlab matprop2(mat2, 1);
72 
74  avm.accumulate(matprop1);
75  avm.accumulate(matprop2);
76  auto result = avm.average();
77  CHECK_CLOSE_REL(result.X0(), 2. / (1. / 1. + 1. / 6.), 1e-4);
78  CHECK_CLOSE_REL(result.L0(), 2. / (1. / 2. + 1. / 7.), 1e-4);
79  CHECK_CLOSE_REL(result.Ar(), (5 * 3. + 10 * 8.) / (5 + 10), 1e-4);
80  CHECK_CLOSE_REL(result.Z(), exp((1. / 2.) * log(4.) + (1. / 2.) * log(9.)),
81  1e-4);
82  CHECK_CLOSE_REL(result.molarDensity(), 0.5 * (5. + 10.), 1e-4);
83 }
84 
85 BOOST_AUTO_TEST_CASE(two_materials_different_lengh) {
86  Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
87  Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
88 
89  MaterialSlab matprop1(mat1, 0.5);
90  MaterialSlab matprop2(mat2, 2);
91 
93  avm.accumulate(matprop1);
94  avm.accumulate(matprop2);
95  auto result = avm.average();
96  CHECK_CLOSE_REL(result.X0(), 2.5 / (0.5 / 1. + 2. / 6.), 1e-4);
97  CHECK_CLOSE_REL(result.L0(), 2.5 / (0.5 / 2. + 2. / 7.), 1e-4);
98  CHECK_CLOSE_REL(result.Ar(),
99  (0.5 * 5 * 3. + 2 * 10 * 8.) / (0.5 * 5 + 2 * 10), 1e-4);
101  result.Z(),
102  exp((0.5 / (0.5 + 2.)) * log(4.) + (2. / (0.5 + 2.)) * log(9.)), 1e-4);
103  CHECK_CLOSE_REL(result.molarDensity(), (0.5 * 5. + 2 * 10.) / (0.5 + 2),
104  1e-4);
105 }
106 
107 BOOST_AUTO_TEST_SUITE_END()
108 
109 } // namespace Test
110 } // namespace Acts