Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-18 09:32:56

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 #pragma once
0010 
0011 #include "Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp"
0012 
0013 #include <unordered_map>
0014 
0015 namespace Acts {
0016 
0017 template <TrackContainerFrontend track_container_t, typename source_link_hash_t,
0018           typename source_link_equality_t>
0019 void GreedyAmbiguityResolution::computeInitialState(
0020     const track_container_t& tracks, State& state,
0021     source_link_hash_t&& sourceLinkHash,
0022     source_link_equality_t&& sourceLinkEquality) const {
0023   auto measurementIndexMap =
0024       std::unordered_map<SourceLink, std::size_t, source_link_hash_t,
0025                          source_link_equality_t>(
0026           0, std::forward<source_link_hash_t>(sourceLinkHash),
0027           std::forward<source_link_equality_t>(sourceLinkEquality));
0028 
0029   // Iterate through all input tracks, collect their properties like measurement
0030   // count and chi2 and fill the measurement map in order to relate tracks to
0031   // each other if they have shared hits.
0032   for (const auto& track : tracks) {
0033     // Kick out tracks that do not fulfill our initial requirements
0034     if (track.nMeasurements() < m_cfg.nMeasurementsMin) {
0035       continue;
0036     }
0037     std::vector<std::size_t> measurements;
0038     boost::container::flat_set<std::size_t> splitMeasurements;
0039     for (auto ts : track.trackStatesReversed()) {
0040       if (ts.typeFlags().isMeasurement()) {
0041         SourceLink sourceLink = ts.getUncalibratedSourceLink();
0042         // assign a new measurement index if the source link was not seen yet
0043         auto emplace = measurementIndexMap.try_emplace(
0044             sourceLink, measurementIndexMap.size());
0045         measurements.push_back(emplace.first->second);
0046         // save measurement if it is a split hit
0047         if (ts.typeFlags().isSplitHit()) {
0048           splitMeasurements.insert(emplace.first->second);
0049         }
0050       }
0051     }
0052 
0053     state.trackTips.push_back(track.index());
0054     state.trackChi2.push_back(track.chi2() / static_cast<float>(track.nDoF()));
0055     state.measurementsPerTrack.push_back(std::move(measurements));
0056     state.splitMeasurementsPerTrack.push_back(std::move(splitMeasurements));
0057     state.selectedTracks.insert(state.numberOfTracks);
0058 
0059     ++state.numberOfTracks;
0060   }
0061 
0062   // Now we relate measurements to tracks
0063   for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
0064     for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0065       state.tracksPerMeasurement[iMeasurement].insert(iTrack);
0066     }
0067   }
0068 
0069   // Finally, we can accumulate the number of shared measurements per track
0070   state.sharedMeasurementsPerTrack =
0071       std::vector<std::size_t>(state.trackTips.size(), 0);
0072   for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
0073     for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0074       if (state.tracksPerMeasurement[iMeasurement].size() > 1) {
0075         // only count measurement as "shared" if it is not "split"
0076         if (!state.splitMeasurementsPerTrack[iTrack].contains(iMeasurement)) {
0077           ++state.sharedMeasurementsPerTrack[iTrack];
0078         }
0079       }
0080     }
0081   }
0082 }
0083 
0084 }  // namespace Acts