File indexing completed on 2026-05-01 07:32:40
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Propagator/ConstrainedStep.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/Enumerate.hpp"
0016 #include "Acts/Utilities/Intersection.hpp"
0017 #include "Acts/Utilities/Logger.hpp"
0018
0019 #include <limits>
0020
0021 namespace Acts {
0022
0023
0024 struct PathLimitReached {
0025
0026 double internalLimit = std::numeric_limits<double>::max();
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 template <typename propagator_state_t, typename stepper_t,
0040 typename navigator_t>
0041 bool checkAbort(propagator_state_t& state, const stepper_t& stepper,
0042 const navigator_t& navigator, const Logger& logger) const {
0043 static_cast<void>(navigator);
0044
0045
0046 double distance =
0047 std::abs(internalLimit) - std::abs(state.stepping.pathAccumulated);
0048 double tolerance = state.options.surfaceTolerance;
0049 bool limitReached = (std::abs(distance) < std::abs(tolerance));
0050 if (limitReached) {
0051 ACTS_VERBOSE("PathLimit aborter | " << "Path limit reached at distance "
0052 << distance);
0053 return true;
0054 }
0055 stepper.updateStepSize(state.stepping, distance,
0056 ConstrainedStep::Type::Actor);
0057 ACTS_VERBOSE("PathLimit aborter | "
0058 << "Target stepSize (path limit) updated to "
0059 << stepper.outputStepSize(state.stepping));
0060 return false;
0061 }
0062 };
0063
0064
0065
0066 struct SurfaceReached {
0067
0068 const Surface* surface = nullptr;
0069
0070 BoundaryTolerance boundaryTolerance = BoundaryTolerance::None();
0071
0072
0073
0074
0075
0076 double nearLimit = -100 * UnitConstants::um;
0077
0078 SurfaceReached() = default;
0079
0080
0081 explicit SurfaceReached(double nLimit) : nearLimit(nLimit) {}
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 template <typename propagator_state_t, typename stepper_t,
0095 typename navigator_t>
0096 bool checkAbort(propagator_state_t& state, const stepper_t& stepper,
0097 const navigator_t& navigator, const Logger& logger) const {
0098 if (surface == nullptr) {
0099 ACTS_VERBOSE("SurfaceReached aborter | Target surface not set.");
0100 return false;
0101 }
0102
0103 if (navigator.currentSurface(state.navigation) == surface) {
0104 ACTS_VERBOSE("SurfaceReached aborter | Target surface reached.");
0105 return true;
0106 }
0107
0108
0109
0110
0111
0112 const double farLimit = std::numeric_limits<double>::max();
0113 const double tolerance = state.options.surfaceTolerance;
0114
0115 const MultiIntersection3D multiIntersection = surface->intersect(
0116 state.geoContext, stepper.position(state.stepping),
0117 state.options.direction * stepper.direction(state.stepping),
0118 boundaryTolerance, tolerance);
0119 const Intersection3D closestIntersection = multiIntersection.closest();
0120
0121 bool reached = false;
0122
0123 if (closestIntersection.status() == IntersectionStatus::onSurface) {
0124 const double distance = closestIntersection.pathLength();
0125 ACTS_VERBOSE(
0126 "SurfaceReached aborter | "
0127 "Target surface reached at distance (tolerance) "
0128 << distance << " (" << tolerance << ")");
0129 reached = true;
0130 }
0131
0132 if (const auto intersectionIt = std::ranges::find_if(
0133 multiIntersection,
0134 [&](const auto& intersection) {
0135 return intersection.isValid() &&
0136 detail::checkPathLength(intersection.pathLength(),
0137 nearLimit, farLimit, logger);
0138 });
0139 intersectionIt != multiIntersection.end()) {
0140 stepper.updateSurfaceStatus(
0141 state.stepping, *surface, intersectionIt - multiIntersection.begin(),
0142 state.options.direction, boundaryTolerance,
0143 state.options.surfaceTolerance, ConstrainedStep::Type::Actor, logger);
0144 ACTS_VERBOSE(
0145 "SurfaceReached aborter | "
0146 "Target stepSize (surface) updated to "
0147 << stepper.outputStepSize(state.stepping));
0148 } else {
0149 ACTS_VERBOSE(
0150 "SurfaceReached aborter | "
0151 "Target intersection not found. Maybe next time?");
0152 }
0153
0154 return reached;
0155 }
0156 };
0157
0158
0159
0160
0161 struct ForcedSurfaceReached : SurfaceReached {
0162 ForcedSurfaceReached()
0163 : SurfaceReached(std::numeric_limits<double>::lowest()) {}
0164 };
0165
0166
0167
0168 struct EndOfWorldReached {
0169
0170
0171
0172
0173
0174
0175
0176
0177 template <typename propagator_state_t, typename stepper_t,
0178 typename navigator_t>
0179 bool checkAbort(propagator_state_t& state, const stepper_t& ,
0180 const navigator_t& navigator,
0181 const Logger& ) const {
0182 bool endOfWorld = navigator.endOfWorldReached(state.navigation);
0183 return endOfWorld;
0184 }
0185 };
0186
0187
0188
0189 struct VolumeConstraintAborter {
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 template <typename propagator_state_t, typename stepper_t,
0200 typename navigator_t>
0201 bool checkAbort(propagator_state_t& state, const stepper_t& ,
0202 const navigator_t& navigator, const Logger& logger) const {
0203 const auto& constrainToVolumeIds = state.options.constrainToVolumeIds;
0204 const auto& endOfWorldVolumeIds = state.options.endOfWorldVolumeIds;
0205
0206 if (constrainToVolumeIds.empty() && endOfWorldVolumeIds.empty()) {
0207 return false;
0208 }
0209 const auto* currentVolume = navigator.currentVolume(state.navigation);
0210
0211
0212 if (currentVolume == nullptr) {
0213 return false;
0214 }
0215
0216 const auto currentVolumeId =
0217 static_cast<std::uint32_t>(currentVolume->geometryId().volume());
0218
0219 if (!constrainToVolumeIds.empty() &&
0220 !rangeContainsValue(constrainToVolumeIds, currentVolumeId)) {
0221 ACTS_VERBOSE(
0222 "VolumeConstraintAborter aborter | Abort with volume constrain "
0223 << currentVolumeId);
0224 return true;
0225 }
0226
0227 if (!endOfWorldVolumeIds.empty() &&
0228 rangeContainsValue(endOfWorldVolumeIds, currentVolumeId)) {
0229 ACTS_VERBOSE(
0230 "VolumeConstraintAborter aborter | Abort with additional end of "
0231 "world volume "
0232 << currentVolumeId);
0233 return true;
0234 }
0235
0236 return false;
0237 }
0238 };
0239
0240
0241 struct AnySurfaceReached {
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 template <typename propagator_state_t, typename stepper_t,
0252 typename navigator_t>
0253 bool checkAbort(propagator_state_t& state, const stepper_t& stepper,
0254 const navigator_t& navigator, const Logger& logger) const {
0255 static_cast<void>(stepper);
0256 static_cast<void>(logger);
0257
0258 const Surface* startSurface = navigator.startSurface(state.navigation);
0259 const Surface* targetSurface = navigator.targetSurface(state.navigation);
0260 const Surface* currentSurface = navigator.currentSurface(state.navigation);
0261
0262
0263
0264 if (currentSurface != nullptr && currentSurface != startSurface &&
0265 currentSurface != targetSurface) {
0266 return true;
0267 }
0268
0269 return false;
0270 }
0271 };
0272
0273 }