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