Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GreedyAmbiguityResolution.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GreedyAmbiguityResolution.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 namespace Acts {
12 
13 namespace {
14 
17 static void removeTrack(GreedyAmbiguityResolution::State& state,
18  std::size_t iTrack) {
19  for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
20  state.tracksPerMeasurement[iMeasurement].erase(iTrack);
21 
22  if (state.tracksPerMeasurement[iMeasurement].size() == 1) {
23  auto jTrack = *state.tracksPerMeasurement[iMeasurement].begin();
24  --state.sharedMeasurementsPerTrack[jTrack];
25  }
26  }
27 
28  state.selectedTracks.erase(iTrack);
29 }
30 
31 } // namespace
32 
36  auto sharedMeasurementsComperator = [&state](std::size_t a, std::size_t b) {
37  return state.sharedMeasurementsPerTrack[a] <
39  };
40 
44  auto trackComperator = [&state](std::size_t a, std::size_t b) {
46  auto relativeSharedMeasurements = [&state](std::size_t i) {
47  return 1.0 * state.sharedMeasurementsPerTrack[i] /
48  state.measurementsPerTrack[i].size();
49  };
50 
51  if (relativeSharedMeasurements(a) != relativeSharedMeasurements(b)) {
52  return relativeSharedMeasurements(a) < relativeSharedMeasurements(b);
53  }
54  return state.trackChi2[a] < state.trackChi2[b];
55  };
56 
57  for (std::size_t i = 0; i < m_cfg.maximumIterations; ++i) {
58  // Lazy out if there is nothing to filter on.
59  if (state.selectedTracks.empty()) {
60  ACTS_VERBOSE("no tracks left - exit loop");
61  break;
62  }
63 
64  // Find the maximum amount of shared measurements per track to decide if we
65  // are done or not.
66  auto maximumSharedMeasurements = *std::max_element(
67  state.selectedTracks.begin(), state.selectedTracks.end(),
68  sharedMeasurementsComperator);
70  "maximum shared measurements "
71  << state.sharedMeasurementsPerTrack[maximumSharedMeasurements]);
72  if (state.sharedMeasurementsPerTrack[maximumSharedMeasurements] <
74  break;
75  }
76 
77  // Find the "worst" track by comparing them to each other
78  auto badTrack =
79  *std::max_element(state.selectedTracks.begin(),
80  state.selectedTracks.end(), trackComperator);
81  ACTS_VERBOSE("remove track "
82  << badTrack << " nMeas "
83  << state.measurementsPerTrack[badTrack].size() << " nShared "
84  << state.sharedMeasurementsPerTrack[badTrack] << " chi2 "
85  << state.trackChi2[badTrack]);
86  removeTrack(state, badTrack);
87  }
88 }
89 
90 } // namespace Acts