Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:05

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/MultiLayerSurfacesUpdater.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 AllPortalsImpl : public INavigationDelegate {
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           "AllPortalsImpl: 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 AllPortalsAndSurfacesImpl : public INavigationDelegate {
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           "AllPortalsAndSurfacesImpl: no detector volume set to navigation "
0074           "state.");
0075     }
0076     // A volume switch has happened, update list of portals & surfaces
0077     if (nState.surfaceCandidates.empty()) {
0078       // Fill internal portals if existing
0079       for (const auto v : nState.currentVolume->volumes()) {
0080         const auto& iPortals = v->portals();
0081         PortalsFiller::fill(nState, iPortals);
0082       }
0083       // Assign the new volume
0084       const auto& portals = nState.currentVolume->portals();
0085       const auto& surfaces = nState.currentVolume->surfaces();
0086       PortalsFiller::fill(nState, portals);
0087       SurfacesFiller::fill(nState, surfaces);
0088     }
0089     // Update internal candidates
0090     updateCandidates(gctx, nState);
0091   }
0092 };
0093 
0094 /// Generate a provider for all portals
0095 ///
0096 /// @return a connected navigationstate updator
0097 inline static SurfaceCandidatesUpdater tryAllPortals() {
0098   auto ap = std::make_unique<const AllPortalsImpl>();
0099   SurfaceCandidatesUpdater nStateUpdater;
0100   nStateUpdater.connect<&AllPortalsImpl::update>(std::move(ap));
0101   return nStateUpdater;
0102 }
0103 
0104 /// Generate a provider for all portals and Surfacess
0105 ///
0106 /// @note this is a try-and error navigation, not recommended for production
0107 /// setup with many surfaces
0108 ///
0109 /// @return a connected navigationstate updator
0110 inline static SurfaceCandidatesUpdater tryAllPortalsAndSurfaces() {
0111   auto aps = std::make_unique<const AllPortalsAndSurfacesImpl>();
0112   SurfaceCandidatesUpdater nStateUpdater;
0113   nStateUpdater.connect<&AllPortalsAndSurfacesImpl::update>(std::move(aps));
0114   return nStateUpdater;
0115 }
0116 
0117 /// @brief This holds and extracts a collection of surfaces without much
0118 /// checking, this could be e.g. support surfaces for layer structures,
0119 /// e.g.
0120 ///
0121 struct AdditionalSurfacesImpl : public INavigationDelegate {
0122   /// The volumes held by this collection
0123   std::vector<const Surface*> surfaces = {};
0124 
0125   /// Extract the sub volumes from the volume
0126   ///
0127   /// @param gctx the geometry contextfor this extraction call (ignored)
0128   /// @param nState is the navigation state
0129   ///
0130   inline void update([[maybe_unused]] const GeometryContext& gctx,
0131                      NavigationState& nState) const {
0132     SurfacesFiller::fill(nState, surfaces);
0133   }
0134 };
0135 
0136 /// @brief  An indexed surface implementation access
0137 ///
0138 /// @tparam grid_type is the grid type used for this indexed lookup
0139 template <typename grid_type>
0140 using IndexedSurfacesImpl =
0141     IndexedUpdaterImpl<grid_type, IndexedSurfacesExtractor, SurfacesFiller>;
0142 
0143 /// @brief  An indexed multi layer surface implementation access
0144 ///
0145 /// @tparam grid_type is the grid type used for this indexed lookup
0146 template <typename grid_type>
0147 using MultiLayerSurfacesImpl =
0148     MultiLayerSurfacesUpdaterImpl<grid_type, PathGridSurfacesGenerator>;
0149 
0150 /// @brief An indexed surface implementation with portal access
0151 ///
0152 ///@tparam inexed_updator is the updator for the indexed surfaces
0153 template <typename grid_type, template <typename> class indexed_updator>
0154 using IndexedSurfacesAllPortalsImpl =
0155     ChainedUpdaterImpl<AllPortalsImpl, indexed_updator<grid_type>>;
0156 
0157 }  // namespace Acts::Experimental