ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DD4hepVolumeBuilder.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DD4hepVolumeBuilder.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 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 
16 #include "Acts/Utilities/Units.hpp"
17 #include "DD4hep/Detector.h"
18 
19 #include <boost/algorithm/string.hpp>
20 
23  std::unique_ptr<const Logger> logger)
24  : m_cfg(), m_logger(std::move(logger)) {
25  setConfiguration(config);
26 }
27 
29 
32  m_cfg = config;
33 }
34 
35 std::vector<std::shared_ptr<Acts::TrackingVolume>>
37  if (m_cfg.centralVolumes.empty()) {
38  ACTS_VERBOSE("[L] No layers handed over for central volume!");
39  return {};
40  }
41 
43  "[L] Received layers for central volume -> creating "
44  "cylindrical layers");
45 
46  // Resulting volumes
48  // Inner/outer radius and half length of the barrel
49  double rMin, rMax, dz;
50 
51  // Go through volumes
52  for (auto& detElement : m_cfg.centralVolumes) {
53  // Access the global transformation matrix of the volume
54  auto transform =
55  convertTransform(&(detElement.nominal().worldTransformation()));
56  // Get the shape of the volume
57  TGeoShape* geoShape = detElement.placement().ptr()->GetVolume()->GetShape();
58 
59  if (geoShape != nullptr) {
60  TGeoTubeSeg* tube = dynamic_cast<TGeoTubeSeg*>(geoShape);
61  if (tube == nullptr)
62  ACTS_ERROR(
63  "[L] Cylinder layer has wrong shape - needs to be TGeoTubeSeg!");
64 
65  // Extract the boundaries
66  rMin = tube->GetRmin() * units::_cm;
67  rMax = tube->GetRmax() * units::_cm;
68  dz = tube->GetDz() * units::_cm;
69 
70  } else {
71  throw std::logic_error(
72  std::string("Volume DetElement: ") + detElement.name() +
73  std::string(" has not a shape "
74  "added to its extension. Please check your detector "
75  "constructor!"));
76  }
77  // Build boundaries
78  CylinderVolumeBounds cvBounds(rMin, rMax, dz);
79  // Extract material if available
80  dd4hep::Material ddmaterial = detElement.volume().material();
81  if (!boost::iequals(ddmaterial.name(), "vacuum")) {
82  Material volumeMaterial(ddmaterial.radLength() * Acts::units::_cm,
83  ddmaterial.intLength() * Acts::units::_cm,
84  ddmaterial.A(), ddmaterial.Z(),
85  ddmaterial.density() / pow(Acts::units::_cm, 3));
86 
87  volumes.push_back(TrackingVolume::create(
88  transform, std::make_shared<const CylinderVolumeBounds>(cvBounds),
89  std::make_shared<const HomogeneousVolumeMaterial>(volumeMaterial)));
90  } else {
91  volumes.push_back(TrackingVolume::create(
92  transform, std::make_shared<const CylinderVolumeBounds>(cvBounds)));
93  }
94  }
95  return volumes;
96 }
97 
98 std::shared_ptr<const Acts::Transform3D>
99 Acts::DD4hepVolumeBuilder::convertTransform(const TGeoMatrix* tGeoTrans) const {
100  // Get the placement and orientation in respect to its mother
101  const Double_t* rotation = tGeoTrans->GetRotationMatrix();
102  const Double_t* translation = tGeoTrans->GetTranslation();
103  auto transform =
104  std::make_shared<const Transform3D>(TGeoPrimitivesHelpers::makeTransform(
105  Acts::Vector3D(rotation[0], rotation[3], rotation[6]),
106  Acts::Vector3D(rotation[1], rotation[4], rotation[7]),
107  Acts::Vector3D(rotation[2], rotation[5], rotation[8]),
108  Acts::Vector3D(translation[0] * units::_cm,
109  translation[1] * units::_cm,
110  translation[2] * units::_cm)));
111  return (transform);
112 }