File indexing completed on 2025-01-18 09:11:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Propagation/PropagationAlgorithm.hpp"
0010
0011 #include "Acts/Utilities/Enumerate.hpp"
0012 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0013 #include "ActsExamples/Propagation/PropagatorInterface.hpp"
0014
0015 #include <stdexcept>
0016 #include <utility>
0017
0018 namespace ActsExamples {
0019
0020 PropagationAlgorithm::PropagationAlgorithm(
0021 const PropagationAlgorithm::Config& config, Acts::Logging::Level level)
0022 : IAlgorithm("PropagationAlgorithm", level), m_cfg(config) {
0023 if (!m_cfg.propagatorImpl) {
0024 throw std::invalid_argument("Config needs to contain a propagator");
0025 }
0026 m_inputTrackParameters.initialize(m_cfg.inputTrackParameters);
0027 m_outputSummary.initialize(m_cfg.outputSummaryCollection);
0028 m_outputMaterialTracks.initialize(m_cfg.outputMaterialCollection);
0029 }
0030
0031 ProcessCode PropagationAlgorithm::execute(
0032 const AlgorithmContext& context) const {
0033
0034 const auto& inputTrackParameters = m_inputTrackParameters(context);
0035
0036 ACTS_DEBUG("Propagating " << inputTrackParameters.size()
0037 << " input trackparameters");
0038
0039
0040 PropagationSummaries propagationSummaries;
0041 propagationSummaries.reserve(inputTrackParameters.size());
0042
0043
0044 std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0045 recordedMaterialTracks;
0046 if (m_cfg.recordMaterialInteractions) {
0047 recordedMaterialTracks.reserve(inputTrackParameters.size());
0048 }
0049
0050 for (const auto [it, parameters] : Acts::enumerate(inputTrackParameters)) {
0051
0052
0053 auto propagationResult =
0054 m_cfg.covarianceTransport
0055 ? m_cfg.propagatorImpl->execute(context, m_cfg, logger(),
0056 parameters)
0057 : m_cfg.propagatorImpl->execute(
0058 context, m_cfg, logger(),
0059 TrackParameters(parameters.referenceSurface().getSharedPtr(),
0060 parameters.parameters(), std::nullopt,
0061 parameters.particleHypothesis()));
0062 if (!propagationResult.ok()) {
0063 ACTS_ERROR("Propagation failed with " << propagationResult.error());
0064 continue;
0065 }
0066
0067 PropagationOutput& propagationOutput = propagationResult.value();
0068
0069
0070 Acts::Vector3 position = parameters.position(context.geoContext);
0071 Acts::Vector3 direction = parameters.direction();
0072
0073
0074 propagationSummaries.push_back(std::move(propagationOutput.first));
0075
0076 if (m_cfg.recordMaterialInteractions) {
0077
0078 recordedMaterialTracks.emplace(
0079 it, std::make_pair(std::make_pair(position, direction),
0080 std::move(propagationOutput.second)));
0081 }
0082 }
0083
0084 m_outputSummary(context, std::move(propagationSummaries));
0085
0086
0087 if (m_cfg.recordMaterialInteractions) {
0088 m_outputMaterialTracks(context, std::move(recordedMaterialTracks));
0089 }
0090 return ProcessCode::SUCCESS;
0091 }
0092
0093 }