Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:45:47

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/Geometry/BoundarySurfaceT.hpp"
0012 #include "Acts/Geometry/Portal.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Utilities/Intersection.hpp"
0015 
0016 #include <cstddef>
0017 #include <variant>
0018 
0019 namespace Acts {
0020 
0021 /// @brief The navigation target
0022 ///
0023 /// This struct represents a navigation target which is communicated from the
0024 /// navigator to the stepper through the propagator.
0025 ///
0026 /// @note This incorporates `std::optional` semantics as the next target might
0027 ///       not exist.
0028 class NavigationTarget {
0029  public:
0030   /// Type alias for the intersection object
0031   using Intersection = Intersection3D;
0032   /// Type alias for the intersection position
0033   using Position = Intersection::Position;
0034 
0035   /// Create a surface intersection from a 3D intersection, intersection index,
0036   /// and a surface
0037   ///
0038   /// @param intersection is the intersection
0039   /// @param intersectionIndex is the intersection index
0040   /// @param target is the intersected target
0041   /// @param boundaryTolerance is the boundary tolerance used for this
0042   /// intersection
0043   constexpr NavigationTarget(
0044       const Intersection3D& intersection, IntersectionIndex intersectionIndex,
0045       const Surface& target,
0046       const BoundaryTolerance& boundaryTolerance) noexcept
0047       : m_intersection(intersection),
0048         m_intersectionIndex(intersectionIndex),
0049         m_target(&target),
0050         m_surfaceRepresentation(&target),
0051         m_boundaryTolerance(boundaryTolerance) {}
0052 
0053   /// Create a layer intersection from a 3D intersection, intersection index,
0054   /// and a layer
0055   ///
0056   /// @param intersection is the intersection
0057   /// @param intersectionIndex is the intersection index
0058   /// @param target is the intersected target
0059   /// @param surfaceRepresentation is the surface representation of the layer
0060   /// @param boundaryTolerance is the boundary tolerance used for this
0061   /// intersection
0062   constexpr NavigationTarget(
0063       const Intersection3D& intersection, IntersectionIndex intersectionIndex,
0064       const Layer& target, const Surface& surfaceRepresentation,
0065       const BoundaryTolerance& boundaryTolerance) noexcept
0066       : m_intersection(intersection),
0067         m_intersectionIndex(intersectionIndex),
0068         m_target(&target),
0069         m_surfaceRepresentation(&surfaceRepresentation),
0070         m_boundaryTolerance(boundaryTolerance) {}
0071 
0072   /// Create a boundary surface intersection from a 3D intersection,
0073   /// intersection index, and a boundary surface
0074   ///
0075   /// @param intersection is the intersection
0076   /// @param intersectionIndex is the intersection index
0077   /// @param target is the intersected target
0078   /// @param boundaryTolerance is the boundary tolerance used for this
0079   /// intersection
0080   constexpr NavigationTarget(
0081       const Intersection3D& intersection, IntersectionIndex intersectionIndex,
0082       const BoundarySurface& target,
0083       const BoundaryTolerance& boundaryTolerance) noexcept
0084       : m_intersection(intersection),
0085         m_intersectionIndex(intersectionIndex),
0086         m_target(&target),
0087         m_surfaceRepresentation(&target.surfaceRepresentation()),
0088         m_boundaryTolerance(boundaryTolerance) {}
0089 
0090   /// Create a portal intersection from a 3D intersection, intersection index,
0091   /// and a portal
0092   ///
0093   /// @param intersection is the intersection
0094   /// @param intersectionIndex is the intersection index
0095   /// @param target is the intersected target
0096   /// @param boundaryTolerance is the boundary tolerance used for this
0097   /// intersection
0098   NavigationTarget(const Intersection3D& intersection,
0099                    IntersectionIndex intersectionIndex, const Portal& target,
0100                    const BoundaryTolerance& boundaryTolerance) noexcept
0101       : m_intersection(intersection),
0102         m_intersectionIndex(intersectionIndex),
0103         m_target(&target),
0104         m_surfaceRepresentation(&target.surface()),
0105         m_boundaryTolerance(boundaryTolerance) {}
0106 
0107   /// Copy constructor
0108   constexpr NavigationTarget(const NavigationTarget&) noexcept = default;
0109 
0110   /// Move constructor
0111   constexpr NavigationTarget(NavigationTarget&&) noexcept = default;
0112 
0113   /// Copy assignment operator
0114   /// @return Reference to this object
0115   constexpr NavigationTarget& operator=(const NavigationTarget&) noexcept =
0116       default;
0117 
0118   /// Move assignment operator
0119   /// @return Reference to this object
0120   constexpr NavigationTarget& operator=(NavigationTarget&&) noexcept = default;
0121 
0122   /// Returns the intersection
0123   /// @return the intersection
0124   constexpr const Intersection3D& intersection() const {
0125     return m_intersection;
0126   }
0127 
0128   /// Mutable access to the intersection
0129   /// @return the intersection
0130   constexpr Intersection3D& intersection() { return m_intersection; }
0131 
0132   /// Returns the intersection index
0133   /// @return the intersection index
0134   constexpr IntersectionIndex intersectionIndex() const noexcept {
0135     return m_intersectionIndex;
0136   }
0137 
0138   /// Mutable access to the intersection index
0139   /// @return the intersection index
0140   constexpr IntersectionIndex& intersectionIndex() noexcept {
0141     return m_intersectionIndex;
0142   }
0143 
0144   /// Returns the surface that has been intersected
0145   /// @return the surface
0146   constexpr const Surface& surface() const noexcept {
0147     return *m_surfaceRepresentation;
0148   }
0149 
0150   /// Returns the layer that has been intersected
0151   /// @return the layer
0152   constexpr const Layer& layer() const {
0153     return *std::get<const Layer*>(m_target);
0154   }
0155 
0156   /// Returns the boundary surface that has been intersected
0157   /// @return the boundary surface
0158   constexpr const BoundarySurface& boundarySurface() const {
0159     return *std::get<const BoundarySurface*>(m_target);
0160   }
0161 
0162   /// Returns the portal that has been intersected
0163   /// @return the portal
0164   constexpr const Portal& portal() const {
0165     return *std::get<const Portal*>(m_target);
0166   }
0167 
0168   /// Returns whether the target is a surface
0169   /// @return true if the target is a surface
0170   constexpr bool isSurfaceTarget() const noexcept {
0171     return std::holds_alternative<const Surface*>(m_target);
0172   }
0173 
0174   /// Returns whether the target is a layer
0175   /// @return true if the target is a layer
0176   constexpr bool isLayerTarget() const noexcept {
0177     return std::holds_alternative<const Layer*>(m_target);
0178   }
0179 
0180   /// Returns whether the target is a portal
0181   /// @return true if the target is a portal
0182   constexpr bool isPortalTarget() const noexcept {
0183     return std::holds_alternative<const BoundarySurface*>(m_target) ||
0184            std::holds_alternative<const Portal*>(m_target);
0185   }
0186 
0187   /// Returns the boundary tolerance used for this intersection
0188   /// @return the boundary tolerance
0189   constexpr const BoundaryTolerance& boundaryTolerance() const noexcept {
0190     return m_boundaryTolerance;
0191   }
0192 
0193   /// Returns whether the intersection was successful or not
0194   /// @return true if the intersection is valid
0195   constexpr bool isValid() const noexcept { return m_intersection.isValid(); }
0196 
0197   /// Returns the position of the interseciton
0198   /// @return the position
0199   Position position() const noexcept { return m_intersection.position(); }
0200 
0201   /// Returns the path length to the interseciton
0202   /// @return the path length
0203   constexpr double pathLength() const noexcept {
0204     return m_intersection.pathLength();
0205   }
0206 
0207   /// Returns the status of the interseciton
0208   /// @return the status
0209   constexpr IntersectionStatus status() const noexcept {
0210     return m_intersection.status();
0211   }
0212 
0213   /// Returns whether this is a none target
0214   /// @return true if this is a none target
0215   constexpr bool isNone() const noexcept {
0216     return std::holds_alternative<std::monostate>(m_target);
0217   }
0218 
0219   /// Factory method to create a none target
0220   /// @return a none target
0221   constexpr static NavigationTarget None() noexcept {
0222     return NavigationTarget();
0223   }
0224 
0225   /// Comparison operator by path length
0226   /// @param aIntersection First navigation target
0227   /// @param bIntersection Second navigation target
0228   /// @return true if aIntersection is before bIntersection
0229   constexpr static bool pathLengthOrder(
0230       const NavigationTarget& aIntersection,
0231       const NavigationTarget& bIntersection) noexcept {
0232     return Intersection3D::pathLengthOrder(aIntersection.intersection(),
0233                                            bIntersection.intersection());
0234   }
0235 
0236   /// Comparison operator by closest distance to the reference point
0237   /// @param aIntersection First navigation target
0238   /// @param bIntersection Second navigation target
0239   /// @return true if aIntersection is closer than bIntersection
0240   constexpr static bool closestOrder(
0241       const NavigationTarget& aIntersection,
0242       const NavigationTarget& bIntersection) noexcept {
0243     return Intersection3D::closestOrder(aIntersection.intersection(),
0244                                         bIntersection.intersection());
0245   }
0246 
0247   /// Comparison operator by closest distance to the reference point in the
0248   /// @param aIntersection First navigation target
0249   /// @param bIntersection Second navigation target
0250   /// @return true if aIntersection is closer than bIntersection
0251   constexpr static bool closestForwardOrder(
0252       const NavigationTarget& aIntersection,
0253       const NavigationTarget& bIntersection) noexcept {
0254     return Intersection3D::closestForwardOrder(aIntersection.intersection(),
0255                                                bIntersection.intersection());
0256   }
0257   /// @brief Define the ostream operator to print the object
0258   /// @param ostr: Reference to the ostream
0259   /// @param target: Reference to the target to print
0260   friend std::ostream& operator<<(std::ostream& ostr,
0261                                   const NavigationTarget& target) {
0262     target.print(ostr);
0263     return ostr;
0264   }
0265 
0266  private:
0267   /// Alias for the target variant
0268   using TargetVariant =
0269       std::variant<std::monostate, const Surface*, const Layer*,
0270                    const BoundarySurface*, const Portal*>;
0271 
0272   /// The intersection itself
0273   Intersection3D m_intersection = Intersection3D::Invalid();
0274   /// The intersection index
0275   IntersectionIndex m_intersectionIndex = 0;
0276   /// The target that was intersected
0277   TargetVariant m_target;
0278   /// The surface representation of the target
0279   const Surface* m_surfaceRepresentation = nullptr;
0280   /// The boundary tolerance used for this intersection
0281   BoundaryTolerance m_boundaryTolerance = BoundaryTolerance::None();
0282 
0283   /// Default constructor creating a none target
0284   constexpr NavigationTarget() = default;
0285 
0286   /// @brief print method
0287   /// @param ostr: Stream to which the object is printed
0288   void print(std::ostream& ostr) const;
0289 };
0290 
0291 static_assert(std::is_trivially_copy_constructible_v<NavigationTarget>);
0292 static_assert(std::is_trivially_move_constructible_v<NavigationTarget>);
0293 static_assert(std::is_trivially_move_assignable_v<NavigationTarget>);
0294 
0295 }  // namespace Acts