Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Core/include/Acts/Navigation/NavigationStream.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 class Surface;
0025 
0026 /// The NavigationStream is a container for the navigation candidates that
0027 /// are currentlu processed in a given context. The context could be local to a
0028 /// volume, or global to an entire track following.
0029 ///
0030 /// The current candidates are stored in a vector of candidates, where an index
0031 /// is used to indicate the current active candidate.
0032 class NavigationStream {
0033  public:
0034   /// The query point for the navigation stream
0035   ///
0036   /// This holds the position and direction from which the navigation stream
0037   /// should either be initialized or updated.
0038   struct QueryPoint {
0039     /// The position of the query point
0040     Vector3 position = Vector3::Zero();
0041     /// The direction of the query point
0042     Vector3 direction = Vector3::Zero();
0043   };
0044 
0045   /// Switch to next next candidate
0046   ///
0047   /// @return true if a next candidate is available
0048   bool switchToNextCandidate() {
0049     if (!m_currentIndex.has_value()) {
0050       m_currentIndex = 0;
0051     } else {
0052       ++(*m_currentIndex);
0053     }
0054     return isValid();
0055   }
0056   /// Performs the validity check on the navigation current navigation candidate
0057   /// index
0058   /// @return Returns whether the index is initialized and less than the size of the available
0059   ///         candidates
0060   bool isValid() const {
0061     return m_currentIndex.value_or(m_candidates.size()) < m_candidates.size();
0062   }
0063 
0064   /// Const access the current candidate
0065   /// @return Const reference to current candidate
0066   const NavigationTarget& currentCandidate() const {
0067     assert(m_currentIndex != std::nullopt);
0068     return m_candidates.at(*m_currentIndex);
0069   }
0070   /// Preallocate the memory to store a certain amount of candidates
0071   /// @param n: The number of candidates to be stored
0072   void reserve(const std::size_t n) { m_candidates.reserve(n); }
0073 
0074   /// Current Index
0075   /// @return Index of the current candidate in the vector
0076   const std::optional<std::size_t>& currentIndex() const {
0077     return m_currentIndex;
0078   }
0079 
0080   /// Non-const access the candidate vector
0081   /// @return Mutable reference to vector of navigation candidates
0082   std::span<NavigationTarget> candidates() { return m_candidates; }
0083 
0084   /// Const access the candidate vector
0085   /// @return Const reference to vector of navigation candidates
0086   std::span<const NavigationTarget> candidates() const { return m_candidates; }
0087 
0088   /// Non-const access the current candidate
0089   ///
0090   /// This will throw and out of bounds exception if the stream is not
0091   /// valid anymore.
0092   /// @return Mutable reference to current candidate
0093   NavigationTarget& currentCandidate() {
0094     assert(m_currentIndex != std::nullopt);
0095     return m_candidates.at(*m_currentIndex);
0096   }
0097 
0098   /// The number of active candidates
0099   /// @return Number of remaining candidates from current position onwards
0100   std::size_t remainingCandidates() const {
0101     return (m_candidates.size() - m_currentIndex.value_or(0));
0102   }
0103 
0104   /// Fill one surface into the candidate vector
0105   ///
0106   /// @param surface the surface to be filled
0107   /// @param bTolerance the boundary tolerance used for the intersection
0108   void addSurfaceCandidate(const Surface& surface,
0109                            const BoundaryTolerance& bTolerance);
0110 
0111   /// Fill n surfaces into the candidate vector
0112   ///
0113   /// @param surfaces the surfaces that are filled in
0114   /// @param bTolerance the boundary tolerance used for the intersection
0115   void addSurfaceCandidates(std::span<const Surface*> surfaces,
0116                             const BoundaryTolerance& bTolerance);
0117 
0118   /// Fill one portal into the candidate vector
0119   ///
0120   /// @param portal the portals that are filled in
0121   void addPortalCandidate(const Portal& portal);
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 logger is the navigator's logger
0128   /// @param onSurfaceTolerance is the tolerance for on-surface intersections
0129   /// @param candidatesAreUnique the caller guarantees that no surface was
0130   ///        added more than once, so the pre-intersection de-duplication pass
0131   ///        can be skipped. Candidates that intersect the same surface twice
0132   ///        (multi-intersections) are still handled correctly.
0133   ///
0134   /// This method will first de-duplicate the candidates on basis of the surface
0135   /// pointer to make sure that the multi-intersections are handled correctly.
0136   /// This will allow intializeStream() to be called even as a re-initialization
0137   /// and still work correctly with at one time valid candidates.
0138   ///
0139   /// @return true if the stream is active, false indicates that there are no valid candidates
0140   bool initialize(const GeometryContext& gctx,
0141                   const NavigationStream::QueryPoint& queryPoint,
0142                   const Logger& logger,
0143                   double onSurfaceTolerance = s_onSurfaceTolerance,
0144                   bool candidatesAreUnique = false);
0145 
0146   /// Convenience method to update a stream from a new query point,
0147   /// this could be called from navigation delegates that do not require
0148   /// a local state or from the navigator on the target stream
0149   ///
0150   /// @param gctx is the geometry context
0151   /// @param queryPoint holds current position, direction, etc.
0152   /// @param logger is the navigator's logger
0153   /// @param onSurfaceTolerance is the tolerance for on-surface intersections
0154   ///
0155   /// @return true if the stream is active, false indicate no valid candidates left
0156   bool update(const GeometryContext& gctx,
0157               const NavigationStream::QueryPoint& queryPoint,
0158               const Logger& logger,
0159               double onSurfaceTolerance = s_onSurfaceTolerance);
0160 
0161   /// Reset the navigation stream by clearing all candidates and resetting the
0162   /// index.
0163   ///
0164   /// This clears the candidates vector and resets the current index to 0.
0165   /// @param keepBoundLess: Flag to toggle whether unreached boundless
0166   ///                       navigation targets remain in the stream
0167   void reset(const bool keepBoundLess = false);
0168 
0169  private:
0170   /// The candidates of this navigation stream
0171   std::vector<NavigationTarget> m_candidates;
0172 
0173   /// Reusable scratch buffer for the second valid intersection of surfaces with
0174   /// multiple intersections, filled during initialize(). Kept as a member so
0175   /// its heap storage is reused across re-initializations instead of being
0176   /// reallocated every call.
0177   std::vector<NavigationTarget> m_additionalCandidates;
0178 
0179   /// The currently active candidate
0180   std::optional<std::size_t> m_currentIndex{0ul};
0181 };
0182 
0183 /// Append-only helper to add candidates to a navigation stream.
0184 class AppendOnlyNavigationStream {
0185  public:
0186   /// Constructor from navigation stream reference
0187   /// @param stream Navigation stream to append to
0188   explicit AppendOnlyNavigationStream(NavigationStream& stream);
0189   /// Add a surface candidate to the stream
0190   /// @param surface The surface to add
0191   /// @param bTolerance Boundary tolerance for the surface
0192   void addSurfaceCandidate(const Surface& surface,
0193                            const BoundaryTolerance& bTolerance);
0194   /// Add a portal candidate to the stream
0195   /// @param portal The portal to add
0196   void addPortalCandidate(const Portal& portal);
0197 
0198  private:
0199   NavigationStream* m_stream;
0200 };
0201 
0202 }  // namespace Acts