Analysis Software
Documentation for sPHENIX simulation 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 
10 
15 
16 #include <stdexcept>
17 #include <utility>
18 
19 #include <DD4hep/Alignments.h>
20 #include <DD4hep/DetElement.h>
21 #include <DD4hep/Volumes.h>
22 #include <RtypesCore.h>
23 
26  std::unique_ptr<const Logger> logger)
27  : m_cfg(), m_logger(std::move(logger)) {
28  setConfiguration(config);
29 }
30 
32 
35  m_cfg = config;
36 }
37 
38 std::vector<std::shared_ptr<Acts::TrackingVolume>>
40  if (m_cfg.centralVolumes.empty()) {
41  ACTS_VERBOSE("[L] No layers handed over for central volume!");
42  return {};
43  }
44 
46  "[L] Received layers for central volume -> creating "
47  "cylindrical layers");
48 
49  // Resulting volumes
51  // Inner/outer radius and half length of the barrel
52  double rMin = 0, rMax = 0, dz = 0;
53 
54  // Go through volumes
55  for (auto& detElement : m_cfg.centralVolumes) {
56  // Access the global transformation matrix of the volume
57  auto transform =
58  convertTransform(&(detElement.nominal().worldTransformation()));
59  // Get the shape of the volume
60  TGeoShape* geoShape = detElement.placement().ptr()->GetVolume()->GetShape();
61 
62  if (geoShape != nullptr) {
63  TGeoTubeSeg* tube = dynamic_cast<TGeoTubeSeg*>(geoShape);
64  if (tube == nullptr) {
65  ACTS_ERROR(
66  "[L] Cylinder layer has wrong shape - needs to be TGeoTubeSeg!");
67  }
68 
69  // Extract the boundaries
70  rMin = tube->GetRmin() * UnitConstants::cm;
71  rMax = tube->GetRmax() * UnitConstants::cm;
72  dz = tube->GetDz() * UnitConstants::cm;
73 
74  } else {
75  throw std::logic_error(
76  std::string("Volume DetElement: ") + detElement.name() +
77  std::string(" has not a shape "
78  "added to its extension. Please check your detector "
79  "constructor!"));
80  }
81  // Build boundaries
82  CylinderVolumeBounds cvBounds(rMin, rMax, dz);
83  volumes.push_back(TrackingVolume::create(
84  transform, std::make_shared<const CylinderVolumeBounds>(cvBounds)));
85  }
86  return volumes;
87 }
88 
90  const TGeoMatrix* tGeoTrans) const {
91  // Get the placement and orientation in respect to its mother
92  const Double_t* rotation = tGeoTrans->GetRotationMatrix();
93  const Double_t* translation = tGeoTrans->GetTranslation();
95  Acts::Vector3(rotation[0], rotation[3], rotation[6]),
96  Acts::Vector3(rotation[1], rotation[4], rotation[7]),
97  Acts::Vector3(rotation[2], rotation[5], rotation[8]),
98  Acts::Vector3(translation[0] * UnitConstants::cm,
99  translation[1] * UnitConstants::cm,
100  translation[2] * UnitConstants::cm));
101 }