EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoTrd1ConversionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoTrd1ConversionTests.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(TGeoTrd1_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->MakeTrd1("Trd1", med, hxmin, hxmax, t, hy);
59  gGeoManager->CloseGeometry();
60 
61  // Check the 4 possible ways
62  std::vector<std::string> allowedAxes = {"XZ*", "xZ*", "xz*", "Xz*"};
63 
64  size_t itrd = 0;
65  for (const auto &axes : allowedAxes) {
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 
98  // Check exceptions for not allowed axis definition
99  std::vector<std::string> notAllowed = {"XY*", "YZ*", "ZX*", "ZY*"};
100  for (const auto &naxis : notAllowed) {
101  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
102  *gGeoIdentity, naxis, 1),
103  std::invalid_argument);
104  }
105  objVis.write("TGeoConversion_TGeoTrd1_PlaneSurface");
106 }
107 
108 } // namespace Test
109 
110 } // namespace Acts