ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialPropertiesTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialPropertiesTests.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 
11 #include <limits>
12 #include <vector>
13 
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) {
22  // construct from separate arguments
23  Acts::MaterialProperties fromArgs(1., 2., 3., 4., 5., 6.);
25  Acts::MaterialProperties fromMaterial(Acts::Material(1., 2., 3., 4., 5.), 6.);
26 
27  CHECK_CLOSE_REL(fromArgs.thickness(), 6., eps);
28  CHECK_CLOSE_REL(fromArgs.thicknessInX0(), 6., eps);
29  CHECK_CLOSE_REL(fromArgs.thicknessInL0(), 3., eps);
30  CHECK_CLOSE_REL(fromMaterial.thickness(), 6., eps);
31  CHECK_CLOSE_REL(fromMaterial.thicknessInX0(), 6., eps);
32  CHECK_CLOSE_REL(fromMaterial.thicknessInL0(), 3., eps);
33  BOOST_TEST(fromArgs.material() == fromMaterial.material());
34  BOOST_TEST(fromArgs == fromMaterial);
35 }
36 
37 static const Acts::MaterialProperties a(1., 2., 3., 4., 5., 1.);
38 static const Acts::MaterialProperties b(2., 4., 6., 8., 10., 2.);
39 static const Acts::MaterialProperties c(4., 8., 12., 16., 20., 3.);
40 static const std::vector<Acts::MaterialProperties> components = {a, b, c};
41 
42 BOOST_AUTO_TEST_CASE(construct_compound) {
43  Acts::MaterialProperties abc(components);
44 
45  // consistency checks
46  CHECK_CLOSE_REL(abc.thickness() / abc.material().X0(), abc.thicknessInX0(),
47  eps);
48  CHECK_CLOSE_REL(abc.thickness() / abc.material().L0(), abc.thicknessInL0(),
49  eps);
50 
51  // absolute and relative thicknesses are additive
53  a.thickness() + b.thickness() + c.thickness(), eps);
56  eps);
59  eps);
60  // The density scales with the thickness
62  (a.thickness() * a.material().massDensity() +
63  b.thickness() * b.material().massDensity() +
64  c.thickness() * c.material().massDensity()) /
65  (a.thickness() + b.thickness() + c.thickness()),
66  eps);
67 }
68 
69 BOOST_AUTO_TEST_CASE(scale_thickness) {
70  Acts::MaterialProperties mat(1., 2., 3., 4., 5., 0.1);
71  Acts::MaterialProperties halfMat(1., 2., 3., 4., 5., 0.05);
72  Acts::MaterialProperties halfScaled = mat;
73  halfScaled.scaleThickness(0.5);
74 
75  BOOST_TEST(mat != halfMat);
76  BOOST_TEST(halfMat == halfScaled);
77  CHECK_CLOSE_REL(mat.thicknessInX0(), 2 * halfMat.thicknessInX0(), eps);
78  CHECK_CLOSE_REL(mat.thicknessInL0(), 2 * halfMat.thicknessInL0(), eps);
80  2. * halfMat.thickness() * halfMat.material().massDensity(),
81  eps);
82 }
83 
84 BOOST_AUTO_TEST_SUITE_END()