Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:53:19

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