File indexing completed on 2025-01-18 09:11:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Utilities/EventDataTransforms.hpp"
0010
0011 #include "Acts/EventData/SourceLink.hpp"
0012 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0013 #include "ActsExamples/EventData/SimSpacePoint.hpp"
0014
0015 #include <algorithm>
0016 #include <vector>
0017
0018 ActsExamples::ProtoTrack ActsExamples::seedToPrototrack(
0019 const ActsExamples::SimSeed& seed) {
0020 ProtoTrack track;
0021 track.reserve(seed.sp().size());
0022 for (const auto& spacePoints : seed.sp()) {
0023 for (const auto& slink : spacePoints->sourceLinks()) {
0024 const auto& islink = slink.get<IndexSourceLink>();
0025 track.emplace_back(islink.index());
0026 }
0027 }
0028 return track;
0029 }
0030
0031 const ActsExamples::SimSpacePoint* ActsExamples::findSpacePointForIndex(
0032 ActsExamples::Index index, const SimSpacePointContainer& spacepoints) {
0033 auto match = [&](const SimSpacePoint& sp) {
0034 const auto& sls = sp.sourceLinks();
0035 return std::ranges::any_of(sls, [&](const auto& sl) {
0036 return sl.template get<IndexSourceLink>().index() == index;
0037 });
0038 };
0039
0040 auto found = std::ranges::find_if(spacepoints, match);
0041
0042 if (found == spacepoints.end()) {
0043 return nullptr;
0044 }
0045
0046 return &(*found);
0047 }
0048
0049 ActsExamples::SimSeed ActsExamples::prototrackToSeed(
0050 const ActsExamples::ProtoTrack& track,
0051 const ActsExamples::SimSpacePointContainer& spacepoints) {
0052 auto findSpacePoint = [&](ActsExamples::Index index) {
0053 auto found = findSpacePointForIndex(index, spacepoints);
0054 if (found == nullptr) {
0055 throw std::runtime_error("No spacepoint found for source-link index " +
0056 std::to_string(index));
0057 }
0058 return found;
0059 };
0060
0061 const auto s = track.size();
0062 if (s < 3) {
0063 throw std::runtime_error(
0064 "Cannot convert track with less then 3 spacepoints to seed");
0065 }
0066
0067 std::vector<const SimSpacePoint*> ps;
0068 ps.reserve(track.size());
0069
0070 std::transform(track.begin(), track.end(), std::back_inserter(ps),
0071 findSpacePoint);
0072 std::ranges::sort(ps, {}, [](const auto& p) { return p->r(); });
0073
0074
0075
0076 const auto m =
0077 (ps.back()->r() - ps.front()->r()) / (ps.back()->z() - ps.front()->z());
0078 const auto t = ps.front()->r() - m * ps.front()->z();
0079 const auto z_vertex = -t / m;
0080
0081 SimSeed seed(*ps[0], *ps[s / 2], *ps[s - 1]);
0082 seed.setVertexZ(z_vertex);
0083 return seed;
0084 }