Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11: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 "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     // To prevent problematic isInsidePolygon check for straw surfaces with only
0047     // one lseg
0048     int lseg = (sf->type() != Surface::Straw) ? 1 : 2;
0049     auto sfExtent = sf->polyhedronRepresentation(gctx, lseg).extent();
0050     sfExtent.envelope()[sorting.first] = {sorting.second, sorting.second};
0051     auto& sfCluster = findCluster(sfExtent);
0052     sfCluster.first.extend(sfExtent);
0053     sfCluster.second.push_back(sf);
0054   }
0055   // Loop over clusters and create ProtoLayer
0056   protoLayers.reserve(clusteredSurfaces.size());
0057   for (auto& clusters : clusteredSurfaces) {
0058     ACTS_VERBOSE("Creating ProtoLayer with " << clusters.second.size()
0059                                              << " surfaces.");
0060     protoLayers.push_back(ProtoLayer(gctx, clusters.second));
0061   }
0062   return protoLayers;
0063 }
0064 
0065 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
0066     const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
0067     const std::vector<SortingConfig>& sortings) const {
0068   ACTS_DEBUG("Received " << surfaces.size() << " surfaces at input.");
0069   std::vector<std::vector<const Surface*>> sortSurfaces = {surfaces};
0070   for (const auto& sorting : sortings) {
0071     ACTS_VERBOSE("-> Sorting a set of " << sortSurfaces.size() << " in "
0072                                         << axisDirectionName(sorting.first));
0073     std::vector<std::vector<const Surface*>> subSurfaces;
0074     for (const auto& ssurfaces : sortSurfaces) {
0075       ACTS_VERBOSE("-> Surfaces for this sorting step: " << ssurfaces.size());
0076       auto pLayers = protoLayers(gctx, ssurfaces, sorting);
0077       ACTS_VERBOSE("-> Resulted in " << pLayers.size() << " ProtoLayers.");
0078       for (const auto& pLayer : pLayers) {
0079         ACTS_VERBOSE("--> ProtoLayer contains " << pLayer.surfaces().size()
0080                                                 << " surfaces.");
0081         subSurfaces.push_back(pLayer.surfaces());
0082       }
0083     }
0084     sortSurfaces = subSurfaces;
0085   }
0086   ACTS_DEBUG("Yielded " << sortSurfaces.size() << " at output.");
0087 
0088   std::vector<Acts::ProtoLayer> finalProtoLayers;
0089 
0090   for (const auto& ssurfaces : sortSurfaces) {
0091     finalProtoLayers.push_back(ProtoLayer(gctx, ssurfaces));
0092   }
0093 
0094   return finalProtoLayers;
0095 }