Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:24:02

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   constexpr NavigationTarget& operator=(const NavigationTarget&) noexcept =
0115       default;
0116 
0117   /// Move assignment operator
0118   constexpr NavigationTarget& operator=(NavigationTarget&&) noexcept = default;
0119 
0120   /// Returns the intersection
0121   /// @return the intersection
0122   constexpr const Intersection3D& intersection() const {
0123     return m_intersection;
0124   }
0125 
0126   /// Mutable access to the intersection
0127   /// @return the intersection
0128   constexpr Intersection3D& intersection() { return m_intersection; }
0129 
0130   /// Returns the intersection index
0131   /// @return the intersection index
0132   constexpr IntersectionIndex intersectionIndex() const noexcept {
0133     return m_intersectionIndex;
0134   }
0135 
0136   /// Mutable access to the intersection index
0137   /// @return the intersection index
0138   constexpr IntersectionIndex& intersectionIndex() noexcept {
0139     return m_intersectionIndex;
0140   }
0141 
0142   /// Returns the surface that has been intersected
0143   /// @return the surface
0144   constexpr const Surface& surface() const noexcept {
0145     return *m_surfaceRepresentation;
0146   }
0147 
0148   /// Returns the layer that has been intersected
0149   /// @return the layer
0150   constexpr const Layer& layer() const {
0151     return *std::get<const Layer*>(m_target);
0152   }
0153 
0154   /// Returns the boundary surface that has been intersected
0155   /// @return the boundary surface
0156   constexpr const BoundarySurface& boundarySurface() const {
0157     return *std::get<const BoundarySurface*>(m_target);
0158   }
0159 
0160   /// Returns the portal that has been intersected
0161   /// @return the portal
0162   constexpr const Portal& portal() const {
0163     return *std::get<const Portal*>(m_target);
0164   }
0165 
0166   /// Returns whether the target is a surface
0167   /// @return true if the target is a surface
0168   constexpr bool isSurfaceTarget() const noexcept {
0169     return std::holds_alternative<const Surface*>(m_target);
0170   }
0171 
0172   /// Returns whether the target is a layer
0173   /// @return true if the target is a layer
0174   constexpr bool isLayerTarget() const noexcept {
0175     return std::holds_alternative<const Layer*>(m_target);
0176   }
0177 
0178   /// Returns whether the target is a portal
0179   /// @return true if the target is a portal
0180   constexpr bool isPortalTarget() const noexcept {
0181     return std::holds_alternative<const BoundarySurface*>(m_target) ||
0182            std::holds_alternative<const Portal*>(m_target);
0183   }
0184 
0185   /// Returns the boundary tolerance used for this intersection
0186   /// @return the boundary tolerance
0187   constexpr const BoundaryTolerance& boundaryTolerance() const noexcept {
0188     return m_boundaryTolerance;
0189   }
0190 
0191   /// Returns whether the intersection was successful or not
0192   /// @return true if the intersection is valid
0193   constexpr bool isValid() const noexcept { return m_intersection.isValid(); }
0194 
0195   /// Returns the position of the interseciton
0196   /// @return the position
0197   Position position() const noexcept { return m_intersection.position(); }
0198 
0199   /// Returns the path length to the interseciton
0200   /// @return the path length
0201   constexpr double pathLength() const noexcept {
0202     return m_intersection.pathLength();
0203   }
0204 
0205   /// Returns the status of the interseciton
0206   /// @return the status
0207   constexpr IntersectionStatus status() const noexcept {
0208     return m_intersection.status();
0209   }
0210 
0211   /// Returns whether this is a none target
0212   /// @return true if this is a none target
0213   constexpr bool isNone() const noexcept {
0214     return std::holds_alternative<std::monostate>(m_target);
0215   }
0216 
0217   /// Factory method to create a none target
0218   /// @return a none target
0219   constexpr static NavigationTarget None() noexcept {
0220     return NavigationTarget();
0221   }
0222 
0223   /// Comparison operator by path length
0224   /// @return true if aIntersection is before bIntersection
0225   constexpr static bool pathLengthOrder(
0226       const NavigationTarget& aIntersection,
0227       const NavigationTarget& bIntersection) noexcept {
0228     return Intersection3D::pathLengthOrder(aIntersection.intersection(),
0229                                            bIntersection.intersection());
0230   }
0231 
0232   /// Comparison operator by closest distance to the reference point
0233   /// @return true if aIntersection is closer than bIntersection
0234   constexpr static bool closestOrder(
0235       const NavigationTarget& aIntersection,
0236       const NavigationTarget& bIntersection) noexcept {
0237     return Intersection3D::closestOrder(aIntersection.intersection(),
0238                                         bIntersection.intersection());
0239   }
0240 
0241   /// Comparison operator by closest distance to the reference point in the
0242   /// @return true if aIntersection is closer than bIntersection
0243   constexpr static bool closestForwardOrder(
0244       const NavigationTarget& aIntersection,
0245       const NavigationTarget& bIntersection) noexcept {
0246     return Intersection3D::closestForwardOrder(aIntersection.intersection(),
0247                                                bIntersection.intersection());
0248   }
0249 
0250  private:
0251   /// Alias for the target variant
0252   using TargetVariant =
0253       std::variant<std::monostate, const Surface*, const Layer*,
0254                    const BoundarySurface*, const Portal*>;
0255 
0256   /// The intersection itself
0257   Intersection3D m_intersection = Intersection3D::Invalid();
0258   /// The intersection index
0259   IntersectionIndex m_intersectionIndex = 0;
0260   /// The target that was intersected
0261   TargetVariant m_target;
0262   /// The surface representation of the target
0263   const Surface* m_surfaceRepresentation = nullptr;
0264   /// The boundary tolerance used for this intersection
0265   BoundaryTolerance m_boundaryTolerance = BoundaryTolerance::None();
0266 
0267   /// Default constructor creating a none target
0268   constexpr NavigationTarget() = default;
0269 };
0270 
0271 static_assert(std::is_trivially_copy_constructible_v<NavigationTarget>);
0272 static_assert(std::is_trivially_move_constructible_v<NavigationTarget>);
0273 static_assert(std::is_trivially_move_assignable_v<NavigationTarget>);
0274 
0275 }  // namespace Acts