Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceSortingAlgorithm.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceSortingAlgorithm.cpp
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 
10 
14 
15 #include <cstddef>
16 #include <memory>
17 #include <stdexcept>
18 #include <utility>
19 #include <vector>
20 
21 namespace ActsExamples {
22 struct AlgorithmContext;
23 } // namespace ActsExamples
24 
27  : ActsExamples::IAlgorithm("SurfaceSortingAlgorithm", level),
28  m_cfg(std::move(cfg)) {
29  if (m_cfg.inputProtoTracks.empty()) {
30  throw std::invalid_argument("Missing input proto track collection");
31  }
32  if (m_cfg.inputSimHits.empty()) {
33  throw std::invalid_argument("Missing input simulated hits collection");
34  }
35  if (m_cfg.inputMeasurementSimHitsMap.empty()) {
36  throw std::invalid_argument("Missing input measurement sim hits map");
37  }
38  if (m_cfg.outputProtoTracks.empty()) {
39  throw std::invalid_argument("Missing output proto track collection");
40  }
41 
46 }
47 
49  const ActsExamples::AlgorithmContext& ctx) const {
50  const auto& protoTracks = m_inputProtoTracks(ctx);
51  const auto& simHits = m_inputSimHits(ctx);
52  const auto& simHitsMap = m_inputMeasurementSimHitsMap(ctx);
53 
54  ProtoTrackContainer sortedTracks;
55  sortedTracks.reserve(protoTracks.size());
56  TrackHitList trackHitList;
57 
58  for (std::size_t itrack = 0; itrack < protoTracks.size(); ++itrack) {
59  const auto& protoTrack = protoTracks[itrack];
60 
61  ProtoTrack sortedProtoTrack;
62  sortedProtoTrack.reserve(protoTrack.size());
63  trackHitList.clear();
64 
65  if (protoTrack.empty()) {
66  continue;
67  }
68 
69  for (const auto hit : protoTrack) {
70  const auto simHitIndex = simHitsMap.find(hit)->second;
71  auto simHit = simHits.nth(simHitIndex);
72  auto simHitTime = simHit->time();
73  trackHitList.insert(std::make_pair(simHitTime, hit));
74  }
75 
77  for (auto const& [time, hit] : trackHitList) {
78  sortedProtoTrack.emplace_back(hit);
79  }
80 
81  sortedTracks.emplace_back(std::move(sortedProtoTrack));
82  }
83 
84  m_outputProtoTracks(ctx, std::move(sortedTracks));
85 
87 }