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