Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DD4hepLayerStructure.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DD4hepLayerStructure.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 
12  std::shared_ptr<DD4hepDetectorSurfaceFactory> surfaceFactory,
13  std::unique_ptr<const Logger> logger)
14  : m_surfaceFactory(std::move(surfaceFactory)), m_logger(std::move(logger)) {
15  if (m_surfaceFactory == nullptr) {
16  throw std::invalid_argument(
17  "DD4hepLayerStructure: no surface factory provided");
18  }
19 }
20 
21 std::shared_ptr<Acts::Experimental::LayerStructureBuilder>
23  DD4hepDetectorElement::Store& dd4hepStore,
24  const dd4hep::DetElement& dd4hepElement, const Options& options) const {
25  // Check for misconfiguration with double naming
26  if (dd4hepStore.find(options.name) != dd4hepStore.end()) {
27  std::string reMessage = "DD4hepLayerStructure: structure with name '";
28  reMessage += options.name;
29  reMessage += "' already registered in DetectorElementStore";
30  throw std::runtime_error(reMessage.c_str());
31  }
32 
33  // This object is going to be filled with the created surfaces
35  m_surfaceFactory->construct(fCache, dd4hepElement, options.conversionOptions);
36 
37  ACTS_DEBUG("Conversion from DD4Hep : " << fCache.sensitiveSurfaces.size()
38  << " sensitive surfaces");
39 
40  ACTS_DEBUG("Conversion from DD4Hep : " << fCache.passiveSurfaces.size()
41  << " passive surfaces");
42 
43  // Check if binning was provided or detected
44  if (fCache.binnings.empty() and
45  (fCache.sensitiveSurfaces.size() + fCache.passiveSurfaces.size()) > 0u) {
47  "Surface binning neither provided nor found, navigation will be "
48  "'tryAll' (could result in slow navigation).");
49  }
50 
51  // Surfaces are prepared for creating the builder
53  lsbConfig.auxiliary = "*** DD4hep driven builder for: ";
54  lsbConfig.auxiliary += options.name;
55  // Translate binings and supports
56  lsbConfig.binnings = fCache.binnings;
57  lsbConfig.supports = fCache.supports;
58 
59  std::vector<std::shared_ptr<Surface>> lSurfaces;
60  lSurfaces.reserve(fCache.sensitiveSurfaces.size() +
61  fCache.passiveSurfaces.size());
62 
63  std::vector<std::shared_ptr<DD4hepDetectorElement>> cElements;
64  cElements.reserve(fCache.sensitiveSurfaces.size());
65 
66  // Fill them in to the surface provider struct and detector store
67  for (auto [de, ds] : fCache.sensitiveSurfaces) {
68  lSurfaces.push_back(ds);
69  cElements.push_back(de);
70  }
71  dd4hepStore[options.name] = cElements;
72 
73  // Passive surfaces to be added
74  for (auto [ps, toAll] : fCache.passiveSurfaces) {
75  // Passive surface is not declared to be added to all navigation bins
76  if (not toAll) {
77  lSurfaces.push_back(ps);
78  } else {
79  // Passive surface is indeed declared to be added to all navigaiton bins
81  pSupport.surface = ps;
82  pSupport.assignToAll = true;
83  lsbConfig.supports.push_back(pSupport);
84  }
85  }
86 
87  lsbConfig.surfacesProvider =
88  std::make_shared<Experimental::LayerStructureBuilder::SurfacesHolder>(
89  lSurfaces);
90 
91  ACTS_DEBUG("Configured with " << lsbConfig.binnings.size() << " binnings.");
92  ACTS_DEBUG("Configured to build " << lsbConfig.supports.size()
93  << " supports.");
94 
95  // Return the structure builder
96  return std::make_shared<LayerStructureBuilder>(
97  lsbConfig, getDefaultLogger(options.name, options.logLevel));
98 }