Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:24

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022-2023 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 http://mozilla.org/MPL/2.0/.
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& /*gctx*/,
0027                      NavigationState& /*nState*/) 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 /// Generate a delegate to try the root volumes
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 /// Generate a delegate to try all sub volumes
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 /// Generate a delegate to try no volume
0086 inline static ExternalNavigationDelegate tryNoVolumes() {
0087   ExternalNavigationDelegate vFinder;
0088   vFinder.connect<&NoopFinder::update>(std::make_unique<const NoopFinder>());
0089   return vFinder;
0090 }
0091 
0092 /// @brief A helper struct that allows to extrace a volume
0093 /// from the detector by its index
0094 struct IndexedDetectorVolumeExtractor {
0095   /// Extract the surfaces from the volume
0096   ///
0097   /// @param gctx the geometry contextfor this extraction call
0098   /// @param nState is the current navigation state
0099   /// @param index is the index in the global detector volume store
0100   ///
0101   /// @return a raw DetectorVolume pointer
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     // Get the volume container from the detector
0109     const auto& volumes = nState.currentDetector->volumes();
0110     return volumes[index];
0111   }
0112 };
0113 
0114 /// @brief  An indexed volume implementation access
0115 ///
0116 /// @tparam grid_type is the grid type used for this
0117 template <typename grid_type>
0118 using IndexedDetectorVolumesImpl =
0119     IndexedGridNavigation<IExternalNavigation, grid_type,
0120                           IndexedDetectorVolumeExtractor, DetectorVolumeFiller>;
0121 
0122 }  // namespace Acts::Experimental