Analysis Software
Documentation for sPHENIX simulation 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"
15 
16 #include <array>
17 #include <ostream>
18 #include <string>
19 
20 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
21  const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
22  const SortingConfig& sorting) const {
23  std::vector<Acts::ProtoLayer> protoLayers;
24 
25  using SurfaceCluster = std::pair<Extent, std::vector<const Surface*>>;
26  std::vector<SurfaceCluster> clusteredSurfaces;
33  auto findCluster = [&](const Extent& extent) -> SurfaceCluster& {
34  for (auto& cluster : clusteredSurfaces) {
35  if (cluster.first.intersects(extent, sorting.first)) {
36  return cluster;
37  }
38  }
39  // No cluster found, let's create a new one
40  clusteredSurfaces.push_back(SurfaceCluster(extent, {}));
41  return clusteredSurfaces.back();
42  };
43 
44  // Loop over surfaces and sort into clusters
45  for (auto& sf : surfaces) {
46  auto sfExtent = sf->polyhedronRepresentation(gctx, 1).extent();
47  sfExtent.envelope()[sorting.first] = {sorting.second, sorting.second};
48  auto& sfCluster = findCluster(sfExtent);
49  sfCluster.first.extend(sfExtent);
50  sfCluster.second.push_back(sf);
51  }
52  // Loop over clusters and create ProtoLayer
53  protoLayers.reserve(clusteredSurfaces.size());
54  for (auto& clusters : clusteredSurfaces) {
55  ACTS_VERBOSE("Creating ProtoLayer with " << clusters.second.size()
56  << " surfaces.");
57  protoLayers.push_back(ProtoLayer(gctx, clusters.second));
58  }
59  return protoLayers;
60 }
61 
62 std::vector<Acts::ProtoLayer> Acts::ProtoLayerHelper::protoLayers(
63  const GeometryContext& gctx, const std::vector<const Surface*>& surfaces,
64  const std::vector<SortingConfig>& sortings) const {
65  ACTS_DEBUG("Received " << surfaces.size() << " surfaces at input.");
66  std::vector<std::vector<const Surface*>> sortSurfaces = {surfaces};
67  for (const auto& sorting : sortings) {
68  ACTS_VERBOSE("-> Sorting a set of " << sortSurfaces.size() << " in "
69  << binningValueNames()[sorting.first]);
70  std::vector<std::vector<const Surface*>> subSurfaces;
71  for (const auto& ssurfaces : sortSurfaces) {
72  ACTS_VERBOSE("-> Surfaces for this sorting step: " << ssurfaces.size());
73  auto pLayers = protoLayers(gctx, ssurfaces, sorting);
74  ACTS_VERBOSE("-> Resulted in " << pLayers.size() << " ProtoLayers.");
75  for (const auto& pLayer : pLayers) {
76  ACTS_VERBOSE("--> ProtoLayer contains " << pLayer.surfaces().size()
77  << " surfaces.");
78  subSurfaces.push_back(pLayer.surfaces());
79  }
80  }
81  sortSurfaces = subSurfaces;
82  }
83  ACTS_DEBUG("Yielded " << sortSurfaces.size() << " at output.");
84 
85  std::vector<Acts::ProtoLayer> finalProtoLayers;
86 
87  for (const auto& ssurfaces : sortSurfaces) {
88  finalProtoLayers.push_back(ProtoLayer(gctx, ssurfaces));
89  }
90 
91  return finalProtoLayers;
92 }