9 #include <boost/algorithm/string.hpp>
28 #include "TGeoBoolNode.h"
29 #include "TGeoCompositeShape.h"
33 using Line2D = Eigen::Hyperplane<double, 2>;
36 const Identifier& identifier, TGeoNode* tGeoDetElement,
37 const TGeoMatrix* mGlobal,
const std::string& axes,
double scalor,
38 bool isDisc, std::shared_ptr<const Acts::ISurfaceMaterial>
material,
39 std::shared_ptr<const Acts::DigitizationModule> digitizationModule)
41 m_detElement(tGeoDetElement),
42 m_identifier(identifier),
43 m_digitizationModule(std::move(digitizationModule)) {
44 using namespace TGeoPrimitivesHelpers;
47 std::shared_ptr<Surface>
surface =
nullptr;
49 const TGeoMatrix* nodeTransform = (
m_detElement->GetMatrix());
51 const Double_t* translation =
nullptr;
53 if (mGlobal !=
nullptr) {
55 TGeoHMatrix nTransform =
56 TGeoCombiTrans(*mGlobal) * TGeoCombiTrans(*nodeTransform);
57 std::string nName = tGeoDetElement->GetName();
58 std::string suffix =
"_transform";
59 nTransform.SetName((nName + suffix).c_str());
60 translation = nTransform.GetTranslation();
61 rotation = nTransform.GetRotationMatrix();
63 translation = (nodeTransform->GetTranslation());
64 rotation = (nodeTransform->GetRotationMatrix());
67 construct(rotation, translation, axes, scalor, isDisc, std::move(material));
72 TGeoNode* tGeoDetElement,
const std::string& axes,
double scalor,
73 bool isDisc, std::shared_ptr<const Acts::ISurfaceMaterial>
material,
80 const Double_t* rotation = transform.GetRotationMatrix();
81 const Double_t* translation = transform.GetTranslation();
83 construct(rotation, translation, axes, scalor, isDisc, std::move(material));
88 const std::string& axes,
double scalor,
bool isDisc,
89 std::shared_ptr<const Acts::ISurfaceMaterial>
material) {
90 using namespace TGeoPrimitivesHelpers;
93 std::shared_ptr<Surface>
surface =
nullptr;
96 Vector3D colT(scalor * translation[0], scalor * translation[1],
97 scalor * translation[2]);
98 Vector3D colX(rotation[0], rotation[3], rotation[6]);
99 Vector3D colY(rotation[1], rotation[4], rotation[7]);
100 Vector3D colZ(rotation[2], rotation[5], rotation[8]);
102 auto sensor = m_detElement->GetVolume();
105 auto tgShape = sensor->GetShape();
106 auto compShape =
dynamic_cast<TGeoCompositeShape*
>(tgShape);
107 if (compShape !=
nullptr) {
108 auto interNode =
dynamic_cast<TGeoIntersection*
>(compShape->GetBoolNode());
109 if (interNode !=
nullptr) {
110 auto baseTube =
dynamic_cast<TGeoTubeSeg*
>(interNode->GetLeftShape());
111 if (baseTube !=
nullptr) {
112 m_transform = std::make_shared<const Transform3D>(
114 double rMin = baseTube->GetRmin() * scalor;
115 double rMax = baseTube->GetRmax() * scalor;
116 auto maskShape =
dynamic_cast<TGeoArb8*
>(interNode->GetRightShape());
117 if (maskShape !=
nullptr) {
118 auto maskTransform = interNode->GetRightMatrix();
120 const Double_t* polyVrt = maskShape->GetVertices();
124 polyTrl = (maskTransform->GetTranslation());
125 std::vector<Vector2D> vertices;
126 for (
unsigned int v = 0;
v < 8;
v += 2) {
128 (polyTrl[1] + polyVrt[
v + 1]) * scalor);
129 vertices.push_back(vtx);
132 std::vector<std::pair<Vector2D, Vector2D>> boundLines;
133 for (
size_t i = 0; i < vertices.size(); ++i) {
135 Vector2D b = vertices.at((i + 1) % vertices.size());
140 if (a.norm() < b.norm()) {
141 boundLines.push_back(std::make_pair(a, b));
143 boundLines.push_back(std::make_pair(b, a));
148 if (boundLines.size() != 2) {
149 throw std::logic_error(
150 "Input DiscPoly bounds type does not have sensible edges.");
154 Line2D::Through(boundLines[0].first, boundLines[0].
second);
156 Line2D::Through(boundLines[1].first, boundLines[1].second);
159 const Eigen::Translation3d originTranslation(ix.x(), ix.y(), 0.);
163 m_transform = std::make_shared<const Transform3D>((*m_transform) *
170 double phiMax =
std::max(phi1, phi2);
172 double phiShift = 0.;
175 auto annulusBounds = std::make_shared<const AnnulusBounds>(
176 rMin, rMax,
phiMin, phiMax, originShift, phiShift);
178 m_thickness = maskShape->GetDZ() * scalor;
179 m_bounds = annulusBounds;
180 surface = Surface::makeShared<DiscSurface>(annulusBounds, *
this);
188 TGeoBBox*
box =
dynamic_cast<TGeoBBox*
>(tgShape);
190 TGeoTrd2* trapezoid =
dynamic_cast<TGeoTrd2*
>(tgShape);
192 TGeoTubeSeg* tube =
dynamic_cast<TGeoTubeSeg*
>(tgShape);
193 if (tube !=
nullptr) {
194 m_transform = std::make_shared<const Transform3D>(
196 double rMin = tube->GetRmin() * scalor;
197 double rMax = tube->GetRmax() * scalor;
198 double halfZ = tube->GetDz() * scalor;
203 auto radialBounds = std::make_shared<const RadialBounds>(rMin, rMax);
204 m_bounds = radialBounds;
205 surface = Surface::makeShared<DiscSurface>(radialBounds, *
this);
208 m_thickness = std::fabs(rMax - rMin);
209 double radius = (rMin + rMax) * 0.5;
210 auto cylinderBounds =
211 std::make_shared<const CylinderBounds>(
radius, halfZ);
212 m_bounds = cylinderBounds;
213 surface = Surface::makeShared<CylinderSurface>(cylinderBounds, *
this);
216 if (boost::iequals(axes,
"XYZ")) {
221 if (islower(axes.at(0)) != 0) {
224 if (islower(axes.at(1)) != 0) {
227 if (islower(axes.at(2)) != 0) {
234 m_transform = std::make_shared<const Transform3D>(
236 if (trapezoid !=
nullptr) {
238 auto trapezoidBounds = std::make_shared<const TrapezoidBounds>(
239 scalor * trapezoid->GetDx1(), scalor * trapezoid->GetDx2(),
240 scalor * 0.5 * (trapezoid->GetDy1() + trapezoid->GetDy2()));
242 m_thickness = scalor * trapezoid->GetDz();
244 m_bounds = trapezoidBounds;
246 surface = Surface::makeShared<PlaneSurface>(trapezoidBounds, *
this);
249 auto rectangleBounds = std::make_shared<const RectangleBounds>(
250 scalor * box->GetDX(), scalor * box->GetDY());
252 m_thickness = scalor * box->GetDZ();
254 m_bounds = rectangleBounds;
256 surface = Surface::makeShared<PlaneSurface>(rectangleBounds, *
this);
258 }
else if (boost::iequals(axes,
"XZY")) {
264 if (islower(axes.at(0)) != 0) {
267 if (islower(axes.at(1)) != 0) {
270 if (islower(axes.at(2)) != 0) {
277 m_transform = std::make_shared<const Transform3D>(
279 if (trapezoid !=
nullptr) {
281 auto trapezoidBounds = std::make_shared<const TrapezoidBounds>(
282 scalor * trapezoid->GetDx1(), scalor * trapezoid->GetDx2(),
283 scalor * trapezoid->GetDz());
286 scalor * 0.5 * (trapezoid->GetDy1() + trapezoid->GetDy2());
288 m_bounds = trapezoidBounds;
290 surface = Surface::makeShared<PlaneSurface>(trapezoidBounds, *
this);
293 auto rectangleBounds = std::make_shared<const RectangleBounds>(
294 scalor * box->GetDX(), scalor * box->GetDZ());
296 m_thickness = scalor * box->GetDY();
298 m_bounds = rectangleBounds;
300 surface = Surface::makeShared<PlaneSurface>(rectangleBounds, *
this);
303 }
else if (boost::iequals(axes,
"YZX")) {
309 if (islower(axes.at(0)) != 0) {
312 if (islower(axes.at(1)) != 0) {
315 if (islower(axes.at(2)) != 0) {
322 m_transform = std::make_shared<const Transform3D>(
324 if (trapezoid !=
nullptr) {
326 auto trapezoidBounds = std::make_shared<const TrapezoidBounds>(
327 scalor * trapezoid->GetDy1(), scalor * trapezoid->GetDy2(),
328 scalor * trapezoid->GetDz());
331 scalor * 0.5 * (trapezoid->GetDx1() + trapezoid->GetDx2());
333 m_bounds = trapezoidBounds;
335 surface = Surface::makeShared<PlaneSurface>(trapezoidBounds, *
this);
338 auto rectangleBounds = std::make_shared<const RectangleBounds>(
339 scalor * box->GetDY(), scalor * box->GetDZ());
341 m_thickness = scalor * box->GetDX();
343 m_bounds = rectangleBounds;
345 surface = Surface::makeShared<PlaneSurface>(rectangleBounds, *
this);
347 }
else if (boost::iequals(axes,
"YXZ")) {
353 if (islower(axes.at(0)) != 0) {
356 if (islower(axes.at(1)) != 0) {
359 if (islower(axes.at(2)) != 0) {
366 m_transform = std::make_shared<const Transform3D>(
368 if (trapezoid !=
nullptr) {
370 auto trapezoidBounds = std::make_shared<const TrapezoidBounds>(
371 scalor * trapezoid->GetDy1(), scalor * trapezoid->GetDy2(),
372 scalor * 0.5 * (trapezoid->GetDx1() + trapezoid->GetDx2()));
374 m_thickness = scalor * trapezoid->GetDz();
376 m_bounds = trapezoidBounds;
378 surface = Surface::makeShared<PlaneSurface>(trapezoidBounds, *
this);
381 auto rectangleBounds = std::make_shared<const RectangleBounds>(
382 scalor * box->GetDY(), scalor * box->GetDX());
384 m_thickness = scalor * box->GetDZ();
386 m_bounds = rectangleBounds;
388 surface = Surface::makeShared<PlaneSurface>(rectangleBounds, *
this);
390 }
else if (boost::iequals(axes,
"ZYX")) {
396 if (islower(axes.at(0)) != 0) {
399 if (islower(axes.at(1)) != 0) {
402 if (islower(axes.at(2)) != 0) {
409 m_transform = std::make_shared<const Transform3D>(
411 if (trapezoid !=
nullptr) {
413 auto trapezoidBounds = std::make_shared<const TrapezoidBounds>(
414 scalor * trapezoid->GetDz(), scalor * trapezoid->GetDz(),
415 scalor * 0.5 * (trapezoid->GetDy1() + trapezoid->GetDy2()));
418 scalor * 0.5 * (trapezoid->GetDx1() + trapezoid->GetDx2());
420 m_bounds = trapezoidBounds;
422 surface = Surface::makeShared<PlaneSurface>(trapezoidBounds, *
this);
425 auto rectangleBounds = std::make_shared<const RectangleBounds>(
426 scalor * box->GetDZ(), scalor * box->GetDY());
428 m_thickness = scalor * box->GetDX();
430 m_bounds = rectangleBounds;
432 surface = Surface::makeShared<PlaneSurface>(rectangleBounds, *
this);
441 if (islower(axes.at(0)) != 0) {
444 if (islower(axes.at(1)) != 0) {
447 if (islower(axes.at(2)) != 0) {
454 m_transform = std::make_shared<const Transform3D>(
456 if (trapezoid !=
nullptr) {
458 auto trapezoidBounds = std::make_shared<const TrapezoidBounds>(
459 scalor * trapezoid->GetDz(), scalor * trapezoid->GetDz(),
460 scalor * 0.5 * (trapezoid->GetDx1() + trapezoid->GetDx2()));
463 scalor * 0.5 * (trapezoid->GetDy1() + trapezoid->GetDy2());
465 m_bounds = trapezoidBounds;
467 surface = Surface::makeShared<PlaneSurface>(trapezoidBounds, *
this);
470 auto rectangleBounds = std::make_shared<const RectangleBounds>(
471 scalor * box->GetDZ(), scalor * box->GetDX());
473 m_thickness = scalor * box->GetDY();
475 m_bounds = rectangleBounds;
477 surface = Surface::makeShared<PlaneSurface>(rectangleBounds, *
this);
484 surface->assignSurfaceMaterial(std::move(material));