Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:11:59

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 #include "Acts/Navigation/MultiLayerNavigationPolicy.hpp"
0010 
0011 namespace Acts::Experimental {
0012 
0013 MultiLayerNavigationPolicy::MultiLayerNavigationPolicy(
0014     const GeometryContext& gctx, const TrackingVolume& volume,
0015     const Logger& logger, const Config& config, IndexedUpdatorType grid)
0016     : m_volume(volume), m_indexedGrid(std::move(grid)) {
0017   ACTS_VERBOSE("Constructing MultiLayerNavigationPolicy for volume "
0018                << m_volume.volumeName());
0019 
0020   // Fill the grid with surfaces
0021   std::vector<std::shared_ptr<const Surface>> surfaces = {};
0022   for (const auto& surface : m_volume.surfaces()) {
0023     if (surface.associatedDetectorElement() == nullptr) {
0024       continue;
0025     }
0026     surfaces.push_back(surface.getSharedPtr());
0027   }
0028 
0029   Experimental::detail::CenterReferenceGenerator rGenerator;
0030   Experimental::detail::IndexedGridFiller filler{config.binExpansion};
0031   filler.fill(gctx, m_indexedGrid, surfaces, rGenerator, {});
0032 }
0033 
0034 void MultiLayerNavigationPolicy::initializeCandidates(
0035     const NavigationArguments& args, AppendOnlyNavigationStream& stream,
0036     const Logger& logger) const {
0037   ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates initialization for volume"
0038                << m_volume.volumeName());
0039   const Transform3& itransform = m_volume.itransform();
0040   const Vector3 locPosition = itransform * args.position;
0041   const Vector3 locDirection = itransform * args.direction;
0042 
0043   std::vector<Vector2> path = generatePath(locPosition, locDirection);
0044 
0045   const auto& surfaces = m_volume.surfaces();
0046   std::vector<const Surface*> surfCandidates = {};
0047   surfCandidates.reserve(surfaces.size());
0048 
0049   for (const auto& pos : path) {
0050     std::vector<std::size_t> indices = m_indexedGrid.grid.atPosition(pos);
0051 
0052     std::ranges::transform(indices, std::back_inserter(surfCandidates),
0053                            [&](const auto& i) { return &surfaces[i]; });
0054   }
0055 
0056   ACTS_VERBOSE("MultiLayerNavigationPolicy Candidates reported"
0057                << surfCandidates.size() << " candidates");
0058 
0059   // fill the navigation stream with the container
0060   for (const auto* surf : surfCandidates) {
0061     stream.addSurfaceCandidate(*surf, args.tolerance);
0062   }
0063 }
0064 
0065 std::vector<Vector2> MultiLayerNavigationPolicy::generatePath(
0066     const Vector3& startPosition, const Vector3& direction) const {
0067   std::vector<Vector2> path;
0068 
0069   auto maxXIndex = m_indexedGrid.grid.numLocalBins()[0];
0070   auto maxYIndex = m_indexedGrid.grid.numLocalBins()[1];
0071   Vector3 unitDir = direction.normalized();
0072 
0073   for (std::size_t i = 0; i < maxYIndex; i++) {
0074     auto v1 = m_indexedGrid.grid.lowerLeftBinEdge({1, i + 1});
0075     auto v2 = m_indexedGrid.grid.upperRightBinEdge({maxXIndex, i + 1});
0076 
0077     auto intersection = Acts::detail::IntersectionHelper2D::intersectSegment(
0078         Vector2(v1[0], v1[1]), Vector2(v2[0], v2[1]),
0079         startPosition.template block<2, 1>(0, 0),
0080         unitDir.template block<2, 1>(0, 0));
0081     if (!intersection.isValid()) {
0082       continue;
0083     }
0084 
0085     path.push_back(intersection.position());
0086   }
0087   return path;
0088 }
0089 
0090 }  // namespace Acts::Experimental