Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AmbiguityTrackClustering.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AmbiguityTrackClustering.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 #include <iterator>
12 
13 std::unordered_map<int, std::vector<int>> Acts::detail::clusterDuplicateTracks(
14  const std::multimap<int, std::pair<int, std::vector<int>>>& trackMap) {
15  // Unordered map associating a vector with all the track ID of a cluster to
16  // the ID of the first track of the cluster
17  std::unordered_map<int, std::vector<int>> cluster;
18  // Unordered map associating hits to the ID of the first track of the
19  // different clusters.
20  std::unordered_map<int, int> hitToTrack;
21 
22  // Loop over all the tracks
23  for (auto track = trackMap.rbegin(); track != trackMap.rend(); ++track) {
24  std::vector<int> hits = track->second.second;
25  auto matchedTrack = hitToTrack.end();
26  // Loop over all the hits in the track
27  for (auto hit = hits.begin(); hit != hits.end(); hit++) {
28  // Check if the hit is already associated to a track
29  matchedTrack = hitToTrack.find(*hit);
30  if (matchedTrack != hitToTrack.end()) {
31  // Add the track to the cluster associated to the matched track
32  cluster.at(matchedTrack->second).push_back(track->second.first);
33  break;
34  }
35  }
36  // None of the hits have been matched to a track create a new cluster
37  if (matchedTrack == hitToTrack.end()) {
38  cluster.emplace(track->second.first,
39  std::vector<int>(1, track->second.first));
40  for (const auto& hit : hits) {
41  // Add the hits of the new cluster to the hitToTrack
42  hitToTrack.emplace(hit, track->second.first);
43  }
44  }
45  }
46  return cluster;
47 }