Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:41

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Detector/DetectorVolume.hpp"
0014 #include "Acts/Detector/Portal.hpp"
0015 #include "Acts/Geometry/GeometryContext.hpp"
0016 #include "Acts/Navigation/MultiLayerNavigation.hpp"
0017 #include "Acts/Navigation/NavigationState.hpp"
0018 #include "Acts/Navigation/NavigationStateFillers.hpp"
0019 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0020 #include "Acts/Surfaces/Surface.hpp"
0021 
0022 #include <memory>
0023 #include <tuple>
0024 
0025 namespace Acts::Experimental {
0026 
0027 struct AllPortalsNavigation : public IInternalNavigation {
0028   /// A ordered portal provider
0029   ///
0030   /// @param gctx is the Geometry context of this call
0031   /// @param nState is the navigation state to be updated
0032   ///
0033   /// @note that the intersections are ordered, such that the
0034   /// smallest intersection pathlength >= overstep tolerance is the lowest
0035   ///
0036   /// @return an ordered list of portal candidates
0037   inline void update(const GeometryContext& gctx,
0038                      NavigationState& nState) const {
0039     if (nState.currentVolume == nullptr) {
0040       throw std::runtime_error(
0041           "AllPortalsNavigation: no detector volume set to navigation state.");
0042     }
0043     // Retrieval necessary
0044     if (nState.surfaceCandidates.empty()) {
0045       // Fill internal portals if existing
0046       for (const auto v : nState.currentVolume->volumes()) {
0047         const auto& iPortals = v->portals();
0048         PortalsFiller::fill(nState, iPortals);
0049       }
0050       // Filling the new portal candidates
0051       const auto& portals = nState.currentVolume->portals();
0052       PortalsFiller::fill(nState, portals);
0053     }
0054     // Sort and update
0055     updateCandidates(gctx, nState);
0056   }
0057 };
0058 
0059 struct AllPortalsAndSurfacesNavigation : public IInternalNavigation {
0060   /// An ordered list of portals and surfaces provider
0061   ///
0062   /// @param gctx is the Geometry context of this call
0063   /// @param nState is the navigation state to be updated
0064   ///
0065   /// @note that the intersections are ordered, such that the
0066   /// smallest intersection pathlength >= overstep tolerance is the lowest
0067   ///
0068   /// @return an ordered list of portal and surface candidates
0069   inline void update(const GeometryContext& gctx,
0070                      NavigationState& nState) const {
0071     if (nState.currentDetector == nullptr) {
0072       throw std::runtime_error(
0073           "AllPortalsAndSurfacesNavigation: no detector volume set to "
0074           "navigation "
0075           "state.");
0076     }
0077     // A volume switch has happened, update list of portals & surfaces
0078     if (nState.surfaceCandidates.empty()) {
0079       // Fill internal portals if existing
0080       for (const auto v : nState.currentVolume->volumes()) {
0081         const auto& iPortals = v->portals();
0082         PortalsFiller::fill(nState, iPortals);
0083       }
0084       // Assign the new volume
0085       const auto& portals = nState.currentVolume->portals();
0086       const auto& surfaces = nState.currentVolume->surfaces();
0087       PortalsFiller::fill(nState, portals);
0088       SurfacesFiller::fill(nState, surfaces);
0089     }
0090     // Update internal candidates
0091     updateCandidates(gctx, nState);
0092   }
0093 };
0094 
0095 /// Generate a provider for all portals
0096 ///
0097 /// @return a connected navigationstate updator
0098 inline static InternalNavigationDelegate tryAllPortals() {
0099   auto ap = std::make_unique<const AllPortalsNavigation>();
0100   InternalNavigationDelegate nStateUpdater;
0101   nStateUpdater.connect<&AllPortalsNavigation::update>(std::move(ap));
0102   return nStateUpdater;
0103 }
0104 
0105 /// Generate a provider for all portals and Surfacess
0106 ///
0107 /// @note this is a try-and error navigation, not recommended for production
0108 /// setup with many surfaces
0109 ///
0110 /// @return a connected navigationstate updator
0111 inline static InternalNavigationDelegate tryAllPortalsAndSurfaces() {
0112   auto aps = std::make_unique<const AllPortalsAndSurfacesNavigation>();
0113   InternalNavigationDelegate nStateUpdater;
0114   nStateUpdater.connect<&AllPortalsAndSurfacesNavigation::update>(
0115       std::move(aps));
0116   return nStateUpdater;
0117 }
0118 
0119 /// @brief This holds and extracts a collection of surfaces without much
0120 /// checking, this could be e.g. support surfaces for layer structures,
0121 /// e.g.
0122 ///
0123 struct AdditionalSurfacesNavigation : public IInternalNavigation {
0124   /// The volumes held by this collection
0125   std::vector<const Surface*> surfaces = {};
0126 
0127   /// Extract the sub volumes from the volume
0128   ///
0129   /// @param gctx the geometry contextfor this extraction call (ignored)
0130   /// @param nState is the navigation state
0131   ///
0132   inline void update([[maybe_unused]] const GeometryContext& gctx,
0133                      NavigationState& nState) const {
0134     SurfacesFiller::fill(nState, surfaces);
0135   }
0136 };
0137 
0138 /// @brief  An indexed surface implementation access
0139 ///
0140 /// @tparam grid_type is the grid type used for this indexed lookup
0141 template <typename grid_type>
0142 using IndexedSurfacesNavigation =
0143     IndexedGridNavigation<IInternalNavigation, grid_type,
0144                           IndexedSurfacesExtractor, SurfacesFiller>;
0145 
0146 /// @brief  An indexed multi layer surface implementation access
0147 ///
0148 /// @tparam grid_type is the grid type used for this indexed lookup
0149 template <typename grid_type>
0150 using MultiLayerSurfacesNavigation =
0151     MultiLayerNavigation<grid_type, PathGridSurfacesGenerator>;
0152 
0153 /// @brief An indexed surface implementation with portal access
0154 ///
0155 ///@tparam inexed_updator is the updator for the indexed surfaces
0156 template <typename grid_type, template <typename> class indexed_updator>
0157 using IndexedSurfacesAllPortalsNavigation =
0158     ChainedNavigation<IInternalNavigation, AllPortalsNavigation,
0159                       indexed_updator<grid_type>>;
0160 
0161 }  // namespace Acts::Experimental