Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialSlabTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialSlabTests.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 
14 
15 #include <limits>
16 #include <vector>
17 
18 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
19 
20 BOOST_AUTO_TEST_SUITE(material_properties)
21 
22 BOOST_AUTO_TEST_CASE(construct_simple) {
24  Acts::MaterialSlab fromMaterial(
25  Acts::Material::fromMolarDensity(1., 2., 3., 4., 5.), 6.);
26 
27  CHECK_CLOSE_REL(fromMaterial.thickness(), 6., eps);
28  CHECK_CLOSE_REL(fromMaterial.thicknessInX0(), 6., eps);
29  CHECK_CLOSE_REL(fromMaterial.thicknessInL0(), 3., eps);
30 }
31 
32 BOOST_AUTO_TEST_CASE(construct_compound) {
33  using Acts::Material;
34  using Acts::MaterialSlab;
35 
36  MaterialSlab a(Material::fromMolarDensity(1., 2., 3., 4., 5.), 1.);
37  MaterialSlab b(Material::fromMolarDensity(2., 4., 6., 8., 10.), 2.);
38  MaterialSlab c(Material::fromMolarDensity(4., 8., 12., 16., 20.), 3.);
39  std::vector<MaterialSlab> components = {a, b, c};
40  MaterialSlab abc(components);
41 
42  // consistency checks
43  CHECK_CLOSE_REL(abc.thickness() / abc.material().X0(), abc.thicknessInX0(),
44  eps);
45  CHECK_CLOSE_REL(abc.thickness() / abc.material().L0(), abc.thicknessInL0(),
46  eps);
47 
48  // absolute and relative thicknesses are additive
49  CHECK_CLOSE_REL(abc.thickness(),
50  a.thickness() + b.thickness() + c.thickness(), eps);
51  CHECK_CLOSE_REL(abc.thicknessInX0(),
52  a.thicknessInX0() + b.thicknessInX0() + c.thicknessInX0(),
53  eps);
54  CHECK_CLOSE_REL(abc.thicknessInL0(),
55  a.thicknessInL0() + b.thicknessInL0() + c.thicknessInL0(),
56  eps);
57  // The density scales with the thickness
58  CHECK_CLOSE_REL(abc.material().massDensity(),
59  (a.thickness() * a.material().massDensity() +
60  b.thickness() * b.material().massDensity() +
61  c.thickness() * c.material().massDensity()) /
62  (a.thickness() + b.thickness() + c.thickness()),
63  eps);
64 }
65 
66 BOOST_AUTO_TEST_CASE(scale_thickness) {
67  const auto material = Acts::Material::fromMassDensity(1., 2., 3., 4., 5.);
68  const Acts::MaterialSlab mat(material, 0.1);
69  const Acts::MaterialSlab halfMat(material, 0.05);
70  Acts::MaterialSlab halfScaled = mat;
71  halfScaled.scaleThickness(0.5);
72 
73  BOOST_CHECK_NE(mat, halfMat);
74  BOOST_CHECK_EQUAL(halfMat, halfScaled);
75  CHECK_CLOSE_REL(mat.thicknessInX0(), 2 * halfMat.thicknessInX0(), eps);
76  CHECK_CLOSE_REL(mat.thicknessInL0(), 2 * halfMat.thicknessInL0(), eps);
78  2. * halfMat.thickness() * halfMat.material().massDensity(),
79  eps);
80 }
81 
82 BOOST_AUTO_TEST_SUITE_END()