Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:22:28

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/IndexGrid.hpp"
0012 #include "Acts/Geometry/ReferenceGenerators.hpp"
0013 #include "Acts/Geometry/TrackingVolume.hpp"
0014 #include "Acts/Navigation/INavigationPolicy.hpp"
0015 #include "Acts/Navigation/NavigationStream.hpp"
0016 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0017 #include "Acts/Utilities/Grid.hpp"
0018 #include "Acts/Utilities/GridAccessHelpers.hpp"
0019 #include "Acts/Utilities/ProtoAxis.hpp"
0020 
0021 namespace Acts {
0022 
0023 class IndexGridNavigationConfig {
0024  public:
0025   /// The binning expansion for grid neighbor lookups
0026   std::vector<std::size_t> binExpansion = {0u, 0u};
0027 
0028   /// The reference expansion
0029   std::vector<double> referenceExpansion = {};
0030 
0031   /// A potential lookup surface - this would be intersected first,
0032   /// assumption is always closest forward
0033   std::shared_ptr<Surface> surface = nullptr;
0034 
0035   /// The reference generator
0036   std::shared_ptr<IReferenceGenerator> referenceGenerator =
0037       std::make_shared<PolyhedronReferenceGenerator>();
0038 };
0039 
0040 /// A navigation policy that uses grid based navigation for indexed surfaces
0041 /// Navigate through a multilayer structure by creating an artificial path on
0042 /// the grid.
0043 template <typename GridType>
0044 class IndexGridNavigationPolicy : public INavigationPolicy {
0045  public:
0046   using IndexGridType = IndexGrid<GridType>;
0047 
0048   /// Main constructor, which expects the grid and will fill it with the
0049   /// surfaces from the volume passed
0050   /// @note Expects that the grid is defined but not filled - it will be filled here with the surfaces assigned to the @p volume
0051   /// @param gctx The geometrycontext object
0052   /// @param volume The tracking volume holding the surfaces that will be the indexed objects
0053   /// @param logger A logging instance
0054   /// @param config The configuration of the Navigation Policy
0055   /// @param grid The index grid to use for navigation
0056   explicit IndexGridNavigationPolicy(const GeometryContext& gctx,
0057                                      const TrackingVolume& volume,
0058                                      const Logger& logger,
0059                                      const IndexGridNavigationConfig& config,
0060                                      const IndexGridType& grid)
0061       : m_cfg(config), m_volume(volume), m_indexGrid(grid) {
0062     ACTS_VERBOSE("Constructing IndexGridNavigationPolicy for volume '"
0063                  << m_volume.volumeName() << "'");
0064 
0065     // Fill the grid with the surfaces from the volume
0066     IndexGridFiller filler{m_cfg.binExpansion, m_cfg.referenceExpansion,
0067                            getDefaultLogger("IndexGridFiller", logger.level())};
0068     const auto& surfaces = m_volume.surfaces();
0069     // Fill the grid with surfaces
0070     std::vector<std::shared_ptr<const Surface>> surfacePtrs = {};
0071     surfacePtrs.reserve(surfaces.size());
0072     for (const auto& surface : surfaces) {
0073       surfacePtrs.push_back(surface.getSharedPtr());
0074     }
0075     filler.fill(gctx, m_indexGrid, surfacePtrs, *m_cfg.referenceGenerator);
0076   }
0077 
0078   /// Update the navigation state from the surface array
0079   /// @param gctx the geometry context
0080   /// @param args The navigation arguments
0081   /// @param stream The navigation stream to update
0082   /// @param logger The logger
0083   void initializeCandidates(const GeometryContext& gctx,
0084                             const NavigationArguments& args,
0085                             AppendOnlyNavigationStream& stream,
0086                             const Logger& logger) const {
0087     ACTS_VERBOSE(
0088         "IndexGridNavigationPolicy: candidates initialization for volume '"
0089         << m_volume.volumeName() << "'");
0090 
0091     // Nominal or intersected position
0092     Vector3 position = args.position;
0093     if (m_cfg.surface) {
0094       auto multiIntersection = m_cfg.surface->intersect(
0095           gctx, position, args.direction, BoundaryTolerance::Infinite());
0096       position = multiIntersection.closestForward().position();
0097     }
0098 
0099     // The indexing is guaranteed
0100     const auto& surfaces = m_volume.surfaces();
0101     const auto& indices =
0102         m_indexGrid.grid.atPosition(GridAccessHelpers::castPosition<GridType>(
0103             m_indexGrid.transform * position, m_indexGrid.casts));
0104     // Fill the navigation stream with the container
0105     for (const auto& idx : indices) {
0106       stream.addSurfaceCandidate(surfaces[idx], args.tolerance);
0107     }
0108   }
0109 
0110   /// Connect this policy with a navigation delegate
0111   /// @param delegate The navigation delegate to connect to
0112   void connect(NavigationDelegate& delegate) const override {
0113     connectDefault<IndexGridNavigationPolicy>(delegate);
0114   }
0115 
0116   /// @brief  Give const access to the index grid
0117   /// @return
0118   const IndexGridType& indexGrid() const { return m_indexGrid; }
0119 
0120  private:
0121   // Keep the config
0122   IndexGridNavigationConfig m_cfg;
0123   // The tracking volume
0124   const TrackingVolume& m_volume;
0125   // The index grid
0126   IndexGridType m_indexGrid;
0127 };
0128 
0129 // Regular cylinder is in z and phi
0130 using RegularCylinderIndexGrid =
0131     Grid<std::vector<std::size_t>,
0132          Axis<AxisType::Equidistant, AxisBoundaryType::Bound>,
0133          Axis<AxisType::Equidistant, AxisBoundaryType::Closed>>;
0134 using RegularCylinderIndexGridNavigationPolicy =
0135     IndexGridNavigationPolicy<RegularCylinderIndexGrid>;
0136 
0137 static_assert(
0138     NavigationPolicyConcept<RegularCylinderIndexGridNavigationPolicy>);
0139 
0140 // Regular ring in phi
0141 using RegularRingIndexGrid =
0142     Grid<std::vector<std::size_t>,
0143          Axis<AxisType::Equidistant, AxisBoundaryType::Closed>>;
0144 using RegularRingIndexGridNavigationPolicy =
0145     IndexGridNavigationPolicy<RegularRingIndexGrid>;
0146 
0147 // Regular disc is in r and phi
0148 using RegularDiscIndexGrid =
0149     Grid<std::vector<std::size_t>,
0150          Axis<AxisType::Equidistant, AxisBoundaryType::Bound>,
0151          Axis<AxisType::Equidistant, AxisBoundaryType::Closed>>;
0152 using RegularDiscIndexGridNavigationPolicy =
0153     IndexGridNavigationPolicy<RegularDiscIndexGrid>;
0154 
0155 static_assert(NavigationPolicyConcept<RegularDiscIndexGridNavigationPolicy>);
0156 
0157 // Regular planar grid is in x and y
0158 using RegularPlaneIndexGrid =
0159     Grid<std::vector<std::size_t>,
0160          Axis<AxisType::Equidistant, AxisBoundaryType::Bound>,
0161          Axis<AxisType::Equidistant, AxisBoundaryType::Bound>>;
0162 using RegularPlaneIndexGridNavigationPolicy =
0163     IndexGridNavigationPolicy<RegularPlaneIndexGrid>;
0164 static_assert(NavigationPolicyConcept<RegularPlaneIndexGridNavigationPolicy>);
0165 
0166 }  // namespace Acts