Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-05 08:29:31

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