Back to home page

EIC code displayed by LXR

 
 

    


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

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/TracksToTrajectories.hpp"
0010 
0011 #include "Acts/EventData/GenericBoundTrackParameters.hpp"
0012 #include "Acts/EventData/MultiTrajectory.hpp"
0013 #include "Acts/EventData/ProxyAccessor.hpp"
0014 #include "Acts/EventData/TrackContainer.hpp"
0015 #include "Acts/EventData/TrackProxy.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Utilities/HashedString.hpp"
0018 #include "ActsExamples/EventData/Track.hpp"
0019 #include "ActsExamples/EventData/Trajectories.hpp"
0020 
0021 #include <optional>
0022 #include <utility>
0023 #include <vector>
0024 
0025 namespace ActsExamples {
0026 struct AlgorithmContext;
0027 
0028 TracksToTrajectories::TracksToTrajectories(Config cfg, Acts::Logging::Level lvl)
0029     : IAlgorithm("TracksToTrajectories", lvl), m_cfg(std::move(cfg)) {
0030   m_inputTracks.initialize(m_cfg.inputTracks);
0031   m_outputTrajectories.initialize(m_cfg.outputTrajectories);
0032 }
0033 
0034 ProcessCode TracksToTrajectories::execute(const AlgorithmContext& ctx) const {
0035   const auto& tracks = m_inputTracks(ctx);
0036 
0037   // Prepare the output data with MultiTrajectory
0038   TrajectoriesContainer trajectories;
0039   trajectories.reserve(tracks.size());
0040 
0041   static const Acts::ConstProxyAccessor<unsigned int> seedNumber("trackGroup");
0042 
0043   if (tracks.hasColumn(Acts::hashString("trackGroup"))) {
0044     // track group by seed is available, produce grouped trajectories
0045     std::optional<unsigned int> lastSeed;
0046 
0047     Trajectories::IndexedParameters parameters;
0048     std::vector<Acts::MultiTrajectoryTraits::IndexType> tips;
0049 
0050     for (const auto& track : tracks) {
0051       if (!lastSeed) {
0052         lastSeed = seedNumber(track);
0053       }
0054 
0055       if (seedNumber(track) != lastSeed.value()) {
0056         // make copies and clear vectors
0057         trajectories.emplace_back(tracks.trackStateContainer(), tips,
0058                                   parameters);
0059         tips.clear();
0060         parameters.clear();
0061       }
0062 
0063       lastSeed = seedNumber(track);
0064 
0065       tips.push_back(track.tipIndex());
0066       parameters.emplace(
0067           std::pair{track.tipIndex(),
0068                     TrackParameters{track.referenceSurface().getSharedPtr(),
0069                                     track.parameters(), track.covariance(),
0070                                     track.particleHypothesis()}});
0071     }
0072 
0073     if (tips.empty()) {
0074       ACTS_DEBUG("Last trajectory is empty");
0075     }
0076 
0077     // last entry: move vectors
0078     trajectories.emplace_back(tracks.trackStateContainer(), std::move(tips),
0079                               std::move(parameters));
0080 
0081   } else {
0082     // no grouping by seed, make one trajectory per track
0083 
0084     for (const auto& track : tracks) {
0085       if (!track.hasReferenceSurface()) {
0086         ACTS_WARNING("Unable to convert track with tip "
0087                      << track.tipIndex()
0088                      << " because no reference surface is set");
0089         continue;
0090       }
0091       Trajectories::IndexedParameters parameters;
0092       parameters.reserve(1);
0093       std::vector<Acts::MultiTrajectoryTraits::IndexType> tips;
0094       tips.reserve(1);
0095 
0096       tips.push_back(track.tipIndex());
0097       parameters.emplace(
0098           std::pair{track.tipIndex(),
0099                     TrackParameters{track.referenceSurface().getSharedPtr(),
0100                                     track.parameters(), track.covariance(),
0101                                     track.particleHypothesis()}});
0102 
0103       trajectories.emplace_back(tracks.trackStateContainer(), std::move(tips),
0104                                 std::move(parameters));
0105     }
0106   }
0107 
0108   m_outputTrajectories(ctx, std::move(trajectories));
0109 
0110   return ProcessCode::SUCCESS;
0111 }
0112 }  // namespace ActsExamples