Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-16 07:35:32

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 #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,
0022     std::unique_ptr<const Acts::Logger> logger)
0023     : IAlgorithm("PropagationAlgorithm", std::move(logger)), m_cfg(config) {
0024   if (!m_cfg.propagatorImpl) {
0025     throw std::invalid_argument("Config needs to contain a propagator");
0026   }
0027   m_inputTrackParameters.initialize(m_cfg.inputTrackParameters);
0028   m_outputSummary.initialize(m_cfg.outputSummaryCollection);
0029   m_outputMaterialTracks.initialize(m_cfg.outputMaterialCollection);
0030 }
0031 
0032 ProcessCode PropagationAlgorithm::execute(
0033     const AlgorithmContext& context) const {
0034   // Input : the track parameters
0035   const auto& inputTrackParameters = m_inputTrackParameters(context);
0036 
0037   ACTS_DEBUG("Propagating " << inputTrackParameters.size()
0038                             << " input trackparameters");
0039 
0040   // Output : the propagation steps
0041   PropagationSummaries propagationSummaries;
0042   propagationSummaries.reserve(inputTrackParameters.size());
0043 
0044   // Output (optional): the recorded material
0045   std::unordered_map<std::size_t, Acts::RecordedMaterialTrack>
0046       recordedMaterialTracks;
0047   if (m_cfg.recordMaterialInteractions) {
0048     recordedMaterialTracks.reserve(inputTrackParameters.size());
0049   }
0050 
0051   for (const auto [it, parameters] : Acts::enumerate(inputTrackParameters)) {
0052     // In case covariance transport is not desired, it has to be stripped
0053     // off the input parameters
0054     auto propagationResult =
0055         m_cfg.covarianceTransport
0056             ? m_cfg.propagatorImpl->execute(context, m_cfg, logger(),
0057                                             parameters)
0058             : m_cfg.propagatorImpl->execute(
0059                   context, m_cfg, logger(),
0060                   TrackParameters(parameters.referenceSurface().getSharedPtr(),
0061                                   parameters.parameters(), std::nullopt,
0062                                   parameters.particleHypothesis()));
0063     if (!propagationResult.ok()) {
0064       ACTS_ERROR("Propagation failed with " << propagationResult.error());
0065       continue;
0066     }
0067 
0068     PropagationOutput& propagationOutput = propagationResult.value();
0069 
0070     // Position / momentum for the output writing
0071     Acts::Vector3 position = parameters.position(context.geoContext);
0072     Acts::Vector3 direction = parameters.direction();
0073 
0074     // Record the propagator steps
0075     propagationSummaries.push_back(std::move(propagationOutput.first));
0076 
0077     if (m_cfg.recordMaterialInteractions) {
0078       // Record the material information
0079       recordedMaterialTracks.emplace(
0080           it, std::make_pair(std::make_pair(position, direction),
0081                              std::move(propagationOutput.second)));
0082     }
0083   }
0084   // Write the propagation step data to the event store
0085   m_outputSummary(context, std::move(propagationSummaries));
0086 
0087   // Write the recorded material to the event store
0088   if (m_cfg.recordMaterialInteractions) {
0089     m_outputMaterialTracks(context, std::move(recordedMaterialTracks));
0090   }
0091   return ProcessCode::SUCCESS;
0092 }
0093 
0094 }  // namespace ActsExamples