Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-04 09:10:15

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/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/detail/IndexedGridFiller.hpp"
0013 #include "Acts/Navigation/InternalNavigation.hpp"
0014 #include "Acts/Utilities/Enumerate.hpp"
0015 
0016 #include <algorithm>
0017 #include <array>
0018 #include <memory>
0019 
0020 namespace Acts::detail::IndexedSurfacesGenerator {
0021 
0022 /// Factory method to create a 1D indexed surface grid
0023 ///
0024 /// @param gctx the geometry context
0025 /// @param surfaces the surfaces to be indexed
0026 /// @param rGenerator the reference generator
0027 /// @param pAxis the proto axis (directed)
0028 /// @param pFillExpansion the fill expansion
0029 /// @param assignToAll the indices assigned to all bins
0030 /// @param transform the transform into the local binning schema
0031 /// @return an internal navigation delegate
0032 template <template <typename> class indexed_updator, typename surface_container,
0033           typename reference_generator>
0034 Experimental::InternalNavigationDelegate createInternalNavigation(
0035     const GeometryContext& gctx, const surface_container& surfaces,
0036     const reference_generator& rGenerator, const DirectedProtoAxis& pAxis,
0037     std::size_t pFillExpansion, const std::vector<std::size_t> assignToAll = {},
0038     const Transform3 transform = Transform3::Identity()) {
0039   // Let the axis create the grid
0040   return pAxis.getAxis().visit([&]<typename AxisTypeA>(const AxisTypeA& axis) {
0041     Grid<std::vector<std::size_t>, AxisTypeA> grid(axis);
0042 
0043     // Prepare the indexed updator
0044     std::array<AxisDirection, 1u> axisDirs = {pAxis.getAxisDirection()};
0045     indexed_updator<decltype(grid)> indexedSurfaces(std::move(grid), axisDirs,
0046                                                     transform);
0047 
0048     // Prepare the filling
0049     Experimental::InternalNavigationDelegate nStateUpdater;
0050 
0051     std::vector<std::size_t> fillExpansion = {pFillExpansion};
0052     Experimental::detail::IndexedGridFiller filler{fillExpansion};
0053     filler.fill(gctx, indexedSurfaces, surfaces, rGenerator, assignToAll);
0054 
0055     // The portal delegate
0056     Experimental::AllPortalsNavigation allPortals;
0057 
0058     // The chained delegate: indexed surfaces and all portals
0059     using DelegateType =
0060         Experimental::IndexedSurfacesAllPortalsNavigation<decltype(grid),
0061                                                           indexed_updator>;
0062     auto indexedSurfacesAllPortals = std::make_unique<const DelegateType>(
0063         std::tie(allPortals, indexedSurfaces));
0064 
0065     // Create the delegate and connect it
0066     nStateUpdater.connect<&DelegateType::update>(
0067         std::move(indexedSurfacesAllPortals));
0068 
0069     return nStateUpdater;
0070   });
0071 }
0072 
0073 /// Factory method to create a 2D indexed surface grid
0074 ///
0075 /// @param gctx the geometry context
0076 /// @param surfaces the surfaces to be indexed
0077 /// @param rGenerator the reference generator
0078 /// @param pAxisA the first proto axis (directed)
0079 /// @param fillExpansionA the fill expansion of the first axis
0080 /// @param pAxisB the second proto axis (directed)
0081 /// @param fillExpansionB the fill expansion of the second axis
0082 /// @param assignToAll the indices assigned to all bins
0083 /// @param transform the transform into the local binning schema
0084 ///
0085 /// @return an internal navigation delegate
0086 template <template <typename> class indexed_updator, typename surface_container,
0087           typename reference_generator>
0088 Experimental::InternalNavigationDelegate createInternalNavigation(
0089     const GeometryContext& gctx, const surface_container& surfaces,
0090     const reference_generator& rGenerator, const DirectedProtoAxis& pAxisA,
0091     std::size_t fillExpansionA, const DirectedProtoAxis& pAxisB,
0092     std::size_t fillExpansionB, const std::vector<std::size_t> assignToAll = {},
0093     const Transform3 transform = Transform3::Identity()) {
0094   // Let the axes create the grid
0095   return pAxisA.getAxis().visit([&]<typename AxisTypeA>(
0096                                     const AxisTypeA& axisA) {
0097     return pAxisB.getAxis().visit([&]<typename AxisTypeB>(
0098                                       const AxisTypeB& axisB) {
0099       Grid<std::vector<std::size_t>, AxisTypeA, AxisTypeB> grid(axisA, axisB);
0100       Experimental::InternalNavigationDelegate nStateUpdater;
0101 
0102       // Prepare the indexed updator
0103       std::array<AxisDirection, 2u> axisDirs = {pAxisA.getAxisDirection(),
0104                                                 pAxisB.getAxisDirection()};
0105       indexed_updator<decltype(grid)> indexedSurfaces(std::move(grid), axisDirs,
0106                                                       transform);
0107 
0108       std::vector<std::size_t> fillExpansion = {fillExpansionA, fillExpansionB};
0109 
0110       Experimental::detail::IndexedGridFiller filler{fillExpansion};
0111       filler.fill(gctx, indexedSurfaces, surfaces, rGenerator, assignToAll);
0112 
0113       // The portal delegate
0114       Experimental::AllPortalsNavigation allPortals;
0115 
0116       // The chained delegate: indexed surfaces and all portals
0117       using DelegateType =
0118           Experimental::IndexedSurfacesAllPortalsNavigation<decltype(grid),
0119                                                             indexed_updator>;
0120       auto indexedSurfacesAllPortals = std::make_unique<const DelegateType>(
0121           std::tie(allPortals, indexedSurfaces));
0122 
0123       // Create the delegate and connect it
0124       nStateUpdater.connect<&DelegateType::update>(
0125           std::move(indexedSurfacesAllPortals));
0126 
0127       return nStateUpdater;
0128     });
0129   });
0130 }
0131 
0132 }  // namespace Acts::detail::IndexedSurfacesGenerator