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/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Material/BinnedSurfaceMaterial.hpp"
0014 #include "Acts/Material/BinnedSurfaceMaterialAccumulater.hpp"
0015 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0016 #include "Acts/Material/Material.hpp"
0017 #include "Acts/Material/MaterialSlab.hpp"
0018 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0019 #include "Acts/Surfaces/CylinderSurface.hpp"
0020 #include "Acts/Surfaces/Surface.hpp"
0021 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0022 #include "Acts/Utilities/BinUtility.hpp"
0023 #include "Acts/Utilities/Logger.hpp"
0024
0025 #include <numbers>
0026 #include <tuple>
0027 #include <utility>
0028 #include <vector>
0029
0030 namespace Acts::Test {
0031
0032 auto tContext = GeometryContext();
0033
0034 BOOST_AUTO_TEST_SUITE(BinnedSurfaceMaterialAccumulaterSuite)
0035
0036 BOOST_AUTO_TEST_CASE(InvalidSetupTest) {
0037 std::vector<std::shared_ptr<Surface>> surfaces = {
0038 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20.0, 100.0),
0039 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30.0, 100.0),
0040 };
0041
0042 for (auto [is, surface] : enumerate(surfaces)) {
0043 surface->assignGeometryId(GeometryIdentifier().setSensitive(is + 1));
0044 }
0045
0046
0047 MaterialSlab mp;
0048 surfaces[0u]->assignSurfaceMaterial(
0049 std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0050
0051
0052
0053 BinnedSurfaceMaterialAccumulater::Config bsmaConfig;
0054 bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get()};
0055 bsmaConfig.emptyBinCorrection = true;
0056 bsmaConfig.geoContext = tContext;
0057
0058 BinnedSurfaceMaterialAccumulater bsma(
0059 bsmaConfig,
0060 getDefaultLogger("BinnedSurfaceMaterialAccumulater", Logging::VERBOSE));
0061
0062
0063
0064 BOOST_CHECK_THROW(bsma.createState(), std::invalid_argument);
0065 }
0066
0067 BOOST_AUTO_TEST_CASE(AccumulationTest) {
0068 std::vector<std::shared_ptr<Surface>> surfaces = {
0069 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20.0, 100.0),
0070 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30.0, 100.0),
0071 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 50.0,
0072 100.0)};
0073
0074 for (auto [is, surface] : enumerate(surfaces)) {
0075 surface->assignGeometryId(GeometryIdentifier().setSensitive(is + 1));
0076 }
0077
0078
0079
0080
0081
0082
0083
0084 MaterialSlab mp;
0085 surfaces[0u]->assignSurfaceMaterial(
0086 std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0087
0088
0089 BinUtility sb1(4, -std::numbers::pi, std::numbers::pi, closed,
0090 AxisDirection::AxisPhi);
0091 sb1 += BinUtility(2, -100., 100., open, AxisDirection::AxisZ);
0092 surfaces[1u]->assignSurfaceMaterial(
0093 std::make_shared<ProtoSurfaceMaterial>(sb1));
0094
0095
0096 std::vector<MaterialSlab> mps = {mp, mp, mp};
0097 BinUtility sb2(3, -100., 100., open, AxisDirection::AxisZ);
0098 surfaces[2u]->assignSurfaceMaterial(
0099 std::make_shared<BinnedSurfaceMaterial>(sb2, mps));
0100
0101 BinnedSurfaceMaterialAccumulater::Config bsmaConfig;
0102 bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get(),
0103 surfaces[2].get()};
0104 bsmaConfig.emptyBinCorrection = true;
0105 bsmaConfig.geoContext = tContext;
0106
0107 BinnedSurfaceMaterialAccumulater bsma(
0108 bsmaConfig,
0109 getDefaultLogger("BinnedSurfaceMaterialAccumulater", Logging::VERBOSE));
0110
0111
0112 auto state = bsma.createState();
0113
0114 auto cState =
0115 static_cast<const BinnedSurfaceMaterialAccumulater::State*>(state.get());
0116
0117 BOOST_CHECK_EQUAL(cState->accumulatedMaterial.size(), 3u);
0118
0119
0120
0121
0122
0123
0124 Vector3 p(0, 0, 0);
0125 Vector3 d0 = Vector3(50, 1, 0).normalized();
0126
0127 MaterialInteraction m00;
0128 m00.surface = surfaces[0u].get();
0129 m00.position = 20 * d0;
0130 m00.direction = d0;
0131
0132 MaterialInteraction m01;
0133 m01.surface = surfaces[1u].get();
0134 m01.position = 30 * d0;
0135 m01.direction = d0;
0136
0137 MaterialInteraction m02;
0138 m02.surface = surfaces[1u].get();
0139 m02.position = 30 * d0;
0140 m02.direction = d0;
0141
0142 std::vector<MaterialInteraction> mInteractions = {m01, m01, m02};
0143 std::vector<IAssignmentFinder::SurfaceAssignment> emptyHits = {
0144 {surfaces[2u].get(), 50 * d0, d0}};
0145
0146 bsma.accumulate(*state, mInteractions, emptyHits);
0147
0148
0149
0150
0151
0152 Vector3 d1 = Vector3(10, 10, 0).normalized();
0153 MaterialInteraction m11;
0154 m11.surface = surfaces[1u].get();
0155 m11.position = 30 * d1;
0156 m11.direction = d1;
0157
0158 MaterialInteraction m12;
0159 m12.surface = surfaces[2u].get();
0160 m12.position = 50 * d1;
0161 m12.direction = d1;
0162
0163 mInteractions = {m11, m12};
0164 emptyHits = {{surfaces[0u].get(), 50 * d1, d1}};
0165 bsma.accumulate(*state, mInteractions, emptyHits);
0166
0167
0168 auto maps = bsma.finalizeMaterial(*state);
0169
0170 BOOST_CHECK_EQUAL(maps.size(), 3u);
0171
0172 auto m0Itr = maps.find(GeometryIdentifier().setSensitive(1));
0173 BOOST_CHECK(m0Itr != maps.end());
0174 BOOST_CHECK(m0Itr->second != nullptr);
0175
0176 auto m1Itr = maps.find(GeometryIdentifier().setSensitive(2));
0177 BOOST_CHECK(m1Itr != maps.end());
0178 BOOST_CHECK(m1Itr->second != nullptr);
0179
0180 auto m2Itr = maps.find(GeometryIdentifier().setSensitive(3));
0181 BOOST_CHECK(m2Itr != maps.end());
0182 BOOST_CHECK(m2Itr->second != nullptr);
0183
0184
0185
0186 auto m0 = m0Itr->second;
0187 const HomogeneousSurfaceMaterial* hm0 =
0188 dynamic_cast<const HomogeneousSurfaceMaterial*>(m0.get());
0189 BOOST_CHECK(hm0 != nullptr);
0190
0191
0192 auto m1 = m1Itr->second;
0193 const BinnedSurfaceMaterial* bm1 =
0194 dynamic_cast<const BinnedSurfaceMaterial*>(m1.get());
0195 BOOST_CHECK(bm1 != nullptr);
0196
0197
0198 auto m2 = m2Itr->second;
0199 const BinnedSurfaceMaterial* bm2 =
0200 dynamic_cast<const BinnedSurfaceMaterial*>(m2.get());
0201 BOOST_CHECK(bm2 != nullptr);
0202
0203
0204 auto invalidSurface =
0205 Surface::makeShared<CylinderSurface>(Transform3::Identity(), 40.0, 100.0);
0206 invalidSurface->assignGeometryId(GeometryIdentifier().setSensitive(4));
0207
0208
0209 MaterialInteraction mXX;
0210 mXX.surface = invalidSurface.get();
0211 mXX.position = 50 * d1;
0212 mXX.direction = d1;
0213 BOOST_CHECK_THROW(bsma.accumulate(*state, {mXX}, {}), std::invalid_argument);
0214
0215
0216 BOOST_CHECK_THROW(
0217 bsma.accumulate(*state, {}, {{invalidSurface.get(), 50 * d1, d1}}),
0218 std::invalid_argument);
0219 }
0220
0221 BOOST_AUTO_TEST_SUITE_END()
0222
0223 }