Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-16 08:02:15

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