Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-21 08:02:03

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/Definitions/Tolerance.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Geometry/Layer.hpp"
0015 #include "Acts/Geometry/Portal.hpp"
0016 #include "Acts/Propagator/NavigationTarget.hpp"
0017 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0018 
0019 #include <span>
0020 #include <vector>
0021 
0022 namespace Acts {
0023 
0024 // To be removed when the namespace Experimental is omitted
0025 namespace Experimental {
0026 class Portal;
0027 }
0028 
0029 class Surface;
0030 
0031 /// The NavigationStream is a container for the navigation candidates that
0032 /// are currentlu processed in a given context. The context could be local to a
0033 /// volume, or global to an entire track following.
0034 ///
0035 /// The current candidates are stored in a vector of candidates, where an index
0036 /// is used to indicate the current active candidate.
0037 class NavigationStream {
0038  public:
0039   /// The query point for the navigation stream
0040   ///
0041   /// This holds the position and direction from which the navigation stream
0042   /// should either be initialized or updated.
0043   struct QueryPoint {
0044     /// The position of the query point
0045     Vector3 position = Vector3::Zero();
0046     /// The direction of the query point
0047     Vector3 direction = Vector3::Zero();
0048   };
0049 
0050   /// Switch to next next candidate
0051   ///
0052   /// @return true if a next candidate is available
0053   bool switchToNextCandidate() {
0054     if (m_currentIndex < m_candidates.size()) {
0055       ++m_currentIndex;
0056       return true;
0057     }
0058     return false;
0059   }
0060 
0061   /// Const access the current candidate
0062   /// @return Const reference to current candidate
0063   const NavigationTarget& currentCandidate() const {
0064     return m_candidates.at(m_currentIndex);
0065   }
0066 
0067   /// Current Index
0068   /// @return Index of the current candidate in the vector
0069   std::size_t currentIndex() const { return m_currentIndex; }
0070 
0071   /// Non-const access the candidate vector
0072   /// @return Mutable reference to vector of navigation candidates
0073   std::vector<NavigationTarget>& candidates() { return m_candidates; }
0074 
0075   /// Const access the candidate vector
0076   /// @return Const reference to vector of navigation candidates
0077   const std::vector<NavigationTarget>& candidates() const {
0078     return m_candidates;
0079   }
0080 
0081   /// Non-const access the current candidate
0082   ///
0083   /// This will throw and out of bounds exception if the stream is not
0084   /// valid anymore.
0085   /// @return Mutable reference to current candidate
0086   NavigationTarget& currentCandidate() {
0087     return m_candidates.at(m_currentIndex);
0088   }
0089 
0090   /// The number of active candidates
0091   /// @return Number of remaining candidates from current position onwards
0092   std::size_t remainingCandidates() const {
0093     return (m_candidates.size() - m_currentIndex);
0094   }
0095 
0096   /// Fill one surface into the candidate vector
0097   ///
0098   /// @param surface the surface to be filled
0099   /// @param bTolerance the boundary tolerance used for the intersection
0100   void addSurfaceCandidate(const Surface& surface,
0101                            const BoundaryTolerance& bTolerance);
0102 
0103   /// Fill n surfaces into the candidate vector
0104   ///
0105   /// @param surfaces the surfaces that are filled in
0106   /// @param bTolerance the boundary tolerance used for the intersection
0107   void addSurfaceCandidates(std::span<const Surface*> surfaces,
0108                             const BoundaryTolerance& bTolerance);
0109 
0110   /// Fill one portal into the candidate vector
0111   ///
0112   /// @param portal Portal to add as candidate
0113   void addPortalCandidate(const Experimental::Portal& portal);
0114   /// @param portal the portals that are filled in
0115 
0116   void addPortalCandidate(const Portal& portal);
0117 
0118   /// Fill n portals into the candidate vector
0119   ///
0120   /// @param portals the portals that are filled in
0121   void addPortalCandidates(std::span<const Experimental::Portal*> portals);
0122 
0123   /// Initialize the stream from a query point
0124   ///
0125   /// @param gctx is the geometry context
0126   /// @param queryPoint holds current position, direction, etc.
0127   /// @param cTolerance is the candidate search tolerance
0128   /// @param onSurfaceTolerance is the tolerance for on-surface intersections
0129   ///
0130   /// This method will first de-duplicate the candidates on basis of the surface
0131   /// pointer to make sure that the multi-intersections are handled correctly.
0132   /// This will allow intializeStream() to be called even as a re-initialization
0133   /// and still work correctly with at one time valid candidates.
0134   ///
0135   /// @return true if the stream is active, false indicates that there are no valid candidates
0136   bool initialize(const GeometryContext& gctx,
0137                   const NavigationStream::QueryPoint& queryPoint,
0138                   const BoundaryTolerance& cTolerance,
0139                   double onSurfaceTolerance = s_onSurfaceTolerance);
0140 
0141   /// Convenience method to update a stream from a new query point,
0142   /// this could be called from navigation delegates that do not require
0143   /// a local state or from the navigator on the target stream
0144   ///
0145   /// @param gctx is the geometry context
0146   /// @param queryPoint holds current position, direction, etc.
0147   /// @param onSurfaceTolerance is the tolerance for on-surface intersections
0148   ///
0149   /// @return true if the stream is active, false indicate no valid candidates left
0150   bool update(const GeometryContext& gctx,
0151               const NavigationStream::QueryPoint& queryPoint,
0152               double onSurfaceTolerance = s_onSurfaceTolerance);
0153 
0154   /// Reset the navigation stream by clearing all candidates and resetting the
0155   /// index.
0156   ///
0157   /// This clears the candidates vector and resets the current index to 0.
0158   void reset();
0159 
0160  private:
0161   /// The candidates of this navigation stream
0162   std::vector<NavigationTarget> m_candidates;
0163 
0164   /// The currently active candidate
0165   std::size_t m_currentIndex = 0u;
0166 };
0167 
0168 class AppendOnlyNavigationStream {
0169  public:
0170   explicit AppendOnlyNavigationStream(NavigationStream& stream);
0171   void addSurfaceCandidate(const Surface& surface,
0172                            const BoundaryTolerance& bTolerance);
0173   void addPortalCandidate(const Portal& portal);
0174 
0175  private:
0176   NavigationStream* m_stream;
0177 };
0178 
0179 }  // namespace Acts