File indexing completed on 2025-01-19 09:23:24
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Detector/Detector.hpp"
0012 #include "Acts/Detector/DetectorVolume.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Navigation/NavigationDelegates.hpp"
0015 #include "Acts/Navigation/NavigationState.hpp"
0016 #include "Acts/Navigation/NavigationStateFillers.hpp"
0017 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0018 #include "Acts/Utilities/Grid.hpp"
0019 #include "Acts/Utilities/detail/Axis.hpp"
0020
0021 #include <stdexcept>
0022
0023 namespace Acts::Experimental {
0024
0025 struct NoopFinder : public IExternalNavigation {
0026 inline void update(const GeometryContext& ,
0027 NavigationState& ) const {}
0028 };
0029
0030 struct RootVolumeFinder : public IExternalNavigation {
0031 inline void update(const GeometryContext& gctx,
0032 NavigationState& nState) const {
0033 if (nState.currentDetector == nullptr) {
0034 throw std::runtime_error(
0035 "DetectorVolumeFinders: no detector set to navigation state.");
0036 }
0037
0038 const auto& volumes = nState.currentDetector->rootVolumes();
0039 for (const auto v : volumes) {
0040 if (v->inside(gctx, nState.position)) {
0041 nState.currentVolume = v;
0042 v->externalNavigation()(gctx, nState);
0043 return;
0044 }
0045 }
0046 nState.currentVolume = nullptr;
0047 }
0048 };
0049
0050 struct TrialAndErrorVolumeFinder : public IExternalNavigation {
0051 inline void update(const GeometryContext& gctx,
0052 NavigationState& nState) const {
0053 if (nState.currentVolume == nullptr) {
0054 throw std::runtime_error(
0055 "DetectorVolumeFinders: no volume set to navigation state.");
0056 }
0057
0058 const auto& volumes = nState.currentVolume->volumes();
0059 for (const auto v : volumes) {
0060 if (v->inside(gctx, nState.position)) {
0061 nState.currentVolume = v;
0062 v->externalNavigation()(gctx, nState);
0063 return;
0064 }
0065 }
0066 }
0067 };
0068
0069
0070 inline static ExternalNavigationDelegate tryRootVolumes() {
0071 ExternalNavigationDelegate vFinder;
0072 vFinder.connect<&RootVolumeFinder::update>(
0073 std::make_unique<const RootVolumeFinder>());
0074 return vFinder;
0075 }
0076
0077
0078 inline static ExternalNavigationDelegate tryAllSubVolumes() {
0079 ExternalNavigationDelegate vFinder;
0080 vFinder.connect<&TrialAndErrorVolumeFinder::update>(
0081 std::make_unique<const TrialAndErrorVolumeFinder>());
0082 return vFinder;
0083 }
0084
0085
0086 inline static ExternalNavigationDelegate tryNoVolumes() {
0087 ExternalNavigationDelegate vFinder;
0088 vFinder.connect<&NoopFinder::update>(std::make_unique<const NoopFinder>());
0089 return vFinder;
0090 }
0091
0092
0093
0094 struct IndexedDetectorVolumeExtractor {
0095
0096
0097
0098
0099
0100
0101
0102 inline static const DetectorVolume* extract(
0103 [[maybe_unused]] const GeometryContext& gctx,
0104 const NavigationState& nState, std::size_t index) noexcept(false) {
0105 if (nState.currentDetector == nullptr) {
0106 throw std::runtime_error("IndexedVolumeExtractor: no detector given.");
0107 }
0108
0109 const auto& volumes = nState.currentDetector->volumes();
0110 return volumes[index];
0111 }
0112 };
0113
0114
0115
0116
0117 template <typename grid_type>
0118 using IndexedDetectorVolumesImpl =
0119 IndexedGridNavigation<IExternalNavigation, grid_type,
0120 IndexedDetectorVolumeExtractor, DetectorVolumeFiller>;
0121
0122 }