File indexing completed on 2025-01-18 09:12:42
0001
0002
0003
0004
0005
0006
0007
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 }
0031
0032 BOOST_AUTO_TEST_SUITE(MaterialAccumulatedMaterialSlab)
0033
0034 BOOST_AUTO_TEST_CASE(Nothing) {
0035 AccumulatedMaterialSlab a;
0036 auto [average, trackCount] = a.totalAverage();
0037
0038 BOOST_CHECK(!average.isValid());
0039 BOOST_CHECK_EQUAL(trackCount, 0u);
0040 }
0041
0042
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
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
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
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
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
0097
0098 BOOST_AUTO_TEST_CASE(MultipleDifferentThicknessTrackSteps) {
0099 MaterialSlab unit = makeUnitSlab();
0100 AccumulatedMaterialSlab a;
0101
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
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
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
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
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
0146 BOOST_AUTO_TEST_CASE(MultipleDifferentTracks) {
0147 MaterialSlab unit = makeUnitSlab();
0148 AccumulatedMaterialSlab a;
0149
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
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
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
0175 {
0176 MaterialSlab vac(2 * unit.thickness());
0177
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
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
0190 CHECK_CLOSE_REL(average.material().Ar(), unit.material().Ar(), eps);
0191
0192 CHECK_CLOSE_REL(average.material().Z(), 0.5 * unit.material().Z(), eps);
0193
0194 BOOST_CHECK_EQUAL(average.thicknessInX0(), 1 * unit.thicknessInX0());
0195 BOOST_CHECK_EQUAL(average.thicknessInL0(), 1 * unit.thicknessInL0());
0196
0197 BOOST_CHECK_EQUAL(average.thickness(), 2 * unit.thickness());
0198 }
0199 }
0200
0201 BOOST_AUTO_TEST_SUITE_END()