File indexing completed on 2025-10-17 07:58:35
0001
0002
0003
0004
0005
0006
0007
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 <map>
0022 #include <utility>
0023 #include <vector>
0024
0025 namespace Acts {
0026
0027
0028
0029
0030 struct MaterialSurfaceIdentifier {
0031
0032
0033
0034 bool operator()(const Surface& sf) const {
0035 return (sf.surfaceMaterial() != nullptr);
0036 }
0037 };
0038
0039
0040 struct InteractionVolumeCollector {
0041
0042
0043
0044
0045 struct this_result {
0046
0047 std::map<GeometryIdentifier, IAssignmentFinder::VolumeAssignment> collected;
0048 };
0049
0050
0051 using result_type = this_result;
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 template <typename propagator_state_t, typename stepper_t,
0067 typename navigator_t>
0068 void act(propagator_state_t& state, const stepper_t& stepper,
0069 const navigator_t& navigator, result_type& result,
0070 const Logger& ) const {
0071
0072 auto currentVolume = navigator.currentVolume(state.navigation);
0073
0074
0075 if (currentVolume != nullptr) {
0076 auto collIt = result.collected.find(currentVolume->geometryId());
0077
0078 if (collIt == result.collected.end() &&
0079 currentVolume->volumeMaterial() != nullptr) {
0080 Vector3 entryPosition = stepper.position(state.stepping);
0081 Vector3 exitPosition = entryPosition;
0082 IAssignmentFinder::VolumeAssignment vAssignment{
0083 InteractionVolume(currentVolume), entryPosition, exitPosition};
0084 result.collected.emplace(currentVolume->geometryId(), vAssignment);
0085 } else if (collIt != result.collected.end()) {
0086
0087 (collIt->second).exit = stepper.position(state.stepping);
0088 }
0089 }
0090 }
0091 };
0092
0093
0094
0095
0096
0097
0098
0099
0100 template <typename propagator_t>
0101 class PropagatorMaterialAssigner final : public IAssignmentFinder {
0102 public:
0103
0104
0105 explicit PropagatorMaterialAssigner(propagator_t propagator)
0106 : m_propagator(std::move(propagator)) {}
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
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
0124 std::pair<std::vector<IAssignmentFinder::SurfaceAssignment>,
0125 std::vector<IAssignmentFinder::VolumeAssignment>>
0126 candidates;
0127
0128 using VectorHelpers::makeVector4;
0129
0130 NeutralBoundTrackParameters start =
0131 NeutralBoundTrackParameters::createCurvilinear(
0132 makeVector4(position, 0), direction, 1, std::nullopt,
0133 NeutralParticleHypothesis::geantino());
0134
0135
0136 using MaterialSurfaceCollector =
0137 SurfaceCollector<MaterialSurfaceIdentifier>;
0138 using ActorList = ActorList<MaterialSurfaceCollector,
0139 InteractionVolumeCollector, EndOfWorldReached>;
0140 using PropagatorOptions =
0141 typename propagator_t::template Options<ActorList>;
0142
0143 PropagatorOptions options(gctx, mctx);
0144
0145 const auto& result = m_propagator.propagate(start, options).value();
0146
0147
0148 auto scResult =
0149 result.template get<MaterialSurfaceCollector::result_type>();
0150 auto mappingSurfaces = scResult.collected;
0151
0152 for (auto& mSurface : mappingSurfaces) {
0153 candidates.first.push_back(IAssignmentFinder::SurfaceAssignment{
0154 mSurface.surface, mSurface.position, direction});
0155 }
0156
0157
0158 auto vcResult =
0159 result.template get<InteractionVolumeCollector::result_type>();
0160 for (const auto& [geoId, vIntersection] : vcResult.collected) {
0161 candidates.second.push_back(vIntersection);
0162 }
0163
0164
0165 return candidates;
0166 }
0167
0168 private:
0169 propagator_t m_propagator;
0170 };
0171
0172 }