Back to home page

EIC code displayed by LXR

 
 

    


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

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/unit_test.hpp>
0010 
0011 #include "Acts/Material/MaterialComposition.hpp"
0012 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0013 
0014 #include <vector>
0015 
0016 namespace Acts::Test {
0017 
0018 BOOST_AUTO_TEST_SUITE(material_composition)
0019 
0020 constexpr float eps = 1.0f / 255u;
0021 
0022 BOOST_AUTO_TEST_CASE(construct_element_fraction) {
0023   // carbon parameters, atomic charge is Z
0024   unsigned int carbonZ = 12u;
0025   // a fraction between 0 and 255
0026   unsigned int carbonWeight = 46u;
0027   float carbonFraction = static_cast<float>(carbonWeight) / 255u;
0028 
0029   ElementFraction a(carbonZ, carbonFraction);
0030   BOOST_CHECK_EQUAL(a.element(), carbonZ);
0031   CHECK_CLOSE_REL(a.fraction(), carbonFraction, eps);
0032 
0033   ElementFraction b(carbonZ, carbonWeight);
0034   BOOST_CHECK_EQUAL(b.element(), carbonZ);
0035   CHECK_CLOSE_REL(b.fraction(), carbonFraction, eps);
0036 }
0037 
0038 BOOST_AUTO_TEST_CASE(construct_with_fractions) {
0039   ElementFraction carbon(12u, 0.45f);
0040   ElementFraction silicon(14u, 0.125f);
0041   ElementFraction titanium(22u, 0.25f);
0042   ElementFraction copper(29u, 0.175f);
0043 
0044   MaterialComposition compound({silicon, carbon, titanium, copper});
0045   BOOST_CHECK(!!compound);
0046   BOOST_CHECK_EQUAL(compound.size(), 4u);
0047 
0048   float totalFraction = 0.0f;
0049   for (const auto& eFraction : compound) {
0050     totalFraction += eFraction.fraction();
0051   }
0052   // to better fit we need to implement some proper weight scaling
0053   CHECK_CLOSE_REL(totalFraction, 1.0f, compound.size() * eps);
0054 
0055   // input order should not matter
0056   MaterialComposition shuffled({carbon, silicon, titanium, copper});
0057   // check if the sorting worked
0058   BOOST_CHECK_EQUAL(compound.size(), shuffled.size());
0059   BOOST_CHECK_EQUAL(compound, shuffled);
0060 }
0061 
0062 BOOST_AUTO_TEST_CASE(construct_with_weights) {
0063   ElementFraction carbon(12u, 128u);
0064   ElementFraction silicon(14u, 64u);
0065   ElementFraction titanium(22u, 32u);
0066   ElementFraction copper(29u, 31u);
0067 
0068   MaterialComposition compound({silicon, carbon, titanium, copper});
0069   BOOST_CHECK(!!compound);
0070   BOOST_CHECK_EQUAL(compound.size(), 4u);
0071 
0072   float totalFraction = 0.0f;
0073   for (const auto& eFraction : compound) {
0074     totalFraction += eFraction.fraction();
0075   }
0076   // to better fit we need to implement some proper weight scaling
0077   CHECK_CLOSE_REL(totalFraction, 1.0f, compound.size() * eps);
0078 }
0079 
0080 BOOST_AUTO_TEST_SUITE_END()
0081 
0082 }  // namespace Acts::Test