Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:03:28

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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/Root/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 namespace Acts {
0025 
0026 DD4hepVolumeBuilder::DD4hepVolumeBuilder(
0027     const DD4hepVolumeBuilder::Config& config,
0028     std::unique_ptr<const Logger> logger)
0029     : m_cfg(), m_logger(std::move(logger)) {
0030   setConfiguration(config);
0031 }
0032 
0033 DD4hepVolumeBuilder::~DD4hepVolumeBuilder() = default;
0034 
0035 void DD4hepVolumeBuilder::setConfiguration(
0036     const DD4hepVolumeBuilder::Config& config) {
0037   m_cfg = config;
0038 }
0039 
0040 std::vector<std::shared_ptr<TrackingVolume>>
0041 DD4hepVolumeBuilder::centralVolumes() const {
0042   if (m_cfg.centralVolumes.empty()) {
0043     ACTS_VERBOSE("[L] No layers handed over for central volume!");
0044     return {};
0045   }
0046 
0047   ACTS_VERBOSE(
0048       "[L] Received layers for central volume -> creating "
0049       "cylindrical layers");
0050 
0051   // Resulting volumes
0052   MutableTrackingVolumeVector volumes;
0053   // Inner/outer radius and half length of the barrel
0054   double rMin = 0, rMax = 0, dz = 0;
0055 
0056   // Go through volumes
0057   for (auto& detElement : m_cfg.centralVolumes) {
0058     // Access the global transformation matrix of the volume
0059     auto transform =
0060         convertTransform(&(detElement.nominal().worldTransformation()));
0061     // Get the shape of the volume
0062     TGeoShape* geoShape = detElement.placement().ptr()->GetVolume()->GetShape();
0063 
0064     if (geoShape != nullptr) {
0065       TGeoTubeSeg* tube = dynamic_cast<TGeoTubeSeg*>(geoShape);
0066       if (tube == nullptr) {
0067         ACTS_ERROR(
0068             "[L] Cylinder layer has wrong shape - needs to be TGeoTubeSeg!");
0069         throw std::logic_error{
0070             "[L] Cylinder layer has wrong shape - needs to be TGeoTubeSeg!"};
0071       }
0072 
0073       // Extract the boundaries
0074       rMin = tube->GetRmin() * UnitConstants::cm;
0075       rMax = tube->GetRmax() * UnitConstants::cm;
0076       dz = tube->GetDz() * UnitConstants::cm;
0077 
0078     } else {
0079       throw std::logic_error(
0080           std::string("Volume DetElement: ") + detElement.name() +
0081           std::string(" has not a shape "
0082                       "added to its extension. Please check your detector "
0083                       "constructor!"));
0084     }
0085     // Build boundaries
0086     volumes.push_back(std::make_shared<TrackingVolume>(
0087         transform, std::make_shared<CylinderVolumeBounds>(rMin, rMax, dz)));
0088   }
0089   return volumes;
0090 }
0091 
0092 Transform3 DD4hepVolumeBuilder::convertTransform(
0093     const TGeoMatrix* tGeoTrans) const {
0094   // Get the placement and orientation in respect to its mother
0095   const Double_t* rotation = tGeoTrans->GetRotationMatrix();
0096   const Double_t* translation = tGeoTrans->GetTranslation();
0097   return TGeoPrimitivesHelper::makeTransform(
0098       Vector3(rotation[0], rotation[3], rotation[6]),
0099       Vector3(rotation[1], rotation[4], rotation[7]),
0100       Vector3(rotation[2], rotation[5], rotation[8]),
0101       Vector3(translation[0] * UnitConstants::cm,
0102               translation[1] * UnitConstants::cm,
0103               translation[2] * UnitConstants::cm));
0104 }
0105 
0106 }  // namespace Acts