Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:44

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 #include "Acts/EventData/TrackStateType.hpp"
0013 
0014 #include <unordered_map>
0015 
0016 namespace Acts {
0017 
0018 template <TrackContainerFrontend track_container_t, typename source_link_hash_t,
0019           typename source_link_equality_t>
0020 void GreedyAmbiguityResolution::computeInitialState(
0021     const track_container_t& tracks, State& state,
0022     source_link_hash_t&& sourceLinkHash,
0023     source_link_equality_t&& sourceLinkEquality) const {
0024   auto measurementIndexMap =
0025       std::unordered_map<SourceLink, std::size_t, source_link_hash_t,
0026                          source_link_equality_t>(0, sourceLinkHash,
0027                                                  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     for (auto ts : track.trackStatesReversed()) {
0039       bool isMeasurement = ts.typeFlags().test(TrackStateFlag::MeasurementFlag);
0040       bool isOutlier = ts.typeFlags().test(TrackStateFlag::OutlierFlag);
0041       if (isMeasurement && !isOutlier) {
0042         SourceLink sourceLink = ts.getUncalibratedSourceLink();
0043         // assign a new measurement index if the source link was not seen yet
0044         auto emplace = measurementIndexMap.try_emplace(
0045             sourceLink, measurementIndexMap.size());
0046         measurements.push_back(emplace.first->second);
0047       }
0048     }
0049 
0050     state.trackTips.push_back(track.index());
0051     state.trackChi2.push_back(track.chi2() / track.nDoF());
0052     state.measurementsPerTrack.push_back(std::move(measurements));
0053     state.selectedTracks.insert(state.numberOfTracks);
0054 
0055     ++state.numberOfTracks;
0056   }
0057 
0058   // Now we relate measurements to tracks
0059   for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
0060     for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0061       state.tracksPerMeasurement[iMeasurement].insert(iTrack);
0062     }
0063   }
0064 
0065   // Finally, we can accumulate the number of shared measurements per track
0066   state.sharedMeasurementsPerTrack =
0067       std::vector<std::size_t>(state.trackTips.size(), 0);
0068   for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
0069     for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0070       if (state.tracksPerMeasurement[iMeasurement].size() > 1) {
0071         ++state.sharedMeasurementsPerTrack[iTrack];
0072       }
0073     }
0074   }
0075 }
0076 
0077 }  // namespace Acts