Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:44

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 "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 #include "Acts/Tests/CommonHelpers/PredefinedMaterials.hpp"
0016 
0017 #include <limits>
0018 
0019 namespace bdata = boost::unit_test::data;
0020 
0021 using namespace Acts::UnitLiterals;
0022 
0023 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
0024 // manually calculated derived values for silicon
0025 static constexpr float SiNe = 1.160954941_mol / 1_cm3;
0026 static constexpr float SiI = 172.042290036_eV;
0027 
0028 BOOST_AUTO_TEST_SUITE(Material)
0029 
0030 BOOST_AUTO_TEST_CASE(ConstructVacuum) {
0031   // default constructor builds invalid material a.k.a. vacuum
0032   Acts::Material vacuum;
0033   BOOST_CHECK(!vacuum.isValid());
0034 }
0035 
0036 BOOST_AUTO_TEST_CASE(ConstructSomething) {
0037   // anything with non-zero Ar is a valid material
0038   auto notVacuum = Acts::Material::fromMolarDensity(1, 2, 3, 4, 5);
0039   BOOST_CHECK(notVacuum.isValid());
0040 }
0041 
0042 BOOST_AUTO_TEST_CASE(Units) {
0043   Acts::Material silicon = Acts::Test::makeSilicon();
0044 
0045   // check values w/ different units if possible
0046   CHECK_CLOSE_REL(silicon.X0(), 93.70_mm, eps);
0047   CHECK_CLOSE_REL(silicon.X0(), 9.370_cm, eps);
0048   CHECK_CLOSE_REL(silicon.X0(), 0.09370_m, eps);
0049   CHECK_CLOSE_REL(silicon.L0(), 465.2_mm, eps);
0050   CHECK_CLOSE_REL(silicon.L0(), 46.52_cm, eps);
0051   CHECK_CLOSE_REL(silicon.L0(), 0.4652_m, eps);
0052   CHECK_CLOSE_REL(silicon.Ar(), 28.0855, eps);
0053   CHECK_CLOSE_REL(silicon.Z(), 14.0, eps);
0054   CHECK_CLOSE_REL(silicon.molarDensity(), 0.08292535294012926_mol / 1_cm3, eps);
0055   CHECK_CLOSE_REL(silicon.molarDensity(), 82925.35294012926_mol / 1_m3, eps);
0056   // check derived values
0057   CHECK_CLOSE_REL(silicon.massDensity(), 2.329_g / 1_cm3, eps);
0058   CHECK_CLOSE_REL(silicon.massDensity(), 0.002329_kg / 1_cm3, eps);
0059   CHECK_CLOSE_REL(silicon.massDensity(), 0.002329_g / 1_mm3, eps);
0060   CHECK_CLOSE_REL(silicon.molarElectronDensity(),
0061                   silicon.Z() * silicon.molarDensity(), eps);
0062   CHECK_CLOSE_REL(silicon.molarElectronDensity(), SiNe, eps);
0063   CHECK_CLOSE_REL(silicon.meanExcitationEnergy(), SiI, eps);
0064 }
0065 
0066 BOOST_DATA_TEST_CASE(EncodingDecodingRoundtrip,
0067                      bdata::make({
0068                          Acts::Material(),
0069                          Acts::Material::fromMolarDensity(1, 2, 3, 4, 5),
0070                          Acts::Test::makeBeryllium(),
0071                          Acts::Test::makeSilicon(),
0072                      }),
0073                      material) {
0074   // encode material
0075   Acts::Material::ParametersVector numbers0 = material.parameters();
0076   // construct from encoded numbers
0077   Acts::Material fromNumbers(numbers0);
0078   // encode material again
0079   Acts::Material::ParametersVector numbers1 = fromNumbers.parameters();
0080 
0081   BOOST_CHECK_EQUAL(material, fromNumbers);
0082   BOOST_CHECK_EQUAL(numbers0, numbers1);
0083 }
0084 
0085 BOOST_AUTO_TEST_SUITE_END()