Back to home page

EIC code displayed by LXR

 
 

    


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

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/AccumulatedMaterialSlab.hpp"
0012 #include "Acts/Material/Material.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 #include "Acts/Tests/CommonHelpers/PredefinedMaterials.hpp"
0016 
0017 #include <limits>
0018 #include <utility>
0019 
0020 namespace {
0021 
0022 using Acts::AccumulatedMaterialSlab;
0023 using Acts::Material;
0024 using Acts::MaterialSlab;
0025 using Acts::Test::makeSilicon;
0026 using Acts::Test::makeUnitSlab;
0027 
0028 constexpr auto eps = std::numeric_limits<float>::epsilon();
0029 
0030 }  // namespace
0031 
0032 BOOST_AUTO_TEST_SUITE(MaterialAccumulatedMaterialSlab)
0033 
0034 BOOST_AUTO_TEST_CASE(Nothing) {
0035   AccumulatedMaterialSlab a;
0036   auto [average, trackCount] = a.totalAverage();
0037   // material is vacuum
0038   BOOST_CHECK(!average.isValid());
0039   BOOST_CHECK_EQUAL(trackCount, 0u);
0040 }
0041 
0042 // average three empty tracks which are ignored by default
0043 BOOST_AUTO_TEST_CASE(EmptyTracksIgnored) {
0044   AccumulatedMaterialSlab a;
0045   a.trackAverage();
0046   a.trackAverage();
0047   a.trackAverage();
0048   auto [average, trackCount] = a.totalAverage();
0049   BOOST_CHECK(!average.isValid());
0050   BOOST_CHECK_EQUAL(trackCount, 0u);
0051 }
0052 
0053 // average three empty tracks and do not ignore them
0054 BOOST_AUTO_TEST_CASE(EmptyTracks) {
0055   AccumulatedMaterialSlab a;
0056   a.trackAverage(true);
0057   a.trackAverage(true);
0058   a.trackAverage(true);
0059   auto [average, trackCount] = a.totalAverage();
0060   BOOST_CHECK(!average.isValid());
0061   BOOST_CHECK_EQUAL(trackCount, 3u);
0062 }
0063 
0064 BOOST_AUTO_TEST_CASE(MultipleIdenticalThicknessTrackSteps) {
0065   MaterialSlab unit = makeUnitSlab();
0066   AccumulatedMaterialSlab a;
0067   // accumulate three identical steps for one track
0068   {
0069     a.accumulate(unit);
0070     a.accumulate(unit);
0071     a.accumulate(unit);
0072     a.trackAverage();
0073     auto [average, trackCount] = a.totalAverage();
0074     BOOST_CHECK_EQUAL(trackCount, 1u);
0075     BOOST_CHECK_EQUAL(average.material(), unit.material());
0076     BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
0077     BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
0078     BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
0079   }
0080   // accumulate three identical steps for one additional track
0081   {
0082     a.accumulate(unit);
0083     a.accumulate(unit);
0084     a.accumulate(unit);
0085     a.trackAverage();
0086     auto [average, trackCount] = a.totalAverage();
0087     BOOST_CHECK_EQUAL(trackCount, 2u);
0088     // averages must stay the same since we added the same material again
0089     BOOST_CHECK_EQUAL(average.material(), unit.material());
0090     BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
0091     BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
0092     BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
0093   }
0094 }
0095 
0096 // accumulate and average three tracks.
0097 // each track contributes the same material but each in different steps.
0098 BOOST_AUTO_TEST_CASE(MultipleDifferentThicknessTrackSteps) {
0099   MaterialSlab unit = makeUnitSlab();
0100   AccumulatedMaterialSlab a;
0101   // accumulate three identical steps
0102   {
0103     a.accumulate(unit);
0104     a.accumulate(unit);
0105     a.accumulate(unit);
0106     a.trackAverage();
0107     auto [average, trackCount] = a.totalAverage();
0108     BOOST_CHECK_EQUAL(trackCount, 1u);
0109     BOOST_CHECK_EQUAL(average.material(), unit.material());
0110     BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
0111     BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
0112     BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
0113   }
0114   // accumulate one step with thickness 1, one with thickness 2
0115   {
0116     MaterialSlab twice = unit;
0117     twice.scaleThickness(2);
0118     a.accumulate(unit);
0119     a.accumulate(twice);
0120     a.trackAverage();
0121     auto [average, trackCount] = a.totalAverage();
0122     BOOST_CHECK_EQUAL(trackCount, 2u);
0123     // averages must stay the same
0124     BOOST_CHECK_EQUAL(average.material(), unit.material());
0125     BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
0126     BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
0127     BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
0128   }
0129   // accumulate one step with thickness 3
0130   {
0131     MaterialSlab thrice = unit;
0132     thrice.scaleThickness(3);
0133     a.accumulate(thrice);
0134     a.trackAverage();
0135     auto [average, trackCount] = a.totalAverage();
0136     BOOST_CHECK_EQUAL(trackCount, 3u);
0137     // averages must stay the same
0138     BOOST_CHECK_EQUAL(average.material(), unit.material());
0139     BOOST_CHECK_EQUAL(average.thickness(), 3 * unit.thickness());
0140     BOOST_CHECK_EQUAL(average.thicknessInX0(), 3.0f);
0141     BOOST_CHECK_EQUAL(average.thicknessInL0(), 3.0f);
0142   }
0143 }
0144 
0145 // average multiple tracks w/ one step each but different materials
0146 BOOST_AUTO_TEST_CASE(MultipleDifferentTracks) {
0147   MaterialSlab unit = makeUnitSlab();
0148   AccumulatedMaterialSlab a;
0149   // add material w/ given thickness
0150   {
0151     a.accumulate(unit);
0152     a.trackAverage();
0153     auto [average, trackCount] = a.totalAverage();
0154     BOOST_CHECK_EQUAL(trackCount, 1u);
0155     BOOST_CHECK_EQUAL(average.material(), unit.material());
0156     BOOST_CHECK_EQUAL(average.thickness(), unit.thickness());
0157     BOOST_CHECK_EQUAL(average.thicknessInX0(), unit.thicknessInX0());
0158     BOOST_CHECK_EQUAL(average.thicknessInL0(), unit.thicknessInL0());
0159   }
0160   // add material w/ given three times the initial thickness
0161   {
0162     MaterialSlab three = unit;
0163     three.scaleThickness(3);
0164     a.accumulate(three);
0165     a.trackAverage();
0166     auto [average, trackCount] = a.totalAverage();
0167     BOOST_CHECK_EQUAL(trackCount, 2);
0168     // average thickness should now be 2*initial, average material unchanged
0169     BOOST_CHECK_EQUAL(average.material(), unit.material());
0170     BOOST_CHECK_EQUAL(average.thickness(), 2 * unit.thickness());
0171     BOOST_CHECK_EQUAL(average.thicknessInX0(), 2 * unit.thicknessInX0());
0172     BOOST_CHECK_EQUAL(average.thicknessInL0(), 2 * unit.thicknessInL0());
0173   }
0174   // add vacuum w/ given the same thickness as the current average
0175   {
0176     MaterialSlab vac(2 * unit.thickness());
0177     // add vacuum twice to counteract the existing two tracks stored
0178     a.accumulate(vac);
0179     a.trackAverage();
0180     a.accumulate(vac);
0181     a.trackAverage();
0182     auto [average, trackCount] = a.totalAverage();
0183     BOOST_CHECK_EQUAL(trackCount, 4u);
0184     // average material density halved
0185     CHECK_CLOSE_REL(average.material().X0(), 2 * unit.material().X0(), eps);
0186     CHECK_CLOSE_REL(average.material().L0(), 2 * unit.material().L0(), eps);
0187     CHECK_CLOSE_REL(average.material().molarDensity(),
0188                     0.5f * unit.material().molarDensity(), eps);
0189     // average atom is still the same species
0190     CHECK_CLOSE_REL(average.material().Ar(), unit.material().Ar(), eps);
0191     // average atomic number proportional to the thickness
0192     CHECK_CLOSE_REL(average.material().Z(), 0.5 * unit.material().Z(), eps);
0193     // thickness in x0/l0 depends on density and thus halved as well
0194     BOOST_CHECK_EQUAL(average.thicknessInX0(), 1 * unit.thicknessInX0());
0195     BOOST_CHECK_EQUAL(average.thicknessInL0(), 1 * unit.thicknessInL0());
0196     // average real thickness stays the same
0197     BOOST_CHECK_EQUAL(average.thickness(), 2 * unit.thickness());
0198   }
0199 }
0200 
0201 BOOST_AUTO_TEST_SUITE_END()