Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:55

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