Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-23 08:19:31

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/EventData/BoundTrackParameters.hpp"
0012 #include "Acts/Propagator/PropagatorState.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 
0015 namespace Acts {
0016 
0017 /// Simple struct to select surfaces
0018 struct SurfaceSelector {
0019   /// Flag indicating whether to select sensitive surfaces
0020   bool selectSensitive = true;
0021   /// Flag indicating whether to select surfaces with material
0022   bool selectMaterial = false;
0023   /// Flag indicating whether to select passive surfaces
0024   bool selectPassive = false;
0025 
0026   /// SurfaceSelector with options
0027   ///
0028   /// @param sSensitive is the directive to select sensitive surfaces
0029   /// @param sMaterial is the directive to select material surfaces
0030   /// @param sPassive is the directive to select passive surfaces
0031   explicit SurfaceSelector(bool sSensitive = true, bool sMaterial = false,
0032                            bool sPassive = false)
0033       : selectSensitive(sSensitive),
0034         selectMaterial(sMaterial),
0035         selectPassive(sPassive) {}
0036 
0037   /// Call operator to check if a surface should be selected
0038   ///
0039   /// @param surface is the test surface
0040   /// @return true if surface meets selection criteria
0041   bool operator()(const Surface& surface) const {
0042     if (selectSensitive && surface.isSensitive()) {
0043       return true;
0044     }
0045     if (selectMaterial && surface.hasMaterial()) {
0046       return true;
0047     }
0048     if (selectPassive) {
0049       return true;
0050     }
0051     return false;
0052   }
0053 };
0054 
0055 /// The information to be writtern out per hit surface
0056 struct SurfaceHit {
0057   /// Pointer to the surface that was hit
0058   const Surface* surface = nullptr;
0059   /// Position where the surface was encountered
0060   Vector3 position{};
0061   /// Direction of propagation when surface was encountered
0062   Vector3 direction{};
0063 };
0064 
0065 /// A Surface Collector struct
0066 /// templated with a Selector type
0067 ///
0068 /// Whenever a surface is passed in the propagation
0069 /// that satisfies the selector, it is recorded
0070 /// for further usage in the flow.
0071 template <typename Selector = SurfaceSelector>
0072 struct SurfaceCollector {
0073   /// The selector used for this surface
0074   Selector selector;
0075 
0076   /// Simple result struct to be returned
0077   /// It has all the SurfaceHit objects that
0078   /// are collected (and thus have been selected)
0079   struct this_result {
0080     /// Container of collected surface hits during propagation
0081     std::vector<SurfaceHit> collected;
0082   };
0083 
0084   /// Type alias for collector result type
0085   using result_type = this_result;
0086 
0087   /// Collector action for the ActionList of the Propagator
0088   /// It checks if the propagator state has a current surface,
0089   /// in which case the action is performed:
0090   /// - it records the surface given the configuration
0091   ///
0092   /// @tparam propagator_state_t is the type of Propagator state
0093   /// @tparam stepper_t Type of the stepper used for the propagation
0094   /// @tparam navigator_t Type of the navigator used for the propagation
0095   ///
0096   /// @param [in,out] state is the mutable stepper state object
0097   /// @param [in] stepper The stepper in use
0098   /// @param [in] navigator The navigator in use
0099   /// @param [in,out] result is the mutable result object
0100   /// @param logger a logger instance
0101   /// @return Result indicating success or failure
0102   template <typename propagator_state_t, typename stepper_t,
0103             typename navigator_t>
0104   Result<void> act(propagator_state_t& state, const stepper_t& stepper,
0105                    const navigator_t& navigator, result_type& result,
0106                    const Logger& logger) const {
0107     if (state.stage == PropagatorStage::postPropagation) {
0108       return {};
0109     }
0110 
0111     auto currentSurface = navigator.currentSurface(state.navigation);
0112 
0113     // The current surface has been assigned by the navigator
0114     if (currentSurface && selector(*currentSurface)) {
0115       // Create for recording
0116       SurfaceHit surface_hit;
0117       surface_hit.surface = currentSurface;
0118       surface_hit.position = stepper.position(state.stepping);
0119       surface_hit.direction = stepper.direction(state.stepping);
0120       // Save if in the result
0121       result.collected.push_back(surface_hit);
0122       // Screen output
0123       ACTS_VERBOSE("Collect surface  " << currentSurface->geometryId());
0124     }
0125 
0126     return {};
0127   }
0128 };
0129 
0130 /// Collector of the bound track parameters. Every time when the
0131 /// propagator reaches a surface, and the surface passes the selection,
0132 /// the @ref BoundTrackParameters are recorded on this surface.
0133 /// @tparam Selector: Any surface selector class implementation
0134 ///                   to select the parameters on surface for record
0135 template <typename Selector = SurfaceSelector>
0136 struct BoundParameterRecorder {
0137   /// The selector used for this surface
0138   Selector selector;
0139 
0140   /// Type alias for collector result type
0141   using result_type = std::vector<BoundTrackParameters>;
0142 
0143   /// Collector action for the ActionList of the Propagator
0144   /// It checks if the propagator state has a current surface,
0145   /// in which case the action is performed:
0146   /// - it records the bound track parameters
0147   ///
0148   /// @tparam propagator_state_t is the type of Propagator state
0149   /// @tparam stepper_t Type of the stepper used for the propagation
0150   /// @tparam navigator_t Type of the navigator used for the propagation
0151   ///
0152   /// @param [in,out] state is the mutable stepper state object
0153   /// @param [in] stepper The stepper in use
0154   /// @param [in] navigator The navigator in use
0155   /// @param [in,out] result is the mutable result object
0156   /// @param logger a logger instance
0157   /// @return Result indicating success or failure
0158   template <typename propagator_state_t, typename stepper_t,
0159             typename navigator_t>
0160   Result<void> act(propagator_state_t& state, const stepper_t& stepper,
0161                    const navigator_t& navigator, result_type& result,
0162                    const Logger& logger) const {
0163     if (state.stage == PropagatorStage::postPropagation) {
0164       return {};
0165     }
0166 
0167     auto currentSurface = navigator.currentSurface(state.navigation);
0168 
0169     // The current surface has been assigned by the navigator
0170     if (currentSurface && selector(*currentSurface)) {
0171       auto res = stepper.boundState(state.stepping, *currentSurface);
0172       if (res.ok()) {
0173         result.emplace_back(std::get<0>(*res));
0174       }
0175 
0176       // Screen output
0177       ACTS_VERBOSE("Collect surface  " << currentSurface->geometryId());
0178     }
0179 
0180     return {};
0181   }
0182 };
0183 
0184 }  // namespace Acts