Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:41

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/TrackFinding/detail/AmbiguityTrackClustering.hpp"
0010 
0011 #include <iterator>
0012 
0013 std::unordered_map<std::size_t, std::vector<std::size_t>>
0014 Acts::detail::clusterDuplicateTracks(
0015     const std::multimap<int, std::pair<std::size_t, std::vector<std::size_t>>>&
0016         trackMap) {
0017   // Unordered map associating a vector with all the track ID of a cluster to
0018   // the ID of the first track of the cluster
0019   std::unordered_map<std::size_t, std::vector<std::size_t>> cluster;
0020   // Unordered map associating hits to the ID of the first track of the
0021   // different clusters.
0022   std::unordered_map<std::size_t, std::size_t> hitToTrack;
0023 
0024   // Loop over all the tracks
0025   for (auto track = trackMap.rbegin(); track != trackMap.rend(); ++track) {
0026     std::vector<std::size_t> hits = track->second.second;
0027     auto matchedTrack = hitToTrack.end();
0028     // Loop over all the hits in the track
0029     for (auto hit = hits.begin(); hit != hits.end(); hit++) {
0030       // Check if the hit is already associated to a track
0031       matchedTrack = hitToTrack.find(*hit);
0032       if (matchedTrack != hitToTrack.end()) {
0033         // Add the track to the cluster associated to the matched track
0034         cluster.at(matchedTrack->second).push_back(track->second.first);
0035         break;
0036       }
0037     }
0038     // None of the hits have been matched to a track create a new cluster
0039     if (matchedTrack == hitToTrack.end()) {
0040       cluster.emplace(track->second.first,
0041                       std::vector<std::size_t>(1, track->second.first));
0042       for (const auto& hit : hits) {
0043         // Add the hits of the new cluster to the hitToTrack
0044         hitToTrack.emplace(hit, track->second.first);
0045       }
0046     }
0047   }
0048   return cluster;
0049 }