Back to home page

EIC code displayed by LXR

 
 

    


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

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 "Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp"
0010 
0011 namespace Acts {
0012 
0013 namespace {
0014 
0015 /// Removes a track from the state which has to be done for multiple properties
0016 /// because of redundancy.
0017 static void removeTrack(GreedyAmbiguityResolution::State& state,
0018                         std::size_t iTrack) {
0019   for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0020     state.tracksPerMeasurement[iMeasurement].erase(iTrack);
0021 
0022     if (state.tracksPerMeasurement[iMeasurement].size() == 1) {
0023       auto jTrack = *state.tracksPerMeasurement[iMeasurement].begin();
0024       --state.sharedMeasurementsPerTrack[jTrack];
0025     }
0026   }
0027 
0028   state.selectedTracks.erase(iTrack);
0029 }
0030 
0031 }  // namespace
0032 
0033 void GreedyAmbiguityResolution::resolve(State& state) const {
0034   /// Compares two tracks based on the number of shared measurements in order to
0035   /// decide if we already met the final state.
0036   auto sharedMeasurementsComperator = [&state](std::size_t a, std::size_t b) {
0037     return state.sharedMeasurementsPerTrack[a] <
0038            state.sharedMeasurementsPerTrack[b];
0039   };
0040 
0041   /// Compares two tracks in order to find the one which should be evicted.
0042   /// First we compare the relative amount of shared measurements. If that is
0043   /// indecisive we use the chi2.
0044   auto trackComperator = [&state](std::size_t a, std::size_t b) {
0045     /// Helper to calculate the relative amount of shared measurements.
0046     auto relativeSharedMeasurements = [&state](std::size_t i) {
0047       return 1.0 * state.sharedMeasurementsPerTrack[i] /
0048              state.measurementsPerTrack[i].size();
0049     };
0050 
0051     if (relativeSharedMeasurements(a) != relativeSharedMeasurements(b)) {
0052       return relativeSharedMeasurements(a) < relativeSharedMeasurements(b);
0053     }
0054     return state.trackChi2[a] < state.trackChi2[b];
0055   };
0056 
0057   for (std::size_t i = 0; i < m_cfg.maximumIterations; ++i) {
0058     // Lazy out if there is nothing to filter on.
0059     if (state.selectedTracks.empty()) {
0060       ACTS_VERBOSE("no tracks left - exit loop");
0061       break;
0062     }
0063 
0064     // Find the maximum amount of shared measurements per track to decide if we
0065     // are done or not.
0066     auto maximumSharedMeasurements = *std::max_element(
0067         state.selectedTracks.begin(), state.selectedTracks.end(),
0068         sharedMeasurementsComperator);
0069     ACTS_VERBOSE(
0070         "maximum shared measurements "
0071         << state.sharedMeasurementsPerTrack[maximumSharedMeasurements]);
0072     if (state.sharedMeasurementsPerTrack[maximumSharedMeasurements] <
0073         m_cfg.maximumSharedHits) {
0074       break;
0075     }
0076 
0077     // Find the "worst" track by comparing them to each other
0078     auto badTrack =
0079         *std::max_element(state.selectedTracks.begin(),
0080                           state.selectedTracks.end(), trackComperator);
0081     ACTS_VERBOSE("remove track "
0082                  << badTrack << " nMeas "
0083                  << state.measurementsPerTrack[badTrack].size() << " nShared "
0084                  << state.sharedMeasurementsPerTrack[badTrack] << " chi2 "
0085                  << state.trackChi2[badTrack]);
0086     removeTrack(state, badTrack);
0087   }
0088 }
0089 
0090 }  // namespace Acts