Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:12:56

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