EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProtoLayerHelper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ProtoLayerHelper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include "Acts/Geometry/Extent.hpp"
12 
13 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
14  const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
15  const SortingConfig& sorting) const {
16  std::vector<Acts::ProtoLayer> protoLayers;
17 
18  using SurfaceCluster = std::pair<Extent, std::vector<const Surface*>>;
19  std::vector<SurfaceCluster> clusteredSurfaces;
26  auto findCluster = [&](const Extent& extent) -> SurfaceCluster& {
27  for (auto& cluster : clusteredSurfaces) {
28  if (cluster.first.intersects(extent, sorting.first, sorting.second)) {
29  return cluster;
30  }
31  }
32  // No cluster found, let's create a new one
33  clusteredSurfaces.push_back(SurfaceCluster(extent, {}));
34  return clusteredSurfaces.back();
35  };
36 
37  // Loop over surfaces and sort into clusters
38  for (auto& sf : surfaces) {
39  auto sfExtent = sf->polyhedronRepresentation(gctx, 1).extent();
40  auto& sfCluster = findCluster(sfExtent);
41  sfCluster.first.extend(sfExtent);
42  sfCluster.second.push_back(sf);
43  }
44 
45  // Loop over clusters and create ProtoLayer
46  protoLayers.reserve(clusteredSurfaces.size());
47  for (auto& clusters : clusteredSurfaces) {
48  ACTS_VERBOSE("Creatingg ProtoLayer with " << clusters.second.size()
49  << " surfaces.");
50  protoLayers.push_back(ProtoLayer(gctx, clusters.second));
51  }
52  return protoLayers;
53 }
54 
55 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
56  const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
57  const std::vector<SortingConfig>& sortings) const {
58  ACTS_DEBUG("Received " << surfaces.size() << " surfaces at input.");
59  std::vector<std::vector<const Surface*>> sortSurfaces = {surfaces};
60  for (const auto& sorting : sortings) {
61  ACTS_VERBOSE("-> Sorting a set of " << sortSurfaces.size() << " in "
62  << binningValueNames[sorting.first]);
63  std::vector<std::vector<const Surface*>> subSurfaces;
64  for (const auto& ssurfaces : sortSurfaces) {
65  ACTS_VERBOSE("-> Surfaces for this sorting step: " << ssurfaces.size());
66  auto pLayers = protoLayers(gctx, ssurfaces, sorting);
67  ACTS_VERBOSE("-> Resulted in " << pLayers.size() << " ProtoLayers.");
68  for (const auto& pLayer : pLayers) {
69  ACTS_VERBOSE("--> ProtoLayer containes " << pLayer.surfaces().size()
70  << " surfaces.");
71  subSurfaces.push_back(pLayer.surfaces());
72  }
73  }
74  sortSurfaces = subSurfaces;
75  }
76  ACTS_DEBUG("Yielded " << sortSurfaces.size() << " at output.");
77 
78  std::vector<Acts::ProtoLayer> finalProtoLayers;
79 
80  for (auto ssurfaces : sortSurfaces) {
81  finalProtoLayers.push_back(ProtoLayer(gctx, ssurfaces));
82  }
83 
84  return finalProtoLayers;
85 }