File indexing completed on 2025-01-18 09:12:45
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/Navigation/NavigationState.hpp"
0014 #include "Acts/Navigation/NavigationStateFillers.hpp"
0015 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0016 #include "Acts/Utilities/AxisDefinitions.hpp"
0017 #include "Acts/Utilities/BinningType.hpp"
0018 #include "Acts/Utilities/IAxis.hpp"
0019
0020 #include <algorithm>
0021 #include <array>
0022 #include <cstddef>
0023 #include <memory>
0024 #include <tuple>
0025 #include <utility>
0026 #include <vector>
0027
0028 #include "../Surfaces/SurfaceStub.hpp"
0029
0030
0031 Acts::GeometryContext tContext;
0032
0033 namespace Acts {
0034
0035 namespace Experimental {
0036
0037 class Detector;
0038
0039
0040 class DetectorVolume {
0041 public:
0042 const Detector* d = nullptr;
0043 std::vector<const Surface*> sfs = {};
0044 std::vector<const Portal*> prts = {};
0045 const std::vector<const Surface*> surfaces() const { return sfs; }
0046 const std::vector<const Portal*> portals() const { return prts; }
0047 const Detector* detector() const { return d; };
0048 };
0049
0050
0051 class Detector {
0052 public:
0053 std::vector<const DetectorVolume*> vs = {};
0054 const std::vector<const DetectorVolume*> volumes() const { return vs; }
0055 };
0056
0057
0058 struct AllPortalsExtractor {
0059
0060
0061
0062
0063
0064 inline static const std::vector<const Portal*> extract(
0065 [[maybe_unused]] const GeometryContext& gctx,
0066 const NavigationState& nState,
0067 [[maybe_unused]] const std::vector<std::size_t>& indices = {}) {
0068 return nState.currentVolume->portals();
0069 }
0070 };
0071
0072
0073 struct AllSurfacesExtractor {
0074
0075
0076
0077
0078
0079 inline static const std::vector<const Surface*> extract(
0080 [[maybe_unused]] const GeometryContext& gctx,
0081 const NavigationState& nState,
0082 [[maybe_unused]] const std::vector<std::size_t>& indices = {}) {
0083 return nState.currentVolume->surfaces();
0084 }
0085 };
0086
0087
0088 struct IndexedSurfacesExtractor {
0089
0090
0091
0092
0093
0094 inline static const std::vector<const Surface*> extract(
0095 [[maybe_unused]] const GeometryContext& gctx,
0096 const NavigationState& nState, const std::vector<std::size_t>& indices) {
0097
0098 const auto& surfaces = nState.currentVolume->surfaces();
0099
0100 std::vector<const Surface*> eSurfaces;
0101 eSurfaces.reserve(indices.size());
0102 std::for_each(indices.begin(), indices.end(),
0103 [&](const auto& i) { eSurfaces.push_back(surfaces[i]); });
0104 return eSurfaces;
0105 }
0106 };
0107
0108 }
0109
0110 class TestAxis : public IAxis {
0111 public:
0112 TestAxis() = default;
0113
0114 bool isEquidistant() const final { return true; }
0115
0116 bool isVariable() const final { return false; }
0117
0118 AxisType getType() const final { return AxisType::Equidistant; }
0119
0120 AxisBoundaryType getBoundaryType() const final {
0121 return AxisBoundaryType::Closed;
0122 }
0123
0124 std::vector<double> getBinEdges() const final { return {-1, 1}; }
0125
0126 double getMin() const final { return -1.; }
0127
0128 double getMax() const final { return 1.; }
0129
0130 std::size_t getNBins() const final { return 1; };
0131
0132 void toStream(std::ostream& os) const final { os << "TextAxis"; }
0133 };
0134
0135 class MultiGrid1D {
0136 public:
0137 static constexpr std::size_t DIM = 1u;
0138 using point_t = std::array<double, DIM>;
0139
0140 const std::vector<std::size_t>& atPosition(
0141 const std::array<double, 1u>& ) const {
0142 return e;
0143 }
0144
0145 std::array<const IAxis*, DIM> axes() const { return {&ta}; }
0146 TestAxis ta = TestAxis();
0147
0148 private:
0149 std::vector<std::size_t> e = {0u, 1u};
0150 };
0151
0152 class MultiGrid2D {
0153 public:
0154 static constexpr std::size_t DIM = 2u;
0155 using point_t = std::array<double, DIM>;
0156
0157 const std::vector<std::size_t>& atPosition(
0158 const std::array<double, 2u>& ) const {
0159 return e;
0160 }
0161
0162 std::array<const IAxis*, DIM> axes() const { return {&ta, &ta}; };
0163 TestAxis ta = TestAxis();
0164
0165 private:
0166 std::vector<std::size_t> e = {1u};
0167 };
0168 }
0169
0170 using SingleVolumeUpdater = Acts::Experimental::SingleObjectNavigation<
0171 Acts::Experimental::IExternalNavigation, Acts::Experimental::DetectorVolume,
0172 Acts::Experimental::DetectorVolumeFiller>;
0173
0174 using AllSurfacesProvider = Acts::Experimental::StaticAccessNavigation<
0175 Acts::Experimental::IInternalNavigation,
0176 Acts::Experimental::AllSurfacesExtractor,
0177 Acts::Experimental::SurfacesFiller>;
0178
0179 using AllPortalsProvider = Acts::Experimental::StaticAccessNavigation<
0180 Acts::Experimental::IInternalNavigation,
0181 Acts::Experimental::AllPortalsExtractor, Acts::Experimental::PortalsFiller>;
0182
0183 auto surfaceA = Acts::Surface::makeShared<Acts::SurfaceStub>();
0184 auto surfaceB = Acts::Surface::makeShared<Acts::SurfaceStub>();
0185 auto surfaceC = Acts::Surface::makeShared<Acts::SurfaceStub>();
0186
0187 auto pSurfaceA = Acts::Surface::makeShared<Acts::SurfaceStub>();
0188 auto pSurfaceB = Acts::Surface::makeShared<Acts::SurfaceStub>();
0189 auto portalA = std::make_shared<Acts::Experimental::Portal>(pSurfaceA);
0190 auto portalB = std::make_shared<Acts::Experimental::Portal>(pSurfaceB);
0191
0192 BOOST_AUTO_TEST_SUITE(Experimental)
0193
0194 BOOST_AUTO_TEST_CASE(SingleExternalNavigationDelegate) {
0195 Acts::Experimental::NavigationState nState;
0196
0197
0198 auto sVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0199 SingleVolumeUpdater sVolumeUpdater(sVolume.get());
0200
0201
0202 sVolumeUpdater.update(tContext, nState);
0203 BOOST_CHECK_EQUAL(nState.currentVolume, sVolume.get());
0204 }
0205
0206 BOOST_AUTO_TEST_CASE(AllSurfaces) {
0207
0208 auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0209 (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
0210 (*dVolume).prts = {portalA.get(), portalB.get()};
0211
0212 Acts::Experimental::NavigationState nState;
0213 nState.currentVolume = dVolume.get();
0214 BOOST_CHECK(nState.surfaceCandidates.empty());
0215 AllSurfacesProvider allSurfaces;
0216 allSurfaces.update(tContext, nState);
0217 BOOST_CHECK_EQUAL(nState.surfaceCandidates.size(), 3u);
0218 }
0219
0220 BOOST_AUTO_TEST_CASE(AllPortals) {
0221
0222 auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0223 (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
0224 (*dVolume).prts = {portalA.get(), portalB.get()};
0225
0226 Acts::Experimental::NavigationState nState;
0227 nState.currentVolume = dVolume.get();
0228 BOOST_CHECK(nState.surfaceCandidates.empty());
0229 AllPortalsProvider allPortals;
0230 allPortals.update(tContext, nState);
0231 BOOST_CHECK_EQUAL(nState.surfaceCandidates.size(), 2u);
0232 }
0233
0234 BOOST_AUTO_TEST_CASE(AllPortalsAllSurfaces) {
0235
0236 auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0237 (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
0238 (*dVolume).prts = {portalA.get(), portalB.get()};
0239
0240 Acts::Experimental::NavigationState nState;
0241 nState.currentVolume = dVolume.get();
0242 BOOST_CHECK(nState.surfaceCandidates.empty());
0243
0244 AllPortalsProvider allPortals;
0245 AllSurfacesProvider allSurfaces;
0246 auto allPortalsAllSurfaces = Acts::Experimental::ChainedNavigation<
0247 Acts::Experimental::IInternalNavigation, AllPortalsProvider,
0248 AllSurfacesProvider>(std::tie(allPortals, allSurfaces));
0249
0250 allPortalsAllSurfaces.update(tContext, nState);
0251 BOOST_CHECK_EQUAL(nState.surfaceCandidates.size(), 5u);
0252 }
0253
0254 BOOST_AUTO_TEST_CASE(AllPortalsGrid1DSurfaces) {
0255
0256 auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0257 (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
0258 (*dVolume).prts = {portalA.get(), portalB.get()};
0259
0260 Acts::Experimental::NavigationState nState;
0261 nState.currentVolume = dVolume.get();
0262 BOOST_CHECK(nState.surfaceCandidates.empty());
0263
0264 AllPortalsProvider allPortals;
0265 Acts::MultiGrid1D grid;
0266 using Grid1DSurfacesProvider = Acts::Experimental::IndexedGridNavigation<
0267 Acts::Experimental::IInternalNavigation, decltype(grid),
0268 Acts::Experimental::IndexedSurfacesExtractor,
0269 Acts::Experimental::SurfacesFiller>;
0270 auto grid1DSurfaces =
0271 Grid1DSurfacesProvider(std::move(grid), {Acts::AxisDirection::AxisR});
0272
0273 auto allPortalsGrid1DSurfaces = Acts::Experimental::ChainedNavigation<
0274 Acts::Experimental::IInternalNavigation, AllPortalsProvider,
0275 Grid1DSurfacesProvider>(std::tie(allPortals, grid1DSurfaces));
0276
0277 allPortalsGrid1DSurfaces.update(tContext, nState);
0278 BOOST_CHECK_EQUAL(nState.surfaceCandidates.size(), 4u);
0279 }
0280
0281 BOOST_AUTO_TEST_CASE(AllPortalsGrid2DSurfaces) {
0282
0283 auto dVolume = std::make_shared<Acts::Experimental::DetectorVolume>();
0284 (*dVolume).sfs = {surfaceA.get(), surfaceB.get(), surfaceC.get()};
0285 (*dVolume).prts = {portalA.get(), portalB.get()};
0286
0287 Acts::Experimental::NavigationState nState;
0288 nState.currentVolume = dVolume.get();
0289 BOOST_CHECK(nState.surfaceCandidates.empty());
0290
0291 AllPortalsProvider allPortals;
0292 Acts::MultiGrid2D grid;
0293 using Grid2DSurfacesProvider = Acts::Experimental::IndexedGridNavigation<
0294 Acts::Experimental::IInternalNavigation, decltype(grid),
0295 Acts::Experimental::IndexedSurfacesExtractor,
0296 Acts::Experimental::SurfacesFiller>;
0297 auto grid2DSurfaces = Grid2DSurfacesProvider(
0298 std::move(grid),
0299 {Acts::AxisDirection::AxisR, Acts::AxisDirection::AxisZ});
0300
0301 auto allPortalsGrid2DSurfaces = Acts::Experimental::ChainedNavigation<
0302 Acts::Experimental::IInternalNavigation, AllPortalsProvider,
0303 Grid2DSurfacesProvider>(std::tie(allPortals, grid2DSurfaces));
0304
0305 allPortalsGrid2DSurfaces.update(tContext, nState);
0306 BOOST_CHECK_EQUAL(nState.surfaceCandidates.size(), 3u);
0307 }
0308
0309 BOOST_AUTO_TEST_SUITE_END()