Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialTests.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/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
11 
16 
17 #include <limits>
18 
19 namespace bdata = boost::unit_test::data;
20 
21 using namespace Acts::UnitLiterals;
22 
23 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
24 // manually calculated derived values for silicon
25 static constexpr float SiNe = 1.160954941_mol / 1_cm3;
26 static constexpr float SiI = 172.042290036_eV;
27 
28 BOOST_AUTO_TEST_SUITE(Material)
29 
30 BOOST_AUTO_TEST_CASE(ConstructVacuum) {
31  // default constructor builds invalid material a.k.a. vacuum
32  Acts::Material vacuum;
33  BOOST_CHECK(!vacuum);
34 }
35 
36 BOOST_AUTO_TEST_CASE(ConstructSomething) {
37  // anything with non-zero Ar is a valid material
38  auto notVacuum = Acts::Material::fromMolarDensity(1, 2, 3, 4, 5);
39  BOOST_CHECK(!!notVacuum);
40 }
41 
44 
45  // check values w/ different units if possible
46  CHECK_CLOSE_REL(silicon.X0(), 93.70_mm, eps);
47  CHECK_CLOSE_REL(silicon.X0(), 9.370_cm, eps);
48  CHECK_CLOSE_REL(silicon.X0(), 0.09370_m, eps);
49  CHECK_CLOSE_REL(silicon.L0(), 465.2_mm, eps);
50  CHECK_CLOSE_REL(silicon.L0(), 46.52_cm, eps);
51  CHECK_CLOSE_REL(silicon.L0(), 0.4652_m, eps);
52  CHECK_CLOSE_REL(silicon.Ar(), 28.0855, eps);
53  CHECK_CLOSE_REL(silicon.Z(), 14.0, eps);
54  CHECK_CLOSE_REL(silicon.molarDensity(), 0.08292535294012926_mol / 1_cm3, eps);
55  CHECK_CLOSE_REL(silicon.molarDensity(), 82925.35294012926_mol / 1_m3, eps);
56  // check derived values
57  CHECK_CLOSE_REL(silicon.massDensity(), 2.329_g / 1_cm3, eps);
58  CHECK_CLOSE_REL(silicon.massDensity(), 0.002329_kg / 1_cm3, eps);
59  CHECK_CLOSE_REL(silicon.massDensity(), 0.002329_g / 1_mm3, eps);
61  silicon.Z() * silicon.molarDensity(), eps);
64 }
65 
66 BOOST_DATA_TEST_CASE(EncodingDecodingRoundtrip,
67  bdata::make({
69  Acts::Material::fromMolarDensity(1, 2, 3, 4, 5),
72  }),
73  material) {
74  // encode material
76  // construct from encoded numbers
77  Acts::Material fromNumbers(numbers0);
78  // encode material again
79  Acts::Material::ParametersVector numbers1 = fromNumbers.parameters();
80 
81  BOOST_CHECK_EQUAL(material, fromNumbers);
82  BOOST_CHECK_EQUAL(numbers0, numbers1);
83 }
84 
85 BOOST_AUTO_TEST_SUITE_END()