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