Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-19 07:59:03

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Material/Material.hpp"
0014 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0015 #include "ActsTests/CommonHelpers/PredefinedMaterials.hpp"
0016 
0017 #include <limits>
0018 
0019 namespace bdata = boost::unit_test::data;
0020 
0021 using namespace Acts;
0022 using namespace Acts::UnitLiterals;
0023 
0024 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
0025 // manually calculated derived values for silicon
0026 static constexpr float SiNe = 1.160954941_mol / 1_cm3;
0027 static constexpr float SiI = 172.042290036_eV;
0028 
0029 namespace ActsTests {
0030 
0031 BOOST_AUTO_TEST_SUITE(MaterialSuite)
0032 
0033 BOOST_AUTO_TEST_CASE(ConstructVacuum) {
0034   // default constructor builds invalid material a.k.a. vacuum
0035   Material vacuum = Material::Vacuum();
0036   BOOST_CHECK(vacuum.isVacuum());
0037 }
0038 
0039 BOOST_AUTO_TEST_CASE(ConstructSomething) {
0040   // anything with non-zero Ar is a valid material
0041   auto notVacuum = Material::fromMolarDensity(1, 2, 3, 4, 5);
0042   BOOST_CHECK(!notVacuum.isVacuum());
0043 }
0044 
0045 BOOST_AUTO_TEST_CASE(Units) {
0046   Material silicon = makeSilicon();
0047 
0048   // check values w/ different units if possible
0049   CHECK_CLOSE_REL(silicon.X0(), 93.70_mm, eps);
0050   CHECK_CLOSE_REL(silicon.X0(), 9.370_cm, eps);
0051   CHECK_CLOSE_REL(silicon.X0(), 0.09370_m, eps);
0052   CHECK_CLOSE_REL(silicon.L0(), 465.2_mm, eps);
0053   CHECK_CLOSE_REL(silicon.L0(), 46.52_cm, eps);
0054   CHECK_CLOSE_REL(silicon.L0(), 0.4652_m, eps);
0055   CHECK_CLOSE_REL(silicon.Ar(), 28.0855, eps);
0056   CHECK_CLOSE_REL(silicon.Z(), 14.0, eps);
0057   CHECK_CLOSE_REL(silicon.molarDensity(), 0.08292535294012926_mol / 1_cm3, eps);
0058   CHECK_CLOSE_REL(silicon.molarDensity(), 82925.35294012926_mol / 1_m3, eps);
0059   // check derived values
0060   CHECK_CLOSE_REL(silicon.massDensity(), 2.329_g / 1_cm3, eps);
0061   CHECK_CLOSE_REL(silicon.massDensity(), 0.002329_kg / 1_cm3, eps);
0062   CHECK_CLOSE_REL(silicon.massDensity(), 0.002329_g / 1_mm3, eps);
0063   CHECK_CLOSE_REL(silicon.molarElectronDensity(),
0064                   silicon.Z() * silicon.molarDensity(), eps);
0065   CHECK_CLOSE_REL(silicon.molarElectronDensity(), SiNe, eps);
0066   CHECK_CLOSE_REL(silicon.meanExcitationEnergy(), SiI, eps);
0067 }
0068 
0069 BOOST_DATA_TEST_CASE(EncodingDecodingRoundtrip,
0070                      bdata::make({
0071                          Material::Vacuum(),
0072                          Material::fromMolarDensity(1, 2, 3, 4, 5),
0073                          makeBeryllium(),
0074                          makeSilicon(),
0075                      }),
0076                      material) {
0077   // encode material
0078   Material::ParametersVector numbers0 = material.parameters();
0079   // construct from encoded numbers
0080   Material fromNumbers(numbers0);
0081   // encode material again
0082   Material::ParametersVector numbers1 = fromNumbers.parameters();
0083 
0084   BOOST_CHECK_EQUAL(material, fromNumbers);
0085   BOOST_CHECK_EQUAL(numbers0, numbers1);
0086 }
0087 
0088 BOOST_AUTO_TEST_SUITE_END()
0089 
0090 }  // namespace ActsTests