Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GreedyAmbiguityResolutionAlgorithm.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GreedyAmbiguityResolutionAlgorithm.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
10 
18 
19 #include <cstddef>
20 #include <iterator>
21 #include <numeric>
22 #include <stdexcept>
23 
24 #include <boost/container/flat_map.hpp>
25 #include <boost/container/flat_set.hpp>
26 
27 namespace {
28 
35  return result;
36 }
37 
38 std::size_t sourceLinkHash(const Acts::SourceLink& a) {
39  return static_cast<std::size_t>(
41 }
42 
43 bool sourceLinkEquality(const Acts::SourceLink& a, const Acts::SourceLink& b) {
44  return a.get<ActsExamples::IndexSourceLink>().index() ==
46 }
47 
48 } // namespace
49 
54  : ActsExamples::IAlgorithm("GreedyAmbiguityResolutionAlgorithm", lvl),
55  m_cfg(std::move(cfg)),
56  m_core(transformConfig(cfg), logger().clone()) {
57  if (m_cfg.inputTracks.empty()) {
58  throw std::invalid_argument("Missing trajectories input collection");
59  }
60  if (m_cfg.outputTracks.empty()) {
61  throw std::invalid_argument("Missing trajectories output collection");
62  }
65 }
66 
69  const AlgorithmContext& ctx) const {
70  const auto& tracks = m_inputTracks(ctx);
71 
72  ACTS_VERBOSE("Number of input tracks: " << tracks.size());
73 
75  m_core.computeInitialState(tracks, state, &sourceLinkHash,
76  &sourceLinkEquality);
77 
78  ACTS_VERBOSE("State initialized");
79 
80  m_core.resolve(state);
81 
82  ACTS_INFO("Resolved to " << state.selectedTracks.size() << " tracks from "
83  << tracks.size());
84 
85  TrackContainer solvedTracks{std::make_shared<Acts::VectorTrackContainer>(),
86  std::make_shared<Acts::VectorMultiTrajectory>()};
87  solvedTracks.ensureDynamicColumns(tracks);
88 
89  for (auto iTrack : state.selectedTracks) {
90  auto destProxy = solvedTracks.getTrack(solvedTracks.addTrack());
91  auto srcProxy = tracks.getTrack(state.trackTips.at(iTrack));
92  destProxy.copyFrom(srcProxy, false);
93  destProxy.tipIndex() = srcProxy.tipIndex();
94  }
95 
97  std::make_shared<Acts::ConstVectorTrackContainer>(
98  std::move(solvedTracks.container())),
99  tracks.trackStateContainerHolder()};
100 
101  m_outputTracks(ctx, std::move(outputTracks));
103 }