Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-17 07:49:36

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/Geometry/GeometryContext.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/Material/interface/IAssignmentFinder.hpp"
0015 #include "Acts/Propagator/ActorList.hpp"
0016 #include "Acts/Propagator/StandardAborters.hpp"
0017 #include "Acts/Propagator/SurfaceCollector.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "Acts/Utilities/VectorHelpers.hpp"
0021 
0022 #include <map>
0023 #include <utility>
0024 #include <vector>
0025 
0026 namespace Acts {
0027 
0028 /// @brief selector for finding surface
0029 ///
0030 /// This is to be used with a SurfaceCollector<>
0031 struct MaterialSurfaceIdentifier {
0032   /// check if the surface has material
0033   /// @param sf Surface to check for material
0034   /// @return True if the surface has material assigned to it
0035   bool operator()(const Surface& sf) const { return sf.hasMaterial(); }
0036 };
0037 
0038 /// An Interaction volume collector with unique counting
0039 struct InteractionVolumeCollector {
0040   /// Simple result struct that holds the collected volumes
0041   ///
0042   /// @note the map is to avoid double counting as this is
0043   /// called in an action list
0044   struct this_result {
0045     /// Map of collected volume assignments by geometry identifier
0046     std::map<GeometryIdentifier, IAssignmentFinder::VolumeAssignment> collected;
0047   };
0048 
0049   /// Type alias for volume collection result
0050   using result_type = this_result;
0051 
0052   /// Collector action for the ActionList of the Propagator
0053   /// It checks if the propagator state has a current volume,
0054   /// in which case the action is performed:
0055   /// - it records the volume given the configuration
0056   ///
0057   /// @tparam propagator_state_t is the type of Propagator state
0058   /// @tparam stepper_t Type of the stepper used for the propagation
0059   /// @tparam navigator_t Type of the navigator used for the propagation
0060   ///
0061   /// @param [in,out] state is the mutable stepper state object
0062   /// @param [in] stepper The stepper in use
0063   /// @param [in] navigator The navigator in use
0064   /// @param [in,out] result is the mutable result object
0065   /// @return Result object indicating success or failure
0066   template <typename propagator_state_t, typename stepper_t,
0067             typename navigator_t>
0068   Result<void> act(propagator_state_t& state, const stepper_t& stepper,
0069                    const navigator_t& navigator, result_type& result,
0070                    const Logger& /*logger*/) const {
0071     // Retrieve the current volume
0072     auto currentVolume = navigator.currentVolume(state.navigation);
0073 
0074     // The current volume has been assigned by the navigator
0075     if (currentVolume != nullptr) {
0076       auto collIt = result.collected.find(currentVolume->geometryId());
0077       // Check if the volume has been collected and if it has material
0078       if (collIt == result.collected.end() && currentVolume->hasMaterial()) {
0079         Vector3 entryPosition = stepper.position(state.stepping);
0080         Vector3 exitPosition = entryPosition;
0081         IAssignmentFinder::VolumeAssignment vAssignment{
0082             InteractionVolume(currentVolume), entryPosition, exitPosition};
0083         result.collected.emplace(currentVolume->geometryId(), vAssignment);
0084       } else if (collIt != result.collected.end()) {
0085         // Update the exit position
0086         (collIt->second).exit = stepper.position(state.stepping);
0087       }
0088     }
0089     return Result<void>::success();
0090   }
0091 };
0092 
0093 /// @class PropagatorMaterialAssigner
0094 ///
0095 /// A Propagator based material assigner that uses the navigation and
0096 /// transport of the propagator to assign the material to the surface
0097 /// or the volume.
0098 ///
0099 /// @note eventual navigation problems would affect he material mapping
0100 template <typename propagator_t>
0101 class PropagatorMaterialAssigner /*final*/ : public IAssignmentFinder {
0102  public:
0103   /// @brief  Construct with propagator
0104   /// @param propagator
0105   explicit PropagatorMaterialAssigner(propagator_t propagator)
0106       : m_propagator(std::move(propagator)) {}
0107 
0108   /// @brief Method for generating assignment candidates for the
0109   /// material interaction assignment to surfaces or volumes
0110   ///
0111   /// @param gctx is the geometry context
0112   /// @param mctx is the magnetic field context
0113   /// @param position is the position of the initial ray
0114   /// @param direction is the direction of initial ray
0115   ///
0116   /// @return a vector of Surface Assignments and Volume Assignments
0117   std::pair<std::vector<IAssignmentFinder::SurfaceAssignment>,
0118             std::vector<IAssignmentFinder::VolumeAssignment>>
0119   assignmentCandidates(const GeometryContext& gctx,
0120                        const MagneticFieldContext& mctx,
0121                        const Vector3& position,
0122                        const Vector3& direction) const final {
0123     // Return container
0124     std::pair<std::vector<IAssignmentFinder::SurfaceAssignment>,
0125               std::vector<IAssignmentFinder::VolumeAssignment>>
0126         candidates;
0127 
0128     using VectorHelpers::makeVector4;
0129     // Neutral curvilinear parameters
0130     BoundTrackParameters start = BoundTrackParameters::createCurvilinear(
0131         makeVector4(position, 0), direction, 1, std::nullopt,
0132         ParticleHypothesis::geantino());
0133 
0134     // Prepare Action list and abort list
0135     using MaterialSurfaceCollector =
0136         SurfaceCollector<MaterialSurfaceIdentifier>;
0137     using ActorList = ActorList<MaterialSurfaceCollector,
0138                                 InteractionVolumeCollector, EndOfWorldReached>;
0139     using PropagatorOptions =
0140         typename propagator_t::template Options<ActorList>;
0141 
0142     PropagatorOptions options(gctx, mctx);
0143 
0144     const auto& result = m_propagator.propagate(start, options, false).value();
0145 
0146     // The surface collection results
0147     auto scResult =
0148         result.template get<MaterialSurfaceCollector::result_type>();
0149     auto mappingSurfaces = scResult.collected;
0150 
0151     for (auto& mSurface : mappingSurfaces) {
0152       candidates.first.push_back(IAssignmentFinder::SurfaceAssignment{
0153           mSurface.surface, mSurface.position, direction});
0154     }
0155 
0156     // The volume collection results
0157     auto vcResult =
0158         result.template get<InteractionVolumeCollector::result_type>();
0159     for (const auto& [geoId, vIntersection] : vcResult.collected) {
0160       candidates.second.push_back(vIntersection);
0161     }
0162 
0163     // Return the candidates
0164     return candidates;
0165   }
0166 
0167  private:
0168   propagator_t m_propagator;
0169 };
0170 
0171 }  // namespace Acts