Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 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 "Acts/Geometry/ProtoLayerHelper.hpp"
0010 
0011 #include "Acts/Geometry/Extent.hpp"
0012 #include "Acts/Geometry/Polyhedron.hpp"
0013 #include "Acts/Geometry/ProtoLayer.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 
0016 #include <array>
0017 #include <ostream>
0018 #include <string>
0019 
0020 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
0021     const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
0022     const SortingConfig& sorting) const {
0023   std::vector<Acts::ProtoLayer> protoLayers;
0024 
0025   using SurfaceCluster = std::pair<Extent, std::vector<const Surface*>>;
0026   std::vector<SurfaceCluster> clusteredSurfaces;
0027   /// Helper function to find/create the cluster of surfaces where
0028   /// the Extent belongs to. In case none is found, a new one is inserted
0029   ///
0030   /// @param extent The test extent for finding the cluster
0031   ///
0032   /// @return the reference of the SurfaceCluster for insertion
0033   auto findCluster = [&](const Extent& extent) -> SurfaceCluster& {
0034     for (auto& cluster : clusteredSurfaces) {
0035       if (cluster.first.intersects(extent, sorting.first)) {
0036         return cluster;
0037       }
0038     }
0039     // No cluster found, let's create a new one
0040     clusteredSurfaces.push_back(SurfaceCluster(extent, {}));
0041     return clusteredSurfaces.back();
0042   };
0043 
0044   // Loop over surfaces and sort into clusters
0045   for (auto& sf : surfaces) {
0046     auto sfExtent = sf->polyhedronRepresentation(gctx, 1).extent();
0047     sfExtent.envelope()[sorting.first] = {sorting.second, sorting.second};
0048     auto& sfCluster = findCluster(sfExtent);
0049     sfCluster.first.extend(sfExtent);
0050     sfCluster.second.push_back(sf);
0051   }
0052   // Loop over clusters and create ProtoLayer
0053   protoLayers.reserve(clusteredSurfaces.size());
0054   for (auto& clusters : clusteredSurfaces) {
0055     ACTS_VERBOSE("Creating ProtoLayer with " << clusters.second.size()
0056                                              << " surfaces.");
0057     protoLayers.push_back(ProtoLayer(gctx, clusters.second));
0058   }
0059   return protoLayers;
0060 }
0061 
0062 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
0063     const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
0064     const std::vector<SortingConfig>& sortings) const {
0065   ACTS_DEBUG("Received " << surfaces.size() << " surfaces at input.");
0066   std::vector<std::vector<const Surface*>> sortSurfaces = {surfaces};
0067   for (const auto& sorting : sortings) {
0068     ACTS_VERBOSE("-> Sorting a set of " << sortSurfaces.size() << " in "
0069                                         << binningValueNames()[sorting.first]);
0070     std::vector<std::vector<const Surface*>> subSurfaces;
0071     for (const auto& ssurfaces : sortSurfaces) {
0072       ACTS_VERBOSE("-> Surfaces for this sorting step: " << ssurfaces.size());
0073       auto pLayers = protoLayers(gctx, ssurfaces, sorting);
0074       ACTS_VERBOSE("-> Resulted in " << pLayers.size() << " ProtoLayers.");
0075       for (const auto& pLayer : pLayers) {
0076         ACTS_VERBOSE("--> ProtoLayer contains " << pLayer.surfaces().size()
0077                                                 << " surfaces.");
0078         subSurfaces.push_back(pLayer.surfaces());
0079       }
0080     }
0081     sortSurfaces = subSurfaces;
0082   }
0083   ACTS_DEBUG("Yielded " << sortSurfaces.size() << " at output.");
0084 
0085   std::vector<Acts::ProtoLayer> finalProtoLayers;
0086 
0087   for (const auto& ssurfaces : sortSurfaces) {
0088     finalProtoLayers.push_back(ProtoLayer(gctx, ssurfaces));
0089   }
0090 
0091   return finalProtoLayers;
0092 }