Analysis Software
Documentation for sPHENIX simulation 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 
23 
24 #include <algorithm>
25 #include <cstddef>
26 #include <memory>
27 #include <stdexcept>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include "TGeoManager.h"
33 #include "TGeoMaterial.h"
34 #include "TGeoMatrix.h"
35 #include "TGeoMedium.h"
36 #include "TGeoTrd1.h"
37 #include "TGeoVolume.h"
38 #include "TView.h"
39 
40 namespace bdata = boost::unit_test::data;
41 namespace tt = boost::test_tools;
42 
43 namespace Acts {
44 
45 namespace Test {
46 
48 
49 ViewConfig red({200, 0, 0});
50 ViewConfig green({0, 200, 0});
51 ViewConfig blue({0, 0, 200});
52 
56 BOOST_AUTO_TEST_CASE(TGeoTrd2_xz_to_PlaneSurface) {
57  ObjVisualization3D objVis;
58 
59  double hxmin = 10.;
60  double hxmax = 30.;
61  double ht = 1.; // this is the half thickness
62  double hy = 40.;
63 
64  new TGeoManager("trd1", "poza9");
65  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
66  TGeoMedium *med = new TGeoMedium("MED", 1, mat);
67  TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
68  gGeoManager->SetTopVolume(top);
69  TGeoVolume *vol =
70  gGeoManager->MakeTrd2("Trd2", med, hxmin, hxmax, ht, ht, hy);
71  gGeoManager->CloseGeometry();
72 
73  // Check the 4 possible ways
74  std::vector<std::string> axesTypes = {"XZ*", "xZ*", "xz*", "Xz*"};
75 
76  size_t itrd = 0;
77  for (const auto &axes : axesTypes) {
79  *vol->GetShape(), *gGeoIdentity, axes, 1);
80  BOOST_CHECK_NE(plane, nullptr);
81  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
83 
84  auto bounds = dynamic_cast<const TrapezoidBounds *>(&(plane->bounds()));
85  BOOST_CHECK_NE(bounds, nullptr);
86  double hXminY = bounds->get(TrapezoidBounds::eHalfLengthXnegY);
87  double hXmaxY = bounds->get(TrapezoidBounds::eHalfLengthXposY);
88  double hY = bounds->get(TrapezoidBounds::eHalfLengthY);
89 
90  CHECK_CLOSE_ABS(hxmin, std::min(hXminY, hXmaxY), s_epsilon);
91  CHECK_CLOSE_ABS(hxmax, std::max(hXminY, hXmaxY), s_epsilon);
92  CHECK_CLOSE_ABS(hy, hY, s_epsilon);
93 
94  // Check if the surface is the (negative) identity
95  auto transform = plane->transform(tgContext);
96  auto rotation = transform.rotation();
97  const Vector3 offset{(-5.5 + (itrd++) * 2.5) * hxmax, 0., 0.};
99  Translation3{offset} * Transform3::Identity());
100  const Vector3 center = plane->center(tgContext) + offset;
102  objVis, center, center + 1.2 * (hXminY + hXmaxY) * rotation.col(0), 4.,
103  2.5, red);
105  objVis, center, center + 1.2 * hY * rotation.col(1), 4., 2.5, green);
107  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
108  }
109  objVis.write("TGeoConversion_TGeoTrd2_xz_PlaneSurface");
110 
111  // Check exceptions for not allowed axis definition
112  std::vector<std::string> notAllowed = {"XY*", "xy*", "Xy*", "xY*"};
113  for (const auto &naxis : notAllowed) {
114  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
115  *gGeoIdentity, naxis, 1),
116  std::invalid_argument);
117  }
118 }
119 
123 BOOST_AUTO_TEST_CASE(TGeoTrd2_yz_to_PlaneSurface) {
124  ObjVisualization3D objVis;
125 
126  double hxmin = 10.;
127  double hxmax = 30.;
128  double ht = 1.; // this is the half thickness
129  double hy = 40.;
130 
131  new TGeoManager("trd1", "poza9");
132  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
133  TGeoMedium *med = new TGeoMedium("MED", 1, mat);
134  TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
135  gGeoManager->SetTopVolume(top);
136  TGeoVolume *vol =
137  gGeoManager->MakeTrd2("Trd2", med, ht, ht, hxmin, hxmax, hy);
138  gGeoManager->CloseGeometry();
139 
140  // Check the 4 possible ways
141  std::vector<std::string> axesTypes = {"YZ*", "yZ*", "yz*", "Yz*"};
142 
143  size_t itrd = 0;
144  for (const auto &axes : axesTypes) {
146  *vol->GetShape(), *gGeoIdentity, axes, 1);
147  BOOST_CHECK_NE(plane, nullptr);
148  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
150 
151  auto bounds = dynamic_cast<const TrapezoidBounds *>(&(plane->bounds()));
152  BOOST_CHECK_NE(bounds, nullptr);
153  double hXminY = bounds->get(TrapezoidBounds::eHalfLengthXnegY);
154  double hXmaxY = bounds->get(TrapezoidBounds::eHalfLengthXposY);
155  double hY = bounds->get(TrapezoidBounds::eHalfLengthY);
156 
157  CHECK_CLOSE_ABS(hxmin, std::min(hXminY, hXmaxY), s_epsilon);
158  CHECK_CLOSE_ABS(hxmax, std::max(hXminY, hXmaxY), s_epsilon);
159  CHECK_CLOSE_ABS(hy, hY, s_epsilon);
160 
161  // Check if the surface is the (negative) identity
162  auto transform = plane->transform(tgContext);
163  auto rotation = transform.rotation();
164  const Vector3 offset{(-5.5 + (itrd++) * 2.5) * hxmax, 0., 0.};
166  Translation3{offset} * Transform3::Identity());
167  const Vector3 center = plane->center(tgContext) + offset;
169  objVis, center, center + 1.2 * (hXminY + hXmaxY) * rotation.col(0), 4.,
170  2.5, red);
172  objVis, center, center + 1.2 * hY * rotation.col(1), 4., 2.5, green);
174  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
175  }
176  objVis.write("TGeoConversion_TGeoTrd2_yz_PlaneSurface");
177 
178  // Check exceptions for not allowed axis definition
179  std::vector<std::string> notAllowed = {"YX*", "yx*", "yX*", "Yx*"};
180  for (const auto &naxis : notAllowed) {
181  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
182  *gGeoIdentity, naxis, 1),
183  std::invalid_argument);
184  }
185 }
186 
187 } // namespace Test
188 
189 } // namespace Acts