Back to home page

EIC code displayed by LXR

 
 

    


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

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/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 backward over all the tracks
0025   for (auto track = trackMap.rbegin(); track != trackMap.rend(); ++track) {
0026     const auto& trackValue = track->second;
0027     std::vector<std::size_t> hits = trackValue.second;
0028     auto matchedTrack = hitToTrack.end();
0029     // Loop over all the hits in the track
0030     for (const auto& hit : hits) {
0031       // Check if the hit is already associated to a track
0032       matchedTrack = hitToTrack.find(hit);
0033       if (matchedTrack != hitToTrack.end()) {
0034         // Add the track to the cluster associated to the matched track
0035         cluster.at(matchedTrack->second).push_back(trackValue.first);
0036         break;
0037       }
0038     }
0039     // None of the hits have been matched to a track create a new cluster
0040     if (matchedTrack == hitToTrack.end()) {
0041       cluster.emplace(trackValue.first,
0042                       std::vector<std::size_t>(1, trackValue.first));
0043       for (const auto& hit : hits) {
0044         // Add the hits of the new cluster to the hitToTrack
0045         hitToTrack.emplace(hit, trackValue.first);
0046       }
0047     }
0048   }
0049   return cluster;
0050 }