Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-26 08:20:24

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/EventData/SeedSpacePointSelection.hpp"
0010 
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Utilities/Helpers.hpp"
0013 #include "ActsExamples/EventData/IndexSourceLink.hpp"
0014 
0015 #include <array>
0016 #include <cstddef>
0017 #include <optional>
0018 #include <span>
0019 #include <vector>
0020 
0021 namespace ActsExamples {
0022 
0023 namespace {
0024 
0025 /// The first space point of each layer, in the given order, at most @p limit
0026 /// of them.
0027 std::vector<SpacePointIndex> onePerLayer(
0028     const SpacePointContainer& spacePoints,
0029     std::span<const SpacePointIndex> candidates, std::size_t limit) {
0030   std::vector<SpacePointIndex> perLayer;
0031   std::vector<Acts::GeometryIdentifier> layers;
0032   for (const SpacePointIndex index : candidates) {
0033     if (perLayer.size() == limit) {
0034       break;
0035     }
0036     const ConstSpacePointProxy sp = spacePoints.at(index);
0037     if (sp.sourceLinks().empty()) {
0038       continue;
0039     }
0040     const Acts::GeometryIdentifier layer =
0041         sp.sourceLinks()[0].get<IndexSourceLink>().geometryId().withSensitive(
0042             0);
0043     if (Acts::rangeContainsValue(layers, layer)) {
0044       continue;
0045     }
0046     layers.push_back(layer);
0047     perLayer.push_back(index);
0048   }
0049   return perLayer;
0050 }
0051 
0052 }  // namespace
0053 
0054 std::optional<std::array<SpacePointIndex, 3>> selectSeedSpacePoints(
0055     const SpacePointContainer& spacePoints,
0056     std::span<const SpacePointIndex> candidates,
0057     SeedSpacePointSelection selection) {
0058   if (candidates.size() < 3) {
0059     return std::nullopt;
0060   }
0061 
0062   switch (selection) {
0063     case SeedSpacePointSelection::FirstThree:
0064       return std::array{candidates[0], candidates[1], candidates[2]};
0065     case SeedSpacePointSelection::InnermostTriplet: {
0066       const std::vector<SpacePointIndex> perLayer =
0067           onePerLayer(spacePoints, candidates, 3);
0068       if (perLayer.size() < 3) {
0069         return std::nullopt;
0070       }
0071       return std::array{perLayer[0], perLayer[1], perLayer[2]};
0072     }
0073     case SeedSpacePointSelection::SpreadTriplet: {
0074       const std::vector<SpacePointIndex> perLayer =
0075           onePerLayer(spacePoints, candidates, candidates.size());
0076       if (perLayer.size() < 3) {
0077         return std::nullopt;
0078       }
0079       return std::array{perLayer.front(), perLayer[perLayer.size() / 2],
0080                         perLayer.back()};
0081     }
0082   }
0083 
0084   return std::nullopt;
0085 }
0086 
0087 }  // namespace ActsExamples