EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetUtils.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetUtils.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 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 
9 #include "DetUtils.h"
10 
14 #include "Acts/Utilities/Units.hpp"
15 
16 #include "DD4hep/CartesianGridXZ.h"
17 
18 namespace det {
19 namespace utils {
20 
21 std::shared_ptr<const Acts::DigitizationModule> rectangleDigiModuleXZ(
22  double halflengthX, double halflengthZ, double thickness,
23  const dd4hep::Segmentation& segmentation) {
24  // convert to ACTS units
25  double scalor = Acts::UnitConstants::cm;
26  halflengthX *= scalor;
27  halflengthZ *= scalor;
28  thickness *= scalor;
29  auto bounds =
30  std::make_shared<const Acts::RectangleBounds>(halflengthX, halflengthZ);
31  dd4hep::CartesianGridXZ cartesianGrid = segmentation;
32  if (cartesianGrid.isValid()) {
33  // the Acts segmentation of the DigitizationModule
34  double gridSizeX = cartesianGrid.gridSizeX() * scalor;
35  double gridSizeZ = cartesianGrid.gridSizeZ() * scalor;
36  size_t bins0 =
37  (cartesianGrid.gridSizeX() != 0) ? (2 * halflengthX) / gridSizeX : 0;
38  size_t bins1 =
39  (cartesianGrid.gridSizeZ() != 0) ? (2 * halflengthZ) / gridSizeZ : 0;
40 
41  std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
42  std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0,
43  bins1);
44  // finally create the digitization module
45  // @todo set lorentz angle
46  return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
47  thickness, 1, 0));
48  }
49  return nullptr;
50 }
51 
52 std::shared_ptr<const Acts::DigitizationModule> rectangleDigiModuleXZ(
53  double halflengthX, double halflengthZ, double thickness, double gridSizeX,
54  double gridSizeZ) {
55  // convert to ACTS units
56  double scalor = Acts::UnitConstants::cm;
57  halflengthX *= scalor;
58  halflengthZ *= scalor;
59  thickness *= scalor;
60  auto bounds =
61  std::make_shared<const Acts::RectangleBounds>(halflengthX, halflengthZ);
62  // the Acts segmentation of the DigitizationModule
63  size_t bins0 =
64  (gridSizeX != 0) ? (2 * halflengthX) / (gridSizeX * scalor) : 0;
65  size_t bins1 =
66  (gridSizeZ != 0) ? (2 * halflengthZ) / (gridSizeZ * scalor) : 0;
67 
68  std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
69  std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0, bins1);
70 
71  // finally create the digitization module
72  // @todo set lorentz angle
73  return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
74  thickness, 1, 0));
75 }
76 
77 std::shared_ptr<const Acts::DigitizationModule> trapezoidalDigiModuleXZ(
78  double minHalflengthX, double maxHalflengthX, double halflengthZ,
79  double thickness, const dd4hep::Segmentation& segmentation) {
80  // convert to ACTS units
81  double scalor = Acts::UnitConstants::cm;
82  minHalflengthX *= scalor;
83  maxHalflengthX *= scalor;
84  halflengthZ *= scalor;
85  thickness *= scalor;
86 
87  auto bounds = std::make_shared<const Acts::TrapezoidBounds>(
88  minHalflengthX, maxHalflengthX, halflengthZ);
89 
90  dd4hep::CartesianGridXZ cartesianGrid = segmentation;
91  if (cartesianGrid.isValid()) {
92  // the Acts segmentation of the DigitizationModule
93  double gridSizeX = cartesianGrid.gridSizeX() * scalor;
94  double gridSizeZ = cartesianGrid.gridSizeZ() * scalor;
95  size_t bins0 =
96  (cartesianGrid.gridSizeX() != 0) ? (2 * maxHalflengthX) / gridSizeX : 0;
97  size_t bins1 =
98  (cartesianGrid.gridSizeZ() != 0) ? (2 * halflengthZ) / gridSizeZ : 0;
99 
100  std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
101  std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0,
102  bins1);
103  // finally create the digitization module
104  // @todo set lorentz angle
105  return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
106  thickness, 1, 0));
107  }
108  return nullptr;
109 }
110 
111 std::shared_ptr<const Acts::DigitizationModule> trapezoidalDigiModuleXZ(
112  double minHalflengthX, double maxHalflengthX, double halflengthZ,
113  double thickness, double gridSizeX, double gridSizeZ) {
114  // convert to ACTS units
115  double scalor = Acts::UnitConstants::cm;
116  minHalflengthX *= scalor;
117  maxHalflengthX *= scalor;
118  halflengthZ *= scalor;
119  thickness *= scalor;
120 
121  auto bounds = std::make_shared<const Acts::TrapezoidBounds>(
122  minHalflengthX, maxHalflengthX, halflengthZ);
123 
124  // the Acts segmentation of the DigitizationModule
125  size_t bins0 =
126  (gridSizeX != 0) ? (2 * maxHalflengthX) / (gridSizeX * scalor) : 0;
127  size_t bins1 =
128  (gridSizeZ != 0) ? (2 * halflengthZ) / (gridSizeZ * scalor) : 0;
129 
130  std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
131  std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0, bins1);
132  // finally create the digitization module
133  // @todo set lorentz angle
134  return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
135  thickness, 1, 0));
136 }
137 
138 dd4hep::xml::Component getNodeByStrAttr(const dd4hep::xml::Handle_t& mother,
139  const std::string& nodeName,
140  const std::string& attrName,
141  const std::string& attrValue) {
142  for (dd4hep::xml::Collection_t xCompColl(mother, nodeName.c_str());
143  nullptr != xCompColl; ++xCompColl) {
144  if (xCompColl.attr<std::string>(attrName.c_str()) == attrValue) {
145  return static_cast<dd4hep::xml::Component>(xCompColl);
146  }
147  }
148  // in case there was no xml daughter with matching name
149  return dd4hep::xml::Component(nullptr);
150 }
151 
152 double getAttrValueWithFallback(const dd4hep::xml::Component& node,
153  const std::string& attrName,
154  const double& defaultValue) {
155  if (node.hasAttr(_Unicode(attrName.c_str()))) {
156  return node.attr<double>(attrName.c_str());
157  } else {
158  return defaultValue;
159  }
160 }
161 } // namespace utils
162 } // namespace det