Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-17 09:21:10

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 #pragma once
0010 
0011 #include "Acts/EventData/TrackContainerFrontendConcept.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013 
0014 #include <memory>
0015 
0016 #include <boost/container/flat_map.hpp>
0017 #include <boost/container/flat_set.hpp>
0018 
0019 namespace Acts {
0020 
0021 /// Evicts tracks that seem to be duplicates or fakes. This algorithm takes a
0022 /// greedy approach in the sense that it will remove the track which looks "most
0023 /// duplicate/fake" first and continues the same process with the rest. That
0024 /// process continues until the final state conditions are met.
0025 ///
0026 /// The implementation works as follows:
0027 ///  1) Calculate shared hits per track.
0028 ///  2) If the maximum shared hits criteria is met, we are done.
0029 ///     This is the configurable amount of shared hits we are ok with
0030 ///     in our experiment.
0031 ///  3) Else, remove the track with the highest relative shared hits (i.e.
0032 ///     shared hits / hits).
0033 ///  4) Back to square 1.
0034 class GreedyAmbiguityResolution {
0035  public:
0036   /// Configuration parameters for greedy ambiguity resolution.
0037   struct Config {
0038     /// Maximum amount of shared hits per track.
0039     std::uint32_t maximumSharedHits = 0;
0040     /// Maximum number of iterations
0041     std::uint32_t maximumIterations = 1000;
0042 
0043     /// Minimum number of measurement to form a track.
0044     std::size_t nMeasurementsMin = 7;
0045   };
0046 
0047   /// Mutable state used by the greedy ambiguity resolution.
0048   struct State {
0049     /// Total number of tracks
0050     std::size_t numberOfTracks{};
0051 
0052     /// Track tips for each track
0053     std::vector<int> trackTips;
0054     /// Chi-squared value for each track
0055     std::vector<float> trackChi2;
0056     /// Measurement indices for each track
0057     std::vector<std::vector<std::size_t>> measurementsPerTrack;
0058     /// Set of split measurements for each track
0059     std::vector<boost::container::flat_set<std::size_t>>
0060         splitMeasurementsPerTrack;
0061 
0062     // TODO consider boost 1.81 unordered_flat_map
0063     /// Map from measurement index to set of track indices using it
0064     boost::container::flat_map<std::size_t,
0065                                boost::container::flat_set<std::size_t>>
0066         tracksPerMeasurement;
0067     /// Number of shared measurements for each track
0068     std::vector<std::size_t> sharedMeasurementsPerTrack;
0069 
0070     // TODO consider boost 1.81 unordered_flat_map
0071     /// Set of track indices selected as good tracks
0072     boost::container::flat_set<std::size_t> selectedTracks;
0073   };
0074 
0075   /// Constructor with configuration and logger
0076   /// @param cfg Configuration for ambiguity resolution
0077   /// @param logger Logger for diagnostic output
0078   explicit GreedyAmbiguityResolution(
0079       const Config& cfg,
0080       std::unique_ptr<const Logger> logger =
0081           getDefaultLogger("GreedyAmbiguityResolution", Logging::INFO))
0082       : m_cfg{cfg}, m_logger{std::move(logger)} {}
0083 
0084   /// Computes the initial state for the input data. This function accumulates
0085   /// information that will later be used to accelerate the ambiguity
0086   /// resolution.
0087   ///
0088   /// @param tracks The input track container.
0089   /// @param state An empty state object which is expected to be default constructed.
0090   /// @param sourceLinkHash A functor to acquire a hash from a given source link.
0091   /// @param sourceLinkEquality A functor to check equality of two source links.
0092   template <TrackContainerFrontend track_container_t,
0093             typename source_link_hash_t, typename source_link_equality_t>
0094   void computeInitialState(const track_container_t& tracks, State& state,
0095                            source_link_hash_t&& sourceLinkHash,
0096                            source_link_equality_t&& sourceLinkEquality) const;
0097 
0098   /// Updates the state iteratively by evicting one track after the other until
0099   /// the final state conditions are met.
0100   ///
0101   /// @param state A state object that was previously filled by the initialization.
0102   void resolve(State& state) const;
0103 
0104  private:
0105   Config m_cfg;
0106 
0107   /// Logging instance
0108   std::unique_ptr<const Logger> m_logger;
0109 
0110   /// Private access to logging instance
0111   const Logger& logger() const { return *m_logger; }
0112 };
0113 
0114 }  // namespace Acts
0115 
0116 #include "Acts/AmbiguityResolution/GreedyAmbiguityResolution.ipp"