Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DD4hepTestsHelper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DD4hepTestsHelper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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 "DD4hepTestsHelper.hpp"
10 
13 
15  const xml_comp_t& x_det_comp) {
16  // Build the transform - center def
17  double cx = Acts::getAttrValueOr<double>(x_det_comp, "cx", 0.);
18  double cy = Acts::getAttrValueOr<double>(x_det_comp, "cy", 0.);
19  double cz = Acts::getAttrValueOr<double>(x_det_comp, "cz", 0.);
20 
21  double xx = Acts::getAttrValueOr<double>(x_det_comp, "xx", 1.);
22  double xy = Acts::getAttrValueOr<double>(x_det_comp, "xy", 0.);
23  double xz = Acts::getAttrValueOr<double>(x_det_comp, "xz", 0.);
24 
25  double yx = Acts::getAttrValueOr<double>(x_det_comp, "yx", 0.);
26  double yy = Acts::getAttrValueOr<double>(x_det_comp, "yy", 1.);
27  double yz = Acts::getAttrValueOr<double>(x_det_comp, "yz", 0.);
28 
29  Position xAxis(xx, xy, xz);
30  Position yAxis(yx, yy, yz);
31  Position zAxis = xAxis.Cross(yAxis);
32  double zx = zAxis.X();
33  double zy = zAxis.Y();
34  double zz = zAxis.Z();
35 
36  // Create the transform
37  return Transform3D(xx, yx, zx, cx, xy, yy, zy, cy, xz, yz, zz, cz);
38 }
39 
41  const std::array<int, 2u>& axes) {
42  auto tr = tf.translation();
43  auto rot = tf.rotation();
44 
45  std::stringstream sxml;
46  sxml << "cx=\"" << tr[0u] << "*mm\" ";
47  sxml << "cy=\"" << tr[1u] << "*mm\" ";
48  sxml << "cz=\"" << tr[2u] << "*mm\" ";
49 
50  sxml << "xx=\"" << rot.col(axes[0u])[0u] << "\" ";
51  sxml << "xy=\"" << rot.col(axes[0u])[1u] << "\" ";
52  sxml << "xz=\"" << rot.col(axes[0u])[2u] << "\" ";
53  sxml << "yx=\"" << rot.col(axes[1u])[0u] << "\" ";
54  sxml << "yy=\"" << rot.col(axes[1u])[1u] << "\" ";
55  sxml << "yz=\"" << rot.col(axes[1u])[2u] << "\" ";
56 
57  return sxml.str();
58 }
59 
61  const Acts::Surface& surface,
62  const Acts::Transform3& ref) {
63  // The xml to be translated
64  std::stringstream sxml;
65  auto boundValues = surface.bounds().values();
66 
67  std::array<int, 2u> axes = {0, 1};
68  // Change/adapt the behavior
69  switch (surface.bounds().type()) {
71  sxml << "<box ";
72  double dx = (boundValues[2u] - boundValues[0u]);
73  double dy = (boundValues[3u] - boundValues[1u]);
74  double dz = 0.125;
75  sxml << "dx=\"" << dx << "*mm\" ";
76  sxml << "dy=\"" << dy << "*mm\" ";
77  sxml << "dz=\"" << dz << "*mm\" ";
78  }; break;
80  axes = {2, 0};
81 
82  sxml << "<trap ";
83  double hxmin = boundValues[0u];
84  double hxmax = boundValues[1u];
85  double dy = 2 * boundValues[2u];
86  double dz = 0.125;
87  sxml << "x1=\"" << hxmin << "*mm\" ";
88  sxml << "x2=\"" << hxmax << "*mm\" ";
89  sxml << "dy=\"" << dy << "*mm\" ";
90  sxml << "dz=\"" << dz << "*mm\" ";
91  }; break;
92  default:
93  break;
94  }
95 
96  // Unwind the placement you have already
97  auto relTransform = ref * surface.transform(gctx);
98  sxml << transformToXML(relTransform, axes);
99  sxml << " material=\"Air\"";
100  sxml << " sensitive=\"true\"/>";
101  return sxml.str();
102 }