File indexing completed on 2025-01-18 09:10:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013
0014 #include <numbers>
0015
0016 namespace Acts::detail {
0017
0018
0019 template <typename path_aborter_t, typename propagator_state_t,
0020 typename stepper_t>
0021 void setupLoopProtection(propagator_state_t& state, const stepper_t& stepper,
0022 path_aborter_t& pathAborter, bool releaseLimit,
0023 const Logger& logger) {
0024 if (!state.options.loopProtection) {
0025 return;
0026 }
0027
0028 if (releaseLimit) {
0029 pathAborter.internalLimit =
0030 state.options.direction * std::numeric_limits<double>::max();
0031 }
0032
0033
0034 auto fieldRes =
0035 stepper.getField(state.stepping, stepper.position(state.stepping));
0036 if (!fieldRes.ok()) {
0037
0038
0039 ACTS_WARNING("Field lookup was unsuccessful, this is very likely an error");
0040 return;
0041 }
0042 const Vector3 field = *fieldRes;
0043 const double B = field.norm();
0044 if (B == 0) {
0045 return;
0046 }
0047
0048
0049 const double p = stepper.absoluteMomentum(state.stepping);
0050
0051 const double helixPath =
0052 state.options.direction * 2 * std::numbers::pi * p / B;
0053
0054 const double loopLimit = state.options.loopFraction * helixPath;
0055 const double previousLimit = pathAborter.internalLimit;
0056 if (std::abs(loopLimit) < std::abs(previousLimit)) {
0057 pathAborter.internalLimit = loopLimit;
0058
0059 ACTS_VERBOSE("Path aborter limit set to "
0060 << loopLimit << " (full helix = " << helixPath
0061 << ", previous limit = " << previousLimit << ")");
0062 } else {
0063 ACTS_VERBOSE("Path aborter limit not updated to "
0064 << loopLimit << " (full helix = " << helixPath
0065 << ", previous limit = " << previousLimit << ")");
0066 }
0067 }
0068
0069 }