Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-25 09:02:17

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/Propagator/ConstrainedStep.hpp"
0012 #include "Acts/Surfaces/Surface.hpp"
0013 #include "Acts/Utilities/Helpers.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 
0016 #include <cmath>
0017 #include <cstdint>
0018 
0019 namespace Acts::detail {
0020 
0021 /// Check if the propagation reached a path limit
0022 ///
0023 /// If the limit is not reached yet, this constrains the next step to it.
0024 ///
0025 /// @param [in,out] state The propagation state
0026 /// @param [in] stepper Stepper used for the propagation
0027 /// @param [in] pathLimit Signed path limit
0028 /// @param [in] logger A logger instance
0029 /// @return True if the path limit is reached
0030 template <typename propagator_state_t, typename stepper_t>
0031 bool pathLimitReached(propagator_state_t& state, const stepper_t& stepper,
0032                       double pathLimit, const Logger& logger) {
0033   const double distance =
0034       std::abs(pathLimit) - std::abs(stepper.pathLength(state.stepping));
0035   const double tolerance = state.options.surfaceTolerance;
0036   if (std::abs(distance) < std::abs(tolerance)) {
0037     ACTS_VERBOSE("Path limit reached at distance " << distance);
0038     return true;
0039   }
0040   stepper.updateStepSize(state.stepping, distance,
0041                          ConstrainedStep::Type::Actor);
0042   ACTS_VERBOSE("Step size updated to the path limit: "
0043                << stepper.outputStepSize(state.stepping));
0044   return false;
0045 }
0046 
0047 /// Check if the propagation reached a surface
0048 ///
0049 /// @param [in] state The propagation state
0050 /// @param [in] navigator Navigator used for the propagation
0051 /// @param [in] surface The surface to reach, or nullptr for no surface
0052 /// @param [in] logger A logger instance
0053 /// @return True if the surface is the current surface of the navigator
0054 template <typename propagator_state_t, typename navigator_t>
0055 bool surfaceReached(propagator_state_t& state, const navigator_t& navigator,
0056                     const Surface* surface, const Logger& logger) {
0057   if (surface == nullptr ||
0058       navigator.currentSurface(state.navigation) != surface) {
0059     return false;
0060   }
0061   ACTS_VERBOSE("Target surface reached.");
0062   return true;
0063 }
0064 
0065 /// Check if the propagation left the world
0066 ///
0067 /// @param [in] state The propagation state
0068 /// @param [in] navigator Navigator used for the propagation
0069 /// @return True if the navigator reached the end of the world
0070 template <typename propagator_state_t, typename navigator_t>
0071 bool endOfWorldReached(propagator_state_t& state,
0072                        const navigator_t& navigator) {
0073   return navigator.endOfWorldReached(state.navigation);
0074 }
0075 
0076 /// Check if the propagation left the allowed volumes
0077 ///
0078 /// This uses `constrainToVolumeIds` and `endOfWorldVolumeIds` of the
0079 /// propagator options.
0080 ///
0081 /// @param [in] state The propagation state
0082 /// @param [in] navigator Navigator used for the propagation
0083 /// @param [in] logger A logger instance
0084 /// @return True if the current volume is not allowed
0085 template <typename propagator_state_t, typename navigator_t>
0086 bool volumeConstraintReached(propagator_state_t& state,
0087                              const navigator_t& navigator,
0088                              const Logger& logger) {
0089   const auto& constrainToVolumeIds = state.options.constrainToVolumeIds;
0090   const auto& endOfWorldVolumeIds = state.options.endOfWorldVolumeIds;
0091 
0092   if (constrainToVolumeIds.empty() && endOfWorldVolumeIds.empty()) {
0093     return false;
0094   }
0095   const auto* currentVolume = navigator.currentVolume(state.navigation);
0096 
0097   // We need a volume to check its ID
0098   if (currentVolume == nullptr) {
0099     return false;
0100   }
0101 
0102   const auto currentVolumeId =
0103       static_cast<std::uint32_t>(currentVolume->geometryId().volume());
0104 
0105   if (!constrainToVolumeIds.empty() &&
0106       !rangeContainsValue(constrainToVolumeIds, currentVolumeId)) {
0107     ACTS_VERBOSE("Abort with volume constraint " << currentVolumeId);
0108     return true;
0109   }
0110 
0111   if (!endOfWorldVolumeIds.empty() &&
0112       rangeContainsValue(endOfWorldVolumeIds, currentVolumeId)) {
0113     ACTS_VERBOSE("Abort with additional end of world volume "
0114                  << currentVolumeId);
0115     return true;
0116   }
0117 
0118   return false;
0119 }
0120 
0121 /// Check if the propagation reached a surface other than the start and the
0122 /// target surface
0123 ///
0124 /// @param [in] state The propagation state
0125 /// @param [in] navigator Navigator used for the propagation
0126 /// @return True if the current surface is neither the start nor the target
0127 template <typename propagator_state_t, typename navigator_t>
0128 bool anySurfaceReached(propagator_state_t& state,
0129                        const navigator_t& navigator) {
0130   const Surface* startSurface = navigator.startSurface(state.navigation);
0131   const Surface* targetSurface = navigator.targetSurface(state.navigation);
0132   const Surface* currentSurface = navigator.currentSurface(state.navigation);
0133 
0134   // `startSurface` is excluded because we want to reach a new surface
0135   // `targetSurface` is excluded because another condition should handle it
0136   return currentSurface != nullptr && currentSurface != startSurface &&
0137          currentSurface != targetSurface;
0138 }
0139 
0140 }  // namespace Acts::detail