Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventDataTransforms.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventDataTransforms.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 
14 
15 #include <vector>
16 
18  const ActsExamples::SimSeed& seed) {
19  ProtoTrack track;
20  track.reserve(seed.sp().size());
21  for (auto spacePointPtr : seed.sp()) {
22  for (const auto& slink : spacePointPtr->sourceLinks()) {
23  const auto& islink = slink.get<IndexSourceLink>();
24  track.emplace_back(islink.index());
25  }
26  }
27  return track;
28 }
29 
31  ActsExamples::Index index, const SimSpacePointContainer& spacepoints) {
32  auto match = [&](const SimSpacePoint& sp) {
33  const auto& sls = sp.sourceLinks();
34  return std::any_of(sls.begin(), sls.end(), [&](const auto& sl) {
35  return sl.template get<IndexSourceLink>().index() == index;
36  });
37  };
38 
39  auto found = std::find_if(spacepoints.begin(), spacepoints.end(), match);
40 
41  if (found == spacepoints.end()) {
42  return nullptr;
43  }
44 
45  return &(*found);
46 }
47 
49  const ActsExamples::ProtoTrack& track,
50  const ActsExamples::SimSpacePointContainer& spacepoints) {
51  auto findSpacePoint = [&](ActsExamples::Index index) {
52  auto found = findSpacePointForIndex(index, spacepoints);
53  if (found == nullptr) {
54  throw std::runtime_error("No spacepoint found for source-link index " +
56  }
57  return found;
58  };
59 
60  const auto s = track.size();
61  if (s < 3) {
62  throw std::runtime_error(
63  "Cannot convert track with less then 3 spacepoints to seed");
64  }
65 
66  std::vector<const SimSpacePoint*> ps;
67  ps.reserve(track.size());
68 
69  std::transform(track.begin(), track.end(), std::back_inserter(ps),
70  findSpacePoint);
71  std::sort(ps.begin(), ps.end(),
72  [](const auto& a, const auto& b) { return a->r() < b->r(); });
73 
74  // Simply use r = m*z + t and solve for r=0 to find z vertex position...
75  // Probably not the textbook way to do
76  const auto m =
77  (ps.back()->r() - ps.front()->r()) / (ps.back()->z() - ps.front()->z());
78  const auto t = ps.front()->r() - m * ps.front()->z();
79  const auto z_vertex = -t / m;
80 
81  return SimSeed(*ps[0], *ps[s / 2], *ps[s - 1], z_vertex);
82 }