Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GreedyAmbiguityResolution.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GreedyAmbiguityResolution.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
12 
13 #include <unordered_map>
14 
15 namespace Acts {
16 
17 template <typename track_container_t, typename traj_t,
18  template <typename> class holder_t, typename source_link_hash_t,
19  typename source_link_equality_t>
20 void GreedyAmbiguityResolution::computeInitialState(
21  const TrackContainer<track_container_t, traj_t, holder_t>& tracks,
22  State& state, source_link_hash_t&& sourceLinkHash,
23  source_link_equality_t&& sourceLinkEquality) const {
24  auto measurementIndexMap =
25  std::unordered_map<SourceLink, std::size_t, source_link_hash_t,
26  source_link_equality_t>(0, sourceLinkHash,
27  sourceLinkEquality);
28 
29  // Iterate through all input tracks, collect their properties like measurement
30  // count and chi2 and fill the measurement map in order to relate tracks to
31  // each other if they have shared hits.
32  for (const auto& track : tracks) {
33  // Kick out tracks that do not fulfill our initial requirements
34  if (track.nMeasurements() < m_cfg.nMeasurementsMin) {
35  continue;
36  }
37  std::vector<std::size_t> measurements;
38  for (auto ts : track.trackStatesReversed()) {
39  if (ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
40  SourceLink sourceLink = ts.getUncalibratedSourceLink();
41  // assign a new measurement index if the source link was not seen yet
42  auto emplace = measurementIndexMap.try_emplace(
43  sourceLink, measurementIndexMap.size());
44  measurements.push_back(emplace.first->second);
45  }
46  }
47 
48  state.trackTips.push_back(track.index());
49  state.trackChi2.push_back(track.chi2() / track.nDoF());
50  state.measurementsPerTrack.push_back(std::move(measurements));
51  state.selectedTracks.insert(state.numberOfTracks);
52 
53  ++state.numberOfTracks;
54  }
55 
56  // Now we relate measurements to tracks
57  for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
58  for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
59  state.tracksPerMeasurement[iMeasurement].insert(iTrack);
60  }
61  }
62 
63  // Finally, we can accumulate the number of shared measurements per track
64  state.sharedMeasurementsPerTrack =
65  std::vector<std::size_t>(state.trackTips.size(), 0);
66  for (std::size_t iTrack = 0; iTrack < state.numberOfTracks; ++iTrack) {
67  for (auto iMeasurement : state.measurementsPerTrack[iTrack]) {
68  if (state.tracksPerMeasurement[iMeasurement].size() > 1) {
69  ++state.sharedMeasurementsPerTrack[iTrack];
70  }
71  }
72  }
73 }
74 
75 } // namespace Acts