Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:54

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
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 <vector>
0016 
0017 ActsExamples::ProtoTrack ActsExamples::seedToPrototrack(
0018     const ActsExamples::SimSeed& seed) {
0019   ProtoTrack track;
0020   track.reserve(seed.sp().size());
0021   for (auto spacePointPtr : seed.sp()) {
0022     for (const auto& slink : spacePointPtr->sourceLinks()) {
0023       const auto& islink = slink.get<IndexSourceLink>();
0024       track.emplace_back(islink.index());
0025     }
0026   }
0027   return track;
0028 }
0029 
0030 const ActsExamples::SimSpacePoint* ActsExamples::findSpacePointForIndex(
0031     ActsExamples::Index index, const SimSpacePointContainer& spacepoints) {
0032   auto match = [&](const SimSpacePoint& sp) {
0033     const auto& sls = sp.sourceLinks();
0034     return std::any_of(sls.begin(), sls.end(), [&](const auto& sl) {
0035       return sl.template get<IndexSourceLink>().index() == index;
0036     });
0037   };
0038 
0039   auto found = std::find_if(spacepoints.begin(), spacepoints.end(), match);
0040 
0041   if (found == spacepoints.end()) {
0042     return nullptr;
0043   }
0044 
0045   return &(*found);
0046 }
0047 
0048 ActsExamples::SimSeed ActsExamples::prototrackToSeed(
0049     const ActsExamples::ProtoTrack& track,
0050     const ActsExamples::SimSpacePointContainer& spacepoints) {
0051   auto findSpacePoint = [&](ActsExamples::Index index) {
0052     auto found = findSpacePointForIndex(index, spacepoints);
0053     if (found == nullptr) {
0054       throw std::runtime_error("No spacepoint found for source-link index " +
0055                                std::to_string(index));
0056     }
0057     return found;
0058   };
0059 
0060   const auto s = track.size();
0061   if (s < 3) {
0062     throw std::runtime_error(
0063         "Cannot convert track with less then 3 spacepoints to seed");
0064   }
0065 
0066   std::vector<const SimSpacePoint*> ps;
0067   ps.reserve(track.size());
0068 
0069   std::transform(track.begin(), track.end(), std::back_inserter(ps),
0070                  findSpacePoint);
0071   std::sort(ps.begin(), ps.end(),
0072             [](const auto& a, const auto& b) { return a->r() < b->r(); });
0073 
0074   // Simply use r = m*z + t and solve for r=0 to find z vertex position...
0075   // Probably not the textbook way to do
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   return SimSeed(*ps[0], *ps[s / 2], *ps[s - 1], z_vertex);
0082 }