Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HomogeneousSurfaceMaterialTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HomogeneousSurfaceMaterialTests.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 <utility>
20 
21 namespace Acts {
22 
23 namespace Test {
24 
26 BOOST_AUTO_TEST_CASE(HomogeneousSurfaceMaterial_construction_test) {
27  // construct the material properties from arguments
28  Material mat = Material::fromMolarDensity(1., 2., 3., 4., 5.);
29  MaterialSlab mp(mat, 0.1);
30 
31  // Constructor from arguments
32  HomogeneousSurfaceMaterial hsm(mp, 1.);
33  // Copy constructor
34  HomogeneousSurfaceMaterial hsmCopy(hsm);
35  // Test equality of the copy
36  BOOST_CHECK_EQUAL(hsm, hsmCopy);
37  // Copy move constructor
38  HomogeneousSurfaceMaterial hsmCopyMoved(std::move(hsmCopy));
39  // Test equality of the copy
40  BOOST_CHECK_EQUAL(hsm, hsmCopyMoved);
41  // Assignment constructor
42  HomogeneousSurfaceMaterial hsmAssigned = hsm;
43  // Test equality of the assignment
44  BOOST_CHECK_EQUAL(hsm, hsmAssigned);
45  // Assignment move constructor
46  HomogeneousSurfaceMaterial hsmAssignedMoved(std::move(hsmAssigned));
47  // Test equality of the copy
48  BOOST_CHECK_EQUAL(hsm, hsmAssignedMoved);
49 }
50 
51 // Test the Scaling
52 BOOST_AUTO_TEST_CASE(HomogeneousSurfaceMaterial_scaling_test) {
53  MaterialSlab mat(Material::fromMolarDensity(1., 2., 3., 4., 5.), 0.1);
54  MaterialSlab matHalf = mat;
55  matHalf.scaleThickness(0.5);
56 
57  HomogeneousSurfaceMaterial hsm(mat, 1.);
58  hsm *= 0.5;
59 
60  auto matBin = hsm.materialSlab(0, 0);
61 
62  BOOST_CHECK_EQUAL(matBin, matHalf);
63  BOOST_CHECK_NE(matBin, mat);
64 }
65 
66 // Test the Access
67 BOOST_AUTO_TEST_CASE(HomogeneousSurfaceMaterial_access_test) {
68  // construct the material properties from arguments
69  MaterialSlab mat(Material::fromMolarDensity(1., 2., 3., 4., 5.), 0.1);
70  MaterialSlab matHalf = mat;
71  matHalf.scaleThickness(0.5);
72 
73  MaterialSlab vacuum = MaterialSlab();
74 
75  // Constructor from arguments
76  HomogeneousSurfaceMaterial hsmfwd(mat, 1.);
77  HomogeneousSurfaceMaterial hsmhalf(mat, 0.5);
78  HomogeneousSurfaceMaterial hsmbwd(mat, 0.);
79 
80  auto mat2d = hsmfwd.materialSlab(Vector2{0., 0.});
81  auto mat3d = hsmfwd.materialSlab(Vector3{0., 0., 0.});
82  auto matbin = hsmfwd.materialSlab(0, 0);
83 
84  // Test equality of the copy
85  BOOST_CHECK_EQUAL(mat, mat2d);
86  BOOST_CHECK_EQUAL(mat, mat3d);
87  BOOST_CHECK_EQUAL(mat, matbin);
88 
91 
92  MaterialUpdateStage pre = MaterialUpdateStage::PreUpdate;
93  MaterialUpdateStage full = MaterialUpdateStage::FullUpdate;
94  MaterialUpdateStage post = MaterialUpdateStage::PostUpdate;
95 
96  // (a) Forward factor material test
97  BOOST_CHECK_EQUAL(hsmfwd.factor(fDir, full), 1.);
98  BOOST_CHECK_EQUAL(hsmfwd.factor(fDir, pre), 0.);
99  BOOST_CHECK_EQUAL(hsmfwd.factor(fDir, post), 1.);
100 
101  BOOST_CHECK_EQUAL(hsmfwd.factor(bDir, full), 1.);
102  BOOST_CHECK_EQUAL(hsmfwd.factor(bDir, pre), 1.);
103  BOOST_CHECK_EQUAL(hsmfwd.factor(bDir, post), 0.);
104 
105  auto matFwdFull = hsmfwd.materialSlab(Vector3{0., 0., 0.}, fDir, full);
106  auto matBwdFull = hsmfwd.materialSlab(Vector3{0., 0., 0.}, bDir, full);
107 
108  auto matFwdPost = hsmfwd.materialSlab(Vector3{0., 0., 0.}, fDir, post);
109  auto matBwdPost = hsmfwd.materialSlab(Vector3{0., 0., 0.}, bDir, post);
110 
111  auto matFwdPre = hsmfwd.materialSlab(Vector3{0., 0., 0.}, fDir, pre);
112  auto matBwdPre = hsmfwd.materialSlab(Vector3{0., 0., 0.}, bDir, pre);
113 
114  BOOST_CHECK_EQUAL(mat, matFwdFull);
115  BOOST_CHECK_EQUAL(mat, matBwdFull);
116 
117  BOOST_CHECK_EQUAL(mat, matFwdPost);
118  BOOST_CHECK_EQUAL(vacuum, matBwdPost);
119 
120  BOOST_CHECK_EQUAL(vacuum, matFwdPre);
121  BOOST_CHECK_EQUAL(mat, matBwdPre);
122 
123  // (b) Split factor material test
124  BOOST_CHECK_EQUAL(hsmhalf.factor(fDir, full), 1.);
125  CHECK_CLOSE_REL(hsmhalf.factor(fDir, pre), 0.5, 1e-6);
126  CHECK_CLOSE_REL(hsmhalf.factor(fDir, post), 0.5, 1e-6);
127 
128  BOOST_CHECK_EQUAL(hsmhalf.factor(bDir, full), 1.);
129  CHECK_CLOSE_REL(hsmhalf.factor(bDir, pre), 0.5, 1e-6);
130  CHECK_CLOSE_REL(hsmhalf.factor(bDir, post), 0.5, 1e-6);
131 
132  matFwdFull = hsmhalf.materialSlab(Vector3{0., 0., 0.}, fDir, full);
133  matBwdFull = hsmhalf.materialSlab(Vector3{0., 0., 0.}, bDir, full);
134 
135  matFwdPost = hsmhalf.materialSlab(Vector3{0., 0., 0.}, fDir, post);
136  matBwdPost = hsmhalf.materialSlab(Vector3{0., 0., 0.}, bDir, post);
137 
138  matFwdPre = hsmhalf.materialSlab(Vector3{0., 0., 0.}, fDir, pre);
139  matBwdPre = hsmhalf.materialSlab(Vector3{0., 0., 0.}, bDir, pre);
140 
141  BOOST_CHECK_EQUAL(mat, matFwdFull);
142  BOOST_CHECK_EQUAL(mat, matBwdFull);
143 
144  BOOST_CHECK_EQUAL(matHalf, matFwdPost);
145  BOOST_CHECK_EQUAL(matHalf, matBwdPost);
146 
147  BOOST_CHECK_EQUAL(matHalf, matFwdPre);
148  BOOST_CHECK_EQUAL(matHalf, matBwdPre);
149 
150  // c) Forward factor material test
151  BOOST_CHECK_EQUAL(hsmbwd.factor(fDir, full), 1.);
152  BOOST_CHECK_EQUAL(hsmbwd.factor(fDir, pre), 1.);
153  BOOST_CHECK_EQUAL(hsmbwd.factor(fDir, post), 0.);
154 
155  BOOST_CHECK_EQUAL(hsmbwd.factor(bDir, full), 1.);
156  BOOST_CHECK_EQUAL(hsmbwd.factor(bDir, pre), 0.);
157  BOOST_CHECK_EQUAL(hsmbwd.factor(bDir, post), 1.);
158 
159  matFwdFull = hsmbwd.materialSlab(Vector3{0., 0., 0.}, fDir, full);
160  matBwdFull = hsmbwd.materialSlab(Vector3{0., 0., 0.}, bDir, full);
161 
162  matFwdPost = hsmbwd.materialSlab(Vector3{0., 0., 0.}, fDir, post);
163  matBwdPost = hsmbwd.materialSlab(Vector3{0., 0., 0.}, bDir, post);
164 
165  matFwdPre = hsmbwd.materialSlab(Vector3{0., 0., 0.}, fDir, pre);
166  matBwdPre = hsmbwd.materialSlab(Vector3{0., 0., 0.}, bDir, pre);
167 
168  BOOST_CHECK_EQUAL(mat, matFwdFull);
169  BOOST_CHECK_EQUAL(mat, matBwdFull);
170 
171  BOOST_CHECK_EQUAL(vacuum, matFwdPost);
172  BOOST_CHECK_EQUAL(mat, matBwdPost);
173 
174  BOOST_CHECK_EQUAL(mat, matFwdPre);
175  BOOST_CHECK_EQUAL(vacuum, matBwdPre);
176 }
177 } // namespace Test
178 } // namespace Acts