Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:06:05

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024 Minjung Kim, Barak Schmookler
0003 #include "AmbiguitySolver.h"
0004 
0005 #include <Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp>
0006 #include <Acts/EventData/MeasurementHelpers.hpp>
0007 #include <Acts/EventData/SourceLink.hpp>
0008 #include <Acts/EventData/TrackStatePropMask.hpp>
0009 #include <Acts/EventData/VectorMultiTrajectory.hpp>
0010 #include <Acts/EventData/VectorTrackContainer.hpp>
0011 #if Acts_VERSION_MAJOR < 43
0012 #include <Acts/Utilities/Iterator.hpp>
0013 #endif
0014 #include <ActsExamples/EventData/IndexSourceLink.hpp>
0015 #include <ActsExamples/EventData/Track.hpp>
0016 #include <boost/container/flat_set.hpp>
0017 #include <boost/container/vector.hpp>
0018 #include <spdlog/common.h>
0019 #include <Eigen/LU> // IWYU pragma: keep
0020 #include <any>
0021 #include <cstddef>
0022 #include <gsl/pointers>
0023 #include <string>
0024 #include <utility>
0025 #include <vector>
0026 
0027 #include "Acts/Utilities/Logger.hpp"
0028 #include "AmbiguitySolverConfig.h"
0029 #include "extensions/spdlog/SpdlogFormatters.h" // IWYU pragma: keep
0030 #include "extensions/spdlog/SpdlogToActs.h"
0031 
0032 namespace eicrecon {
0033 
0034 Acts::GreedyAmbiguityResolution::Config
0035 transformConfig(const eicrecon::AmbiguitySolverConfig& cfg) {
0036   Acts::GreedyAmbiguityResolution::Config result;
0037   result.maximumSharedHits = cfg.maximum_shared_hits;
0038   result.maximumIterations = cfg.maximum_iterations;
0039   result.nMeasurementsMin  = cfg.n_measurements_min;
0040   return result;
0041 }
0042 
0043 static std::size_t sourceLinkHash(const Acts::SourceLink& a) {
0044   return static_cast<std::size_t>(a.get<ActsExamples::IndexSourceLink>().index());
0045 }
0046 
0047 static bool sourceLinkEquality(const Acts::SourceLink& a, const Acts::SourceLink& b) {
0048   return a.get<ActsExamples::IndexSourceLink>().index() ==
0049          b.get<ActsExamples::IndexSourceLink>().index();
0050 }
0051 
0052 void AmbiguitySolver::init() {
0053   // Convert algorithm log level to Acts log level
0054   const auto spdlog_level = static_cast<spdlog::level::level_enum>(this->level());
0055   const auto acts_level   = eicrecon::SpdlogToActsLevel(spdlog_level);
0056 
0057   // Create Acts logger with appropriate level
0058   m_acts_logger = Acts::getDefaultLogger("AmbiguitySolver", acts_level);
0059   m_acts_cfg    = transformConfig(m_cfg);
0060   m_core = std::make_unique<Acts::GreedyAmbiguityResolution>(m_acts_cfg, acts_logger().clone());
0061 }
0062 
0063 void AmbiguitySolver::process(const Input& input, const Output& output) const {
0064   const auto [input_track_states, input_tracks] = input;
0065   auto [output_track_states, output_tracks]     = output;
0066 
0067   // Construct ConstTrackContainer from underlying containers
0068   auto trackStateContainer =
0069       std::make_shared<Acts::ConstVectorMultiTrajectory>(*input_track_states);
0070   auto trackContainer = std::make_shared<Acts::ConstVectorTrackContainer>(*input_tracks);
0071   ActsExamples::ConstTrackContainer input_trks(trackContainer, trackStateContainer);
0072 
0073   Acts::GreedyAmbiguityResolution::State state;
0074   m_core->computeInitialState(input_trks, state, &sourceLinkHash, &sourceLinkEquality);
0075   m_core->resolve(state);
0076 
0077   ActsExamples::TrackContainer solvedTracks{std::make_shared<Acts::VectorTrackContainer>(),
0078                                             std::make_shared<Acts::VectorMultiTrajectory>()};
0079   solvedTracks.ensureDynamicColumns(input_trks);
0080 
0081   for (auto iTrack : state.selectedTracks) {
0082     auto destProxy = solvedTracks.makeTrack();
0083     auto srcProxy  = input_trks.getTrack(state.trackTips.at(iTrack));
0084     destProxy.copyFrom(srcProxy);
0085   }
0086 
0087   // Allocate new const containers and assign pointers to outputs
0088   *output_track_states =
0089       new Acts::ConstVectorMultiTrajectory(std::move(solvedTracks.trackStateContainer()));
0090   *output_tracks = new Acts::ConstVectorTrackContainer(std::move(solvedTracks.container()));
0091 }
0092 
0093 } // namespace eicrecon