42 #include <boost/algorithm/string.hpp>
44 #include "DD4hep/Alignments.h"
45 #include "DD4hep/DetElement.h"
46 #include "DD4hep/Volumes.h"
47 #include "DDRec/DetectorData.h"
48 #include "RtypesCore.h"
49 #include "TGeoManager.h"
50 #include "TGeoMatrix.h"
54 std::unique_ptr<const Logger>
logger)
68 const std::vector<dd4hep::DetElement>& dendcapLayers,
71 if (dendcapLayers.empty()) {
72 ACTS_VERBOSE(
" No layers handed over for " << side <<
" volume!");
75 <<
" volume -> creating "
78 for (
auto& detElement : dendcapLayers) {
79 ACTS_VERBOSE(
"=> Translating layer from: " << detElement.name());
81 std::vector<std::shared_ptr<const Surface>> layerSurfaces;
87 resolveSensitive(detElement, layerSurfaces);
90 convertTransform(&(detElement.nominal().worldTransformation()));
93 detElement.placement().ptr()->GetVolume()->GetShape();
101 std::vector<double> rvalues;
103 std::back_inserter(rvalues), [&](
const auto&
surface) {
106 std::sort(rvalues.begin(), rvalues.end());
107 std::vector<std::string> locs;
109 std::unique(rvalues.begin(), rvalues.end()),
110 std::back_inserter(locs),
116 if (params.contains(
"envelope_r_min") &&
117 params.contains(
"envelope_r_max") &&
118 params.contains(
"envelope_z_min") &&
119 params.contains(
"envelope_z_max")) {
123 params.get<
double>(
"envelope_r_max")};
125 params.get<
double>(
"envelope_z_max")};
126 }
else if (geoShape !=
nullptr) {
127 TGeoTubeSeg* tube =
dynamic_cast<TGeoTubeSeg*
>(geoShape);
128 if (tube ==
nullptr) {
129 ACTS_ERROR(
" Disc layer has wrong shape - needs to be TGeoTubeSeg!");
146 if (layerSurfaces.empty()) {
150 double z = (zMin + zMax) * 0.5;
153 double eiz = (z != 0.) ? z -
m_cfg.defaultThickness : 0.;
154 double eoz = (z != 0.) ? z +
m_cfg.defaultThickness : 0.;
161 <<
" sensitive surfaces.");
171 throw std::logic_error(
172 std::string(
"Layer DetElement: ") + detElement.name() +
173 std::string(
" has neither a shape nor tolerances for envelopes "
174 "added to its extension. Please check your detector "
178 std::shared_ptr<Layer> endcapLayer =
nullptr;
181 bool hasSurfaceBinning =
182 getParamOr<bool>(
"surface_binning", detElement,
true);
185 if (hasSurfaceBinning) {
186 if (params.contains(
"surface_binning_n_phi")) {
187 nPhi =
static_cast<size_t>(params.get<
int>(
"surface_binning_n_phi"));
189 if (params.contains(
"surface_binning_n_r")) {
190 nR =
static_cast<size_t>(params.get<
int>(
"surface_binning_n_r"));
192 hasSurfaceBinning = nR * nPhi > 1;
196 if (detElement.volume().isSensitive()) {
198 auto sensitiveSurf = createSensitiveSurface(detElement,
true);
200 std::unique_ptr<Acts::SurfaceArray> sArray =
201 std::make_unique<SurfaceArray>(sensitiveSurf);
204 auto dBounds = std::make_shared<const RadialBounds>(pl.
min(
Acts::binR),
211 }
else if (hasSurfaceBinning) {
213 endcapLayer =
m_cfg.layerCreator->discLayer(
214 gctx, layerSurfaces, nR, nPhi, pl,
transform,
nullptr);
217 endcapLayer =
m_cfg.layerCreator->discLayer(
224 layers.push_back(endcapLayer);
232 return endcapLayers(gctx,
m_cfg.negativeLayers,
"negative");
238 if (
m_cfg.centralLayers.empty()) {
239 ACTS_VERBOSE(
" No layers handed over for central volume!");
242 " Received layers for central volume -> creating "
243 "cylindrical layers");
245 for (
auto& detElement :
m_cfg.centralLayers) {
246 ACTS_VERBOSE(
"=> Translating layer from: " << detElement.name());
248 std::vector<std::shared_ptr<const Surface>> layerSurfaces;
254 resolveSensitive(detElement, layerSurfaces);
257 convertTransform(&(detElement.nominal().worldTransformation()));
259 TGeoShape* geoShape =
260 detElement.placement().ptr()->GetVolume()->GetShape();
264 std::stringstream ss;
267 std::vector<double> zvalues;
269 std::back_inserter(zvalues), [&](
const auto&
surface) {
272 std::sort(zvalues.begin(), zvalues.end());
273 std::vector<std::string> locs;
275 std::unique(zvalues.begin(), zvalues.end()),
276 std::back_inserter(locs),
282 if (params.contains(
"envelope_r_min") &&
283 params.contains(
"envelope_r_max") &&
284 params.contains(
"envelope_z_min") &&
285 params.contains(
"envelope_z_max")) {
288 params.get<
double>(
"envelope_r_max")};
290 params.get<
double>(
"envelope_z_max")};
291 }
else if (geoShape !=
nullptr) {
292 TGeoTubeSeg* tube =
dynamic_cast<TGeoTubeSeg*
>(geoShape);
293 if (tube ==
nullptr) {
295 " Cylinder layer has wrong shape - needs to be TGeoTubeSeg!");
303 if (layerSurfaces.empty()) {
306 double r = (rMin + rMax) * 0.5;
309 double eir = (r != 0.) ? r -
m_cfg.defaultThickness : 0.;
310 double eor = (r != 0.) ? r +
m_cfg.defaultThickness : 0.;
324 throw std::logic_error(
325 std::string(
"Layer DetElement: ") + detElement.name() +
326 std::string(
" has neither a shape nor tolerances for envelopes "
327 "added to it¥s extension. Please check your detector "
333 std::shared_ptr<Layer> centralLayer =
nullptr;
335 if (detElement.volume().isSensitive()) {
337 auto sensitiveSurf = createSensitiveSurface(detElement);
339 std::unique_ptr<Acts::SurfaceArray> sArray =
340 std::make_unique<SurfaceArray>(sensitiveSurf);
345 std::shared_ptr<const CylinderBounds> cBounds(
353 centralLayer =
m_cfg.layerCreator->cylinderLayer(
360 layers.push_back(centralLayer);
368 return endcapLayers(gctx,
m_cfg.positiveLayers,
"positive");
372 const dd4hep::DetElement& detElement,
373 std::vector<std::shared_ptr<const Acts::Surface>>& surfaces)
const {
374 const dd4hep::DetElement::Children& children = detElement.children();
375 if (!children.empty()) {
376 for (
auto&
child : children) {
377 dd4hep::DetElement childDetElement =
child.second;
378 if (childDetElement.volume().isSensitive()) {
380 surfaces.push_back(createSensitiveSurface(childDetElement,
false));
382 resolveSensitive(childDetElement, surfaces);
387 std::shared_ptr<const Acts::Surface>
389 const dd4hep::DetElement& detElement,
bool isDisc)
const {
391 getParamOr<std::string>(
"axis_definitions", detElement,
"XYZ");
398 return dd4hepDetElement->surface().getSharedPtr();
402 const TGeoMatrix* tGeoTrans)
const {
404 const Double_t* rotation = tGeoTrans->GetRotationMatrix();
405 const Double_t*
translation = tGeoTrans->GetTranslation();
411 translation[1] * UnitConstants::cm,
412 translation[2] * UnitConstants::cm));