Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:32

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 #pragma once
0010 
0011 #include "Acts/AmbiguityResolution/GreedyAmbiguityResolution.hpp"
0012 
0013 #include <unordered_map>
0014 
0015 namespace Acts {
0016 
0017 template <typename track_container_t, typename traj_t,
0018           template <typename> class holder_t, typename source_link_hash_t,
0019           typename source_link_equality_t>
0020 void GreedyAmbiguityResolution::computeInitialState(
0021     const TrackContainer<track_container_t, traj_t, holder_t>& tracks,
0022     State& state, 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       if (ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
0040         SourceLink sourceLink = ts.getUncalibratedSourceLink();
0041         // assign a new measurement index if the source link was not seen yet
0042         auto emplace = measurementIndexMap.try_emplace(
0043             sourceLink, measurementIndexMap.size());
0044         measurements.push_back(emplace.first->second);
0045       }
0046     }
0047 
0048     state.trackTips.push_back(track.index());
0049     state.trackChi2.push_back(track.chi2() / track.nDoF());
0050     state.measurementsPerTrack.push_back(std::move(measurements));
0051     state.selectedTracks.insert(state.numberOfTracks);
0052 
0053     ++state.numberOfTracks;
0054   }
0055 
0056   // Now we relate measurements to tracks
0057   for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
0058     for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0059       state.tracksPerMeasurement[iMeasurement].insert(iTrack);
0060     }
0061   }
0062 
0063   // Finally, we can accumulate the number of shared measurements per track
0064   state.sharedMeasurementsPerTrack =
0065       std::vector<std::size_t>(state.trackTips.size(), 0);
0066   for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
0067     for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
0068       if (state.tracksPerMeasurement[iMeasurement].size() > 1) {
0069         ++state.sharedMeasurementsPerTrack[iTrack];
0070       }
0071     }
0072   }
0073 }
0074 
0075 }  // namespace Acts