EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoTrd2ConversionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoTrd2ConversionTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
11 
20 
21 #include "TGeoManager.h"
22 #include "TGeoMaterial.h"
23 #include "TGeoMatrix.h"
24 #include "TGeoMedium.h"
25 #include "TGeoTrd1.h"
26 #include "TGeoVolume.h"
27 #include "TView.h"
28 
29 namespace bdata = boost::unit_test::data;
30 namespace tt = boost::test_tools;
31 
32 namespace Acts {
33 
34 namespace Test {
35 
37 
38 ViewConfig red({200, 0, 0});
39 ViewConfig green({0, 200, 0});
40 ViewConfig blue({0, 0, 200});
41 
45 BOOST_AUTO_TEST_CASE(TGeoTrd2_xz_to_PlaneSurface) {
46  ObjVisualization3D objVis;
47 
48  double hxmin = 10.;
49  double hxmax = 30.;
50  double t = 1.;
51  double hy = 40.;
52 
53  new TGeoManager("trd1", "poza9");
54  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
55  TGeoMedium *med = new TGeoMedium("MED", 1, mat);
56  TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
57  gGeoManager->SetTopVolume(top);
58  TGeoVolume *vol = gGeoManager->MakeTrd2("Trd2", med, hxmin, hxmax, t, t, hy);
59  gGeoManager->CloseGeometry();
60 
61  // Check the 4 possible ways
62  std::vector<std::string> axesTypes = {"XZ*", "xZ*", "xz*", "Xz*"};
63 
64  size_t itrd = 0;
65  for (const auto &axes : axesTypes) {
66  auto plane = TGeoSurfaceConverter::toSurface(*vol->GetShape(),
67  *gGeoIdentity, axes, 1);
68  BOOST_CHECK_NE(plane, nullptr);
69  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
70 
71  auto bounds = dynamic_cast<const TrapezoidBounds *>(&(plane->bounds()));
72  BOOST_CHECK_NE(bounds, nullptr);
73  double hXminY = bounds->get(TrapezoidBounds::eHalfLengthXnegY);
74  double hXmaxY = bounds->get(TrapezoidBounds::eHalfLengthXposY);
75  double hY = bounds->get(TrapezoidBounds::eHalfLengthY);
76 
77  CHECK_CLOSE_ABS(hxmin, std::min(hXminY, hXmaxY), s_epsilon);
78  CHECK_CLOSE_ABS(hxmax, std::max(hXminY, hXmaxY), s_epsilon);
79  CHECK_CLOSE_ABS(hy, hY, s_epsilon);
80 
81  // Check if the surface is the (negative) identity
82  auto transform = plane->transform(tgContext);
83  auto rotation = transform.rotation();
84  const Vector3D offset{(-5.5 + (itrd++) * 2.5) * hxmax, 0., 0.};
86  objVis, *plane, tgContext,
87  Translation3D{offset} * Transform3D::Identity());
88  const Vector3D center = plane->center(tgContext) + offset;
90  objVis, center, center + 1.2 * (hXminY + hXmaxY) * rotation.col(0), 4.,
91  2.5, red);
93  objVis, center, center + 1.2 * hY * rotation.col(1), 4., 2.5, green);
95  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
96  }
97  objVis.write("TGeoConversion_TGeoTrd2_xz_PlaneSurface");
98 
99  // Check exceptions for not allowed axis definition
100  std::vector<std::string> notAllowed = {"XY*", "xy*", "Xy*", "xY*"};
101  for (const auto &naxis : notAllowed) {
102  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
103  *gGeoIdentity, naxis, 1),
104  std::invalid_argument);
105  }
106 }
107 
111 BOOST_AUTO_TEST_CASE(TGeoTrd2_yz_to_PlaneSurface) {
112  ObjVisualization3D objVis;
113 
114  double hxmin = 10.;
115  double hxmax = 30.;
116  double t = 1.;
117  double hy = 40.;
118 
119  new TGeoManager("trd1", "poza9");
120  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
121  TGeoMedium *med = new TGeoMedium("MED", 1, mat);
122  TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
123  gGeoManager->SetTopVolume(top);
124  TGeoVolume *vol = gGeoManager->MakeTrd2("Trd2", med, t, t, hxmin, hxmax, hy);
125  gGeoManager->CloseGeometry();
126 
127  // Check the 4 possible ways
128  std::vector<std::string> axesTypes = {"YZ*", "yZ*", "yz*", "Yz*"};
129 
130  size_t itrd = 0;
131  for (const auto &axes : axesTypes) {
132  auto plane = TGeoSurfaceConverter::toSurface(*vol->GetShape(),
133  *gGeoIdentity, axes, 1);
134  BOOST_CHECK_NE(plane, nullptr);
135  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
136 
137  auto bounds = dynamic_cast<const TrapezoidBounds *>(&(plane->bounds()));
138  BOOST_CHECK_NE(bounds, nullptr);
139  double hXminY = bounds->get(TrapezoidBounds::eHalfLengthXnegY);
140  double hXmaxY = bounds->get(TrapezoidBounds::eHalfLengthXposY);
141  double hY = bounds->get(TrapezoidBounds::eHalfLengthY);
142 
143  CHECK_CLOSE_ABS(hxmin, std::min(hXminY, hXmaxY), s_epsilon);
144  CHECK_CLOSE_ABS(hxmax, std::max(hXminY, hXmaxY), s_epsilon);
145  CHECK_CLOSE_ABS(hy, hY, s_epsilon);
146 
147  // Check if the surface is the (negative) identity
148  auto transform = plane->transform(tgContext);
149  auto rotation = transform.rotation();
150  const Vector3D offset{(-5.5 + (itrd++) * 2.5) * hxmax, 0., 0.};
152  objVis, *plane, tgContext,
153  Translation3D{offset} * Transform3D::Identity());
154  const Vector3D center = plane->center(tgContext) + offset;
156  objVis, center, center + 1.2 * (hXminY + hXmaxY) * rotation.col(0), 4.,
157  2.5, red);
159  objVis, center, center + 1.2 * hY * rotation.col(1), 4., 2.5, green);
161  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
162  }
163  objVis.write("TGeoConversion_TGeoTrd2_yz_PlaneSurface");
164 
165  // Check exceptions for not allowed axis definition
166  std::vector<std::string> notAllowed = {"YX*", "yx*", "yX*", "Yx*"};
167  for (const auto &naxis : notAllowed) {
168  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
169  *gGeoIdentity, naxis, 1),
170  std::invalid_argument);
171  }
172 }
173 
174 } // namespace Test
175 
176 } // namespace Acts