File indexing completed on 2025-01-18 09:12:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/DD4hep/DD4hepVolumeBuilder.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0013 #include "Acts/Plugins/TGeo/TGeoPrimitivesHelper.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015
0016 #include <stdexcept>
0017 #include <utility>
0018
0019 #include <DD4hep/Alignments.h>
0020 #include <DD4hep/DetElement.h>
0021 #include <DD4hep/Volumes.h>
0022 #include <RtypesCore.h>
0023
0024 Acts::DD4hepVolumeBuilder::DD4hepVolumeBuilder(
0025 const Acts::DD4hepVolumeBuilder::Config& config,
0026 std::unique_ptr<const Logger> logger)
0027 : m_cfg(), m_logger(std::move(logger)) {
0028 setConfiguration(config);
0029 }
0030
0031 Acts::DD4hepVolumeBuilder::~DD4hepVolumeBuilder() = default;
0032
0033 void Acts::DD4hepVolumeBuilder::setConfiguration(
0034 const Acts::DD4hepVolumeBuilder::Config& config) {
0035 m_cfg = config;
0036 }
0037
0038 std::vector<std::shared_ptr<Acts::TrackingVolume>>
0039 Acts::DD4hepVolumeBuilder::centralVolumes() const {
0040 if (m_cfg.centralVolumes.empty()) {
0041 ACTS_VERBOSE("[L] No layers handed over for central volume!");
0042 return {};
0043 }
0044
0045 ACTS_VERBOSE(
0046 "[L] Received layers for central volume -> creating "
0047 "cylindrical layers");
0048
0049
0050 MutableTrackingVolumeVector volumes;
0051
0052 double rMin = 0, rMax = 0, dz = 0;
0053
0054
0055 for (auto& detElement : m_cfg.centralVolumes) {
0056
0057 auto transform =
0058 convertTransform(&(detElement.nominal().worldTransformation()));
0059
0060 TGeoShape* geoShape = detElement.placement().ptr()->GetVolume()->GetShape();
0061
0062 if (geoShape != nullptr) {
0063 TGeoTubeSeg* tube = dynamic_cast<TGeoTubeSeg*>(geoShape);
0064 if (tube == nullptr) {
0065 ACTS_ERROR(
0066 "[L] Cylinder layer has wrong shape - needs to be TGeoTubeSeg!");
0067 throw std::logic_error{
0068 "[L] Cylinder layer has wrong shape - needs to be TGeoTubeSeg!"};
0069 }
0070
0071
0072 rMin = tube->GetRmin() * UnitConstants::cm;
0073 rMax = tube->GetRmax() * UnitConstants::cm;
0074 dz = tube->GetDz() * UnitConstants::cm;
0075
0076 } else {
0077 throw std::logic_error(
0078 std::string("Volume DetElement: ") + detElement.name() +
0079 std::string(" has not a shape "
0080 "added to its extension. Please check your detector "
0081 "constructor!"));
0082 }
0083
0084 volumes.push_back(std::make_shared<TrackingVolume>(
0085 transform, std::make_shared<CylinderVolumeBounds>(rMin, rMax, dz)));
0086 }
0087 return volumes;
0088 }
0089
0090 Acts::Transform3 Acts::DD4hepVolumeBuilder::convertTransform(
0091 const TGeoMatrix* tGeoTrans) const {
0092
0093 const Double_t* rotation = tGeoTrans->GetRotationMatrix();
0094 const Double_t* translation = tGeoTrans->GetTranslation();
0095 return TGeoPrimitivesHelper::makeTransform(
0096 Acts::Vector3(rotation[0], rotation[3], rotation[6]),
0097 Acts::Vector3(rotation[1], rotation[4], rotation[7]),
0098 Acts::Vector3(rotation[2], rotation[5], rotation[8]),
0099 Acts::Vector3(translation[0] * UnitConstants::cm,
0100 translation[1] * UnitConstants::cm,
0101 translation[2] * UnitConstants::cm));
0102 }