Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DD4hepDetectorSurfaceFactory.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DD4hepDetectorSurfaceFactory.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 
19 
20 #include "DD4hep/DetElement.h"
21 
22 using namespace Acts::detail;
23 
25  std::unique_ptr<const Logger> mlogger)
26  : m_logger(std::move(mlogger)) {
27  ACTS_DEBUG("UnitLength conversion factor (DD4hep -> Acts): " << unitLength);
28 }
29 
31  Cache& cache, const dd4hep::DetElement& dd4hepElement,
32  const Options& options) {
33  ACTS_DEBUG("Configured to convert "
34  << (options.convertSensitive ? "sensitive components and " : "")
35  << (options.convertPassive
36  ? "passive surfaces."
37  : (not options.convertSensitive
38  ? "nothing (this is likely a configuration error)."
39  : "")));
40  ACTS_DEBUG("Constructing DD4hepDetectorElements - tree level call from "
41  << dd4hepElement.name() << ".");
42  recursiveConstruct(cache, dd4hepElement, options, 1);
43  ACTS_DEBUG("Recursive search did yield: "
44  << cache.sensitiveSurfaces.size() << " sensitive surface(s), "
45  << cache.passiveSurfaces.size() << " passive surface(s)");
46 }
47 
49  Cache& cache, const dd4hep::DetElement& dd4hepElement,
50  const Options& options, int level) {
51  ACTS_VERBOSE("Conversion call at level " << level << " for element "
52  << dd4hepElement.name());
53 
54  // Check if any surface binnning can be detected
55  int sBinning = getParamOr<int>("acts_surface_binning_dim", dd4hepElement, 0);
56  if (sBinning > 0) {
57  cache.binnings = convertBinning(dd4hepElement, "acts_surface_binning");
58  }
59 
60  // Deal with passive surface if detected
61  bool pSurface =
62  getParamOr<bool>("acts_passive_surface", dd4hepElement, false);
63  if (pSurface and options.convertPassive) {
64  ACTS_VERBOSE("Passive surface(s) detected.");
65  cache.passiveSurfaces.push_back(
66  constructPassiveComponents(dd4hepElement, options));
67  }
68 
69  const dd4hep::DetElement::Children& children = dd4hepElement.children();
70  if (!children.empty()) {
71  ACTS_VERBOSE(children.size() << " child(ren) detected.");
72  for (auto& child : children) {
73  dd4hep::DetElement childDetElement = child.second;
74  ACTS_VERBOSE("Processing child " << childDetElement.name());
75  if (childDetElement.volume().isSensitive() and options.convertSensitive) {
76  ACTS_VERBOSE("Sensitive surface detected.");
77  cache.sensitiveSurfaces.push_back(
78  constructSensitiveComponents(childDetElement, options));
79  }
80  recursiveConstruct(cache, childDetElement, options, level + 1);
81  }
82  } else {
83  ACTS_VERBOSE("No children detected.");
84  }
85 }
86 
89  const dd4hep::DetElement& dd4hepElement, const Options& options) const {
90  // Extract the axis definition
91  std::string detAxis =
92  getParamOr<std::string>("axis_definitions", dd4hepElement, "XYZ");
93  std::shared_ptr<const Acts::ISurfaceMaterial> surfaceMaterial = nullptr;
94 
95  // Create the corresponding detector element
96  auto dd4hepDetElement = std::make_shared<Acts::DD4hepDetectorElement>(
97  dd4hepElement, detAxis, unitLength, false, nullptr);
98  auto sSurface = dd4hepDetElement->surface().getSharedPtr();
99  attachSurfaceMaterial(dd4hepElement, *sSurface.get(),
100  dd4hepDetElement->thickness(), options);
101  // return the surface
102  return {dd4hepDetElement, sSurface};
103 }
104 
107  const dd4hep::DetElement& dd4hepElement, const Options& options) const {
108  // Underlying TGeo node, shape & transform
109  const auto& tgeoNode = *(dd4hepElement.placement().ptr());
110  auto tgeoShape = tgeoNode.GetVolume()->GetShape();
111  const auto tgeoTransform = dd4hepElement.nominal().worldTransformation();
112  // Extract the axis definition
113  auto detAxis =
114  getParamOr<std::string>("axis_definitions", dd4hepElement, "XYZ");
115  bool assignToAll = getParamOr<bool>("assign_to_all", dd4hepElement, true);
116 
117  auto [pSurface, thickness] =
118  TGeoSurfaceConverter::toSurface(*tgeoShape, tgeoTransform, detAxis);
119  attachSurfaceMaterial(dd4hepElement, *pSurface.get(), thickness, options);
120  // Return a passive surface
121  return {pSurface, assignToAll};
122 }
123 
125  const dd4hep::DetElement& dd4hepElement, Acts::Surface& surface,
126  ActsScalar thickness, const Options& options) const {
127  if (options.convertMaterial) {
128  // Extract the material
129  const auto& tgeoNode = *(dd4hepElement.placement().ptr());
130  auto tgeoMaterial = tgeoNode.GetMedium()->GetMaterial();
131  // Convert the material
132  TGeoMaterialConverter::Options materialOptions;
133  materialOptions.unitLengthScalor = unitLength;
134  auto materialSlab = TGeoMaterialConverter::materialSlab(
135  *tgeoMaterial, thickness, options.surfaceMaterialThickness,
136  materialOptions);
137  auto surfaceMaterial =
138  std::make_shared<HomogeneousSurfaceMaterial>(materialSlab);
139  // Assign the material to the surface
140  surface.assignSurfaceMaterial(std::move(surfaceMaterial));
141  }
142 }