File indexing completed on 2025-01-18 09:11:15
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp"
0010
0011 namespace Acts {
0012
0013 namespace {
0014
0015
0016
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 }
0032
0033 void GreedyAmbiguityResolution::resolve(State& state) const {
0034
0035
0036 auto sharedMeasurementsComperator = [&state](std::size_t a, std::size_t b) {
0037 return state.sharedMeasurementsPerTrack[a] <
0038 state.sharedMeasurementsPerTrack[b];
0039 };
0040
0041
0042
0043
0044 auto trackComperator = [&state](std::size_t a, std::size_t b) {
0045
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
0059 if (state.selectedTracks.empty()) {
0060 ACTS_VERBOSE("no tracks left - exit loop");
0061 break;
0062 }
0063
0064
0065
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
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 }