Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 08:19:51

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Utilities/EventDataTransforms.hpp"
0010 
0011 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0012 #include "ActsExamples/EventData/SpacePoint.hpp"
0013 
0014 #include <algorithm>
0015 #include <vector>
0016 
0017 ActsExamples::ProtoTrack ActsExamples::seedToProtoTrack(
0018     const ConstSeedProxy& seed) {
0019   ProtoTrack track;
0020   track.reserve(seed.size());
0021   for (const auto& sp : seed.spacePoints()) {
0022     for (const auto& slink : sp.sourceLinks()) {
0023       const auto& islink = slink.get<IndexSourceLink>();
0024       track.emplace_back(islink.index());
0025     }
0026   }
0027   return track;
0028 }
0029 
0030 std::optional<ActsExamples::ConstSpacePointProxy>
0031 ActsExamples::findSpacePointForIndex(Index index,
0032                                      const SpacePointContainer& spacePoints) {
0033   auto match = [&](const ConstSpacePointProxy& sp) {
0034     return std::ranges::any_of(
0035         sp.sourceLinks(), [&](const Acts::SourceLink& sl) {
0036           return sl.template get<IndexSourceLink>().index() == index;
0037         });
0038   };
0039 
0040   auto found = std::ranges::find_if(spacePoints, match);
0041   if (found == spacePoints.end()) {
0042     return std::nullopt;
0043   }
0044   return *found;
0045 }
0046 
0047 ActsExamples::SeedProxy ActsExamples::protoTrackToSeed(
0048     const ProtoTrack& track, const SpacePointContainer& spacePoints,
0049     SeedContainer& seeds) {
0050   auto findSpacePoint = [&](Index index) -> SpacePointIndex {
0051     auto found = findSpacePointForIndex(index, spacePoints);
0052     if (!found.has_value()) {
0053       throw std::runtime_error("No space point found for source-link index " +
0054                                std::to_string(index));
0055     }
0056     return found->index();
0057   };
0058 
0059   const auto s = track.size();
0060   if (s < 3) {
0061     throw std::runtime_error(
0062         "Cannot convert track with less then 3 space points to seed");
0063   }
0064 
0065   std::vector<SpacePointIndex> spacePointIndices;
0066   spacePointIndices.reserve(track.size());
0067 
0068   std::transform(track.begin(), track.end(),
0069                  std::back_inserter(spacePointIndices), findSpacePoint);
0070   std::ranges::sort(spacePointIndices, {},
0071                     [&](SpacePointIndex i) { return spacePoints.at(i).r(); });
0072 
0073   // Simply use r = m*z + t and solve for r=0 to find z vertex position...
0074   // Probably not the textbook way to do
0075   const auto& frontSp = spacePoints.at(spacePointIndices.front());
0076   const auto& backSp = spacePoints.at(spacePointIndices.back());
0077   const float m = (backSp.r() - frontSp.r()) / (backSp.z() - frontSp.z());
0078   const float t = frontSp.r() - m * frontSp.z();
0079   const float vertexZ = -t / m;
0080 
0081   auto seed = seeds.createSeed();
0082   seed.assignSpacePointIndices(spacePointIndices);
0083   seed.vertexZ() = vertexZ;
0084 
0085   return seed;
0086 }