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