File indexing completed on 2026-12-01 09:18:37
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Direction.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Geometry/Layer.hpp"
0014 #include "Acts/Geometry/TrackingGeometry.hpp"
0015 #include "Acts/Geometry/TrackingVolume.hpp"
0016 #include "Acts/Propagator/NavigationTarget.hpp"
0017 #include "Acts/Propagator/NavigatorInitializeArguments.hpp"
0018 #include "Acts/Propagator/NavigatorOptions.hpp"
0019 #include "Acts/Propagator/NavigatorStatistics.hpp"
0020 #include "Acts/Propagator/detail/AdditionalSurfaceNavigation.hpp"
0021 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0022 #include "Acts/Surfaces/Surface.hpp"
0023 #include "Acts/Utilities/Enumerate.hpp"
0024 #include "Acts/Utilities/Intersection.hpp"
0025 #include "Acts/Utilities/Logger.hpp"
0026 #include "Acts/Utilities/Result.hpp"
0027
0028 #include <limits>
0029 #include <memory>
0030
0031 namespace Acts {
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 class DirectNavigator {
0042 public:
0043
0044 struct Config {};
0045
0046
0047 struct Options : public NavigatorPlainOptions {
0048
0049
0050 explicit Options(const GeometryContext& gctx)
0051 : NavigatorPlainOptions(gctx) {
0052
0053
0054
0055
0056 nearLimit = -100 * UnitConstants::um;
0057 }
0058
0059
0060 std::vector<const Surface*> surfaceSequence;
0061
0062
0063
0064 void setPlainOptions(const NavigatorPlainOptions& options) {
0065
0066
0067 const double keepNearLimit = nearLimit;
0068 static_cast<NavigatorPlainOptions&>(*this) = options;
0069 nearLimit = keepNearLimit;
0070 }
0071 };
0072
0073
0074
0075
0076
0077
0078 struct State {
0079
0080
0081 explicit State(const Options& options_) : options(options_) {}
0082
0083
0084 Options options;
0085
0086
0087 Direction direction = Direction::Forward();
0088
0089
0090 const Surface* startSurface = nullptr;
0091
0092
0093 const Surface* targetSurface = nullptr;
0094
0095
0096
0097
0098 std::int32_t surfaceIndex = -1;
0099
0100
0101 const Surface* currentSurface = nullptr;
0102
0103
0104 bool navigationBreak = false;
0105
0106
0107 detail::AdditionalSurfaceNavigation additional;
0108
0109
0110 NavigatorStatistics statistics;
0111
0112
0113
0114 const Surface& navSurface() const {
0115 return *options.surfaceSequence.at(surfaceIndex);
0116 }
0117
0118
0119
0120 void nextSurface() {
0121 if (direction == Direction::Forward()) {
0122 ++surfaceIndex;
0123 } else {
0124 --surfaceIndex;
0125 }
0126 }
0127
0128
0129
0130 bool endOfSurfaces() const {
0131 if (direction == Direction::Forward()) {
0132 return surfaceIndex >= static_cast<int>(options.surfaceSequence.size());
0133 }
0134 return surfaceIndex < 0;
0135 }
0136
0137
0138
0139 int remainingSurfaces() const {
0140 if (direction == Direction::Forward()) {
0141 return static_cast<int>(options.surfaceSequence.size()) - surfaceIndex;
0142 }
0143 return surfaceIndex + 1;
0144 }
0145
0146
0147
0148
0149 void resetSurfaceIndex() {
0150 surfaceIndex = direction == Direction::Forward()
0151 ? -1
0152 : static_cast<int>(options.surfaceSequence.size());
0153 }
0154 };
0155
0156
0157
0158 explicit DirectNavigator(std::unique_ptr<const Logger> _logger =
0159 getDefaultLogger("DirectNavigator",
0160 Logging::INFO))
0161 : m_logger{std::move(_logger)} {}
0162
0163
0164
0165
0166 State makeState(const Options& options) const {
0167 State state(options);
0168 return state;
0169 }
0170
0171
0172
0173
0174 const Surface* currentSurface(const State& state) const {
0175 return state.currentSurface;
0176 }
0177
0178
0179
0180
0181 const TrackingVolume* currentVolume(const State& state) const {
0182 static_cast<void>(state);
0183 return nullptr;
0184 }
0185
0186
0187
0188
0189 const IVolumeMaterial* currentVolumeMaterial(const State& state) const {
0190 static_cast<void>(state);
0191 return nullptr;
0192 }
0193
0194
0195
0196
0197 const Surface* startSurface(const State& state) const {
0198 return state.startSurface;
0199 }
0200
0201
0202
0203
0204 const Surface* targetSurface(const State& state) const {
0205 return state.targetSurface;
0206 }
0207
0208
0209
0210
0211
0212 bool endOfWorldReached(State& state) const {
0213 static_cast<void>(state);
0214 return false;
0215 }
0216
0217
0218
0219
0220 bool navigationBreak(const State& state) const {
0221 return state.navigationBreak;
0222 }
0223
0224
0225
0226
0227
0228
0229
0230
0231 [[nodiscard]] Result<void> initialize(
0232 State& state, const NavigatorInitializeArguments& args) const {
0233 ACTS_VERBOSE("Initialize. Surface sequence for navigation:");
0234 for (const Surface* surface : state.options.surfaceSequence) {
0235 ACTS_VERBOSE(surface->geometryId()
0236 << " - "
0237 << surface->center(state.options.geoContext).transpose());
0238 }
0239
0240 state.direction = args.propagationDirection;
0241 ACTS_VERBOSE("Navigation direction is " << args.propagationDirection);
0242
0243 state.startSurface = args.startSurface;
0244 state.targetSurface = args.targetSurface;
0245 state.additional.initialize(state.options, args.targetSurface);
0246 state.statistics = {};
0247
0248
0249 state.currentSurface = state.startSurface;
0250 if (state.currentSurface != nullptr) {
0251 ACTS_VERBOSE("Current surface set to start surface "
0252 << state.currentSurface->geometryId());
0253 } else {
0254 ACTS_VERBOSE("Current surface set to nullptr");
0255 }
0256
0257
0258 auto found =
0259 std::ranges::find(state.options.surfaceSequence, state.startSurface);
0260
0261 if (found != state.options.surfaceSequence.end()) {
0262
0263 state.surfaceIndex = static_cast<std::int32_t>(
0264 std::distance(state.options.surfaceSequence.begin(), found));
0265 } else {
0266 ACTS_DEBUG(
0267 "Did not find the start surface in the sequence. Assuming it is not "
0268 "part of the sequence. Trusting the correctness of the input "
0269 "sequence. Resetting the surface index.");
0270 state.resetSurfaceIndex();
0271 }
0272
0273 state.navigationBreak = false;
0274
0275 return Result<void>::success();
0276 }
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290 NavigationTarget nextTarget(
0291 State& state, const Vector3& position, const Vector3& direction,
0292 [[maybe_unused]] const Vector3& curvature = Vector3::Zero()) const {
0293
0294 state.currentSurface = nullptr;
0295
0296
0297 const TrackingVolume* noVolume = nullptr;
0298 return state.additional.nextTarget(
0299 state.options, position, direction, noVolume,
0300 [&] { return nextSequenceTarget(state, position, direction); });
0301 }
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314 bool checkTargetValid(
0315 State& state, const Vector3& position, const Vector3& direction,
0316 [[maybe_unused]] const Vector3& curvature = Vector3::Zero()) const {
0317 return state.additional.checkTargetValid(state.options, position, direction,
0318 nullptr, true);
0319 }
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 void handleSurfaceReached(
0332 State& state, const Vector3& position, const Vector3& direction,
0333 const Surface& surface,
0334 [[maybe_unused]] const Vector3& curvature = Vector3::Zero()) const {
0335 static_cast<void>(position);
0336 static_cast<void>(direction);
0337
0338 ACTS_VERBOSE("DirectNavigator::handleSurfaceReached");
0339
0340
0341
0342 if (state.additional.handleSurfaceReached(surface)) {
0343 state.currentSurface = &surface;
0344 ACTS_VERBOSE("Current surface set to additional surface "
0345 << surface.geometryId());
0346 return;
0347 }
0348
0349 if (state.navigationBreak) {
0350 return;
0351 }
0352
0353
0354 state.currentSurface = &state.navSurface();
0355 ACTS_VERBOSE("Current surface set to "
0356 << state.currentSurface->geometryId());
0357 }
0358
0359 private:
0360
0361 NavigationTarget nextSequenceTarget(State& state, const Vector3& position,
0362 const Vector3& direction) const {
0363 if (state.navigationBreak) {
0364 return NavigationTarget::None();
0365 }
0366
0367 ACTS_VERBOSE("DirectNavigator::nextTarget");
0368
0369
0370 state.nextSurface();
0371
0372 while (!state.endOfSurfaces()) {
0373 ACTS_VERBOSE("Next surface candidate is "
0374 << state.navSurface().geometryId() << ". "
0375 << state.remainingSurfaces() << " out of "
0376 << state.options.surfaceSequence.size()
0377 << " surfaces remain to try.");
0378
0379
0380
0381 const Surface& surface = state.navSurface();
0382 const double farLimit = std::numeric_limits<double>::max();
0383 const NavigationTarget target = chooseIntersection(
0384 state.options.geoContext, surface, position, direction,
0385 BoundaryTolerance::Infinite(), state.options.nearLimit, farLimit,
0386 state.options.surfaceTolerance);
0387 if (target.isValid()) {
0388 return target;
0389 }
0390
0391 ACTS_VERBOSE("No valid intersection found with surface "
0392 << surface.geometryId() << ", trying next surface.");
0393 state.nextSurface();
0394 }
0395
0396 ACTS_VERBOSE("End of surfaces reached, navigation break.");
0397 state.navigationBreak = true;
0398 return NavigationTarget::None();
0399 }
0400
0401 NavigationTarget chooseIntersection(
0402 const GeometryContext& gctx, const Surface& surface,
0403 const Vector3& position, const Vector3& direction,
0404 const BoundaryTolerance& boundaryTolerance, double nearLimit,
0405 double farLimit, double tolerance) const {
0406 auto intersections = surface.intersect(gctx, position, direction,
0407 boundaryTolerance, tolerance);
0408
0409 for (auto [intersectionIndex, intersection] :
0410 Acts::enumerate(intersections)) {
0411 if (intersection.isValid() &&
0412 detail::checkPathLength(intersection.pathLength(), nearLimit,
0413 farLimit, logger())) {
0414 return NavigationTarget(intersection, intersectionIndex, surface,
0415 boundaryTolerance);
0416 }
0417 }
0418
0419 return NavigationTarget::None();
0420 }
0421
0422 const Logger& logger() const { return *m_logger; }
0423
0424 std::unique_ptr<const Logger> m_logger;
0425 };
0426
0427 }