EIC 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 
13 
14 #include <limits>
15 #include <vector>
16 
17 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
18 
19 BOOST_AUTO_TEST_SUITE(material_properties)
20 
21 BOOST_AUTO_TEST_CASE(construct_simple) {
23  Acts::MaterialSlab fromMaterial(
24  Acts::Material::fromMolarDensity(1., 2., 3., 4., 5.), 6.);
25 
26  CHECK_CLOSE_REL(fromMaterial.thickness(), 6., eps);
27  CHECK_CLOSE_REL(fromMaterial.thicknessInX0(), 6., eps);
28  CHECK_CLOSE_REL(fromMaterial.thicknessInL0(), 3., eps);
29 }
30 
31 BOOST_AUTO_TEST_CASE(construct_compound) {
32  using Acts::Material;
33  using Acts::MaterialSlab;
34 
35  MaterialSlab a(Material::fromMolarDensity(1., 2., 3., 4., 5.), 1.);
36  MaterialSlab b(Material::fromMolarDensity(2., 4., 6., 8., 10.), 2.);
37  MaterialSlab c(Material::fromMolarDensity(4., 8., 12., 16., 20.), 3.);
38  std::vector<MaterialSlab> components = {a, b, c};
39  MaterialSlab abc(components);
40 
41  // consistency checks
42  CHECK_CLOSE_REL(abc.thickness() / abc.material().X0(), abc.thicknessInX0(),
43  eps);
44  CHECK_CLOSE_REL(abc.thickness() / abc.material().L0(), abc.thicknessInL0(),
45  eps);
46 
47  // absolute and relative thicknesses are additive
48  CHECK_CLOSE_REL(abc.thickness(),
49  a.thickness() + b.thickness() + c.thickness(), eps);
50  CHECK_CLOSE_REL(abc.thicknessInX0(),
51  a.thicknessInX0() + b.thicknessInX0() + c.thicknessInX0(),
52  eps);
53  CHECK_CLOSE_REL(abc.thicknessInL0(),
54  a.thicknessInL0() + b.thicknessInL0() + c.thicknessInL0(),
55  eps);
56  // The density scales with the thickness
57  CHECK_CLOSE_REL(abc.material().massDensity(),
58  (a.thickness() * a.material().massDensity() +
59  b.thickness() * b.material().massDensity() +
60  c.thickness() * c.material().massDensity()) /
61  (a.thickness() + b.thickness() + c.thickness()),
62  eps);
63 }
64 
65 BOOST_AUTO_TEST_CASE(scale_thickness) {
66  const auto material = Acts::Material::fromMassDensity(1., 2., 3., 4., 5.);
67  const Acts::MaterialSlab mat(material, 0.1);
68  const Acts::MaterialSlab halfMat(material, 0.05);
69  Acts::MaterialSlab halfScaled = mat;
70  halfScaled.scaleThickness(0.5);
71 
72  BOOST_CHECK_NE(mat, halfMat);
73  BOOST_CHECK_EQUAL(halfMat, halfScaled);
74  CHECK_CLOSE_REL(mat.thicknessInX0(), 2 * halfMat.thicknessInX0(), eps);
75  CHECK_CLOSE_REL(mat.thicknessInL0(), 2 * halfMat.thicknessInL0(), eps);
77  2. * halfMat.thickness() * halfMat.material().massDensity(),
78  eps);
79 }
80 
81 BOOST_AUTO_TEST_SUITE_END()