Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:50:46

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