Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-16 08:18:28

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/Utilities/TrackSelectorAlgorithm.hpp"
0010 
0011 #include "Acts/EventData/TrackContainer.hpp"
0012 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0013 #include "Acts/EventData/VectorTrackContainer.hpp"
0014 #include "ActsExamples/EventData/Track.hpp"
0015 
0016 #include <memory>
0017 #include <stdexcept>
0018 #include <utility>
0019 
0020 namespace ActsExamples {
0021 
0022 TrackSelectorAlgorithm::TrackSelectorAlgorithm(
0023     const Config& config, std::unique_ptr<const Acts::Logger> logger)
0024     : IAlgorithm("TrackSelector", std::move(logger)),
0025       m_cfg(config),
0026       m_selector(config.selectorConfig) {
0027   if (m_cfg.inputTracks.empty()) {
0028     throw std::invalid_argument("Input track collection is empty");
0029   }
0030 
0031   if (m_cfg.outputTracks.empty()) {
0032     throw std::invalid_argument("Output track collection is empty");
0033   }
0034 
0035   m_inputTrackContainer.initialize(m_cfg.inputTracks);
0036   m_outputTrackContainer.initialize(m_cfg.outputTracks);
0037 }
0038 
0039 ProcessCode TrackSelectorAlgorithm::execute(const AlgorithmContext& ctx) const {
0040   ACTS_VERBOSE("Reading tracks from: " << m_cfg.inputTracks);
0041 
0042   const auto& inputTracks = m_inputTrackContainer(ctx);
0043 
0044   std::shared_ptr<Acts::ConstVectorMultiTrajectory> trackStateContainer =
0045       inputTracks.trackStateContainerHolder();
0046 
0047   auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
0048 
0049   // temporary empty track state container: we don't change the original one,
0050   // but we need one for filtering
0051   auto tempTrackStateContainer =
0052       std::make_shared<Acts::VectorMultiTrajectory>();
0053 
0054   TrackContainer filteredTracks{trackContainer, tempTrackStateContainer};
0055   filteredTracks.ensureDynamicColumns(inputTracks);
0056 
0057   ACTS_DEBUG("Track container size before filtering: " << inputTracks.size());
0058 
0059   m_selector.selectTracks(inputTracks, filteredTracks);
0060 
0061   ACTS_DEBUG("Track container size after filtering: " << filteredTracks.size());
0062 
0063   ConstTrackContainer outputTracks{
0064       std::make_shared<Acts::ConstVectorTrackContainer>(
0065           std::move(*trackContainer)),
0066       trackStateContainer};
0067 
0068   m_outputTrackContainer(ctx, std::move(outputTracks));
0069 
0070   return ProcessCode::SUCCESS;
0071 }
0072 
0073 }  // namespace ActsExamples