Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:38

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, 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   // Input : the track parameters
0034   const auto& inputTrackParameters = m_inputTrackParameters(context);
0035 
0036   ACTS_DEBUG("Propagating " << inputTrackParameters.size()
0037                             << " input trackparameters");
0038 
0039   // Output : the propagation steps
0040   PropagationSummaries propagationSummaries;
0041   propagationSummaries.reserve(inputTrackParameters.size());
0042 
0043   // Output (optional): the recorded material
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     // In case covariance transport is not desired, it has to be stripped
0052     // off the input parameters
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     // Position / momentum for the output writing
0070     Acts::Vector3 position = parameters.position(context.geoContext);
0071     Acts::Vector3 direction = parameters.direction();
0072 
0073     // Record the propagator steps
0074     propagationSummaries.push_back(std::move(propagationOutput.first));
0075 
0076     if (m_cfg.recordMaterialInteractions) {
0077       // Record the material information
0078       recordedMaterialTracks.emplace(
0079           it, std::make_pair(std::make_pair(position, direction),
0080                              std::move(propagationOutput.second)));
0081     }
0082   }
0083   // Write the propagation step data to the event store
0084   m_outputSummary(context, std::move(propagationSummaries));
0085 
0086   // Write the recorded material to the event store
0087   if (m_cfg.recordMaterialInteractions) {
0088     m_outputMaterialTracks(context, std::move(recordedMaterialTracks));
0089   }
0090   return ProcessCode::SUCCESS;
0091 }
0092 
0093 }  // namespace ActsExamples