File indexing completed on 2026-09-14 08:19:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/AmbiguityResolution/GreedyAmbiguityResolutionAlgorithm.hpp"
0010
0011 #include "Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0014 #include "ActsExamples/Framework/ProcessCode.hpp"
0015
0016 #include <cstddef>
0017 #include <stdexcept>
0018
0019 #include <boost/container/flat_map.hpp>
0020 #include <boost/container/flat_set.hpp>
0021
0022 namespace ActsExamples {
0023
0024 namespace {
0025
0026 Acts::GreedyAmbiguityResolution::Config transformConfig(
0027 const GreedyAmbiguityResolutionAlgorithm::Config& cfg) {
0028 Acts::GreedyAmbiguityResolution::Config result;
0029 result.maximumSharedHits = cfg.maximumSharedHits;
0030 result.maximumIterations = cfg.maximumIterations;
0031 result.nMeasurementsMin = cfg.nMeasurementsMin;
0032 return result;
0033 }
0034
0035 std::size_t sourceLinkHash(const Acts::SourceLink& a) {
0036 return static_cast<std::size_t>(a.get<IndexSourceLink>().index());
0037 }
0038
0039 bool sourceLinkEquality(const Acts::SourceLink& a, const Acts::SourceLink& b) {
0040 return a.get<IndexSourceLink>().index() == b.get<IndexSourceLink>().index();
0041 }
0042
0043 }
0044
0045 GreedyAmbiguityResolutionAlgorithm::GreedyAmbiguityResolutionAlgorithm(
0046 const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
0047 : IAlgorithm("GreedyAmbiguityResolutionAlgorithm", std::move(logger)),
0048 m_cfg(cfg),
0049 m_core(transformConfig(cfg), this->logger().clone()) {
0050 if (m_cfg.inputTracks.empty()) {
0051 throw std::invalid_argument("Missing trajectories input collection");
0052 }
0053 if (m_cfg.outputTracks.empty()) {
0054 throw std::invalid_argument("Missing trajectories output collection");
0055 }
0056 m_inputTracks.initialize(m_cfg.inputTracks);
0057 m_outputTracks.initialize(m_cfg.outputTracks);
0058 }
0059
0060 ProcessCode GreedyAmbiguityResolutionAlgorithm::execute(
0061 const AlgorithmContext& ctx) const {
0062 const auto& tracks = m_inputTracks(ctx);
0063
0064 ACTS_VERBOSE("Number of input tracks: " << tracks.size());
0065
0066 Acts::GreedyAmbiguityResolution::State state;
0067 m_core.computeInitialState(tracks, state, &sourceLinkHash,
0068 &sourceLinkEquality);
0069
0070 ACTS_VERBOSE("State initialized");
0071
0072 m_core.resolve(state);
0073
0074 ACTS_DEBUG("Resolved to " << state.selectedTracks.size() << " tracks from "
0075 << tracks.size());
0076
0077 TrackContainer solvedTracks{std::make_shared<Acts::VectorTrackContainer>(),
0078 std::make_shared<Acts::VectorMultiTrajectory>()};
0079 solvedTracks.ensureDynamicColumns(tracks);
0080
0081 for (auto iTrack : state.selectedTracks) {
0082 auto destProxy = solvedTracks.makeTrack();
0083 auto srcProxy = tracks.getTrack(state.trackTips.at(iTrack));
0084 destProxy.copyFromWithoutStates(srcProxy);
0085 destProxy.tipIndex() = srcProxy.tipIndex();
0086 }
0087
0088 ConstTrackContainer outputTracks{
0089 std::make_shared<Acts::ConstVectorTrackContainer>(
0090 std::move(solvedTracks.container())),
0091 tracks.trackStateContainerHolder()};
0092
0093 m_outputTracks(ctx, std::move(outputTracks));
0094 return ProcessCode::SUCCESS;
0095 }
0096
0097 }