Analysis Software
Documentation for sPHENIX simulation 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-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 <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(TGeoTrd1_to_PlaneSurface) {
57  ObjVisualization3D objVis;
58 
59  double hxmin = 10.;
60  double hxmax = 30.;
61  double ht = 1.; // 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 = gGeoManager->MakeTrd1("Trd1", med, hxmin, hxmax, ht, hy);
70  gGeoManager->CloseGeometry();
71 
72  // Check the 4 possible ways
73  std::vector<std::string> allowedAxes = {"XZ*", "xZ*", "xz*", "Xz*"};
74 
75  size_t itrd = 0;
76  for (const auto &axes : allowedAxes) {
78  *vol->GetShape(), *gGeoIdentity, axes, 1);
79  BOOST_CHECK_NE(plane, nullptr);
80  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
82 
83  auto bounds = dynamic_cast<const TrapezoidBounds *>(&(plane->bounds()));
84  BOOST_CHECK_NE(bounds, nullptr);
85  double hXminY = bounds->get(TrapezoidBounds::eHalfLengthXnegY);
86  double hXmaxY = bounds->get(TrapezoidBounds::eHalfLengthXposY);
87  double hY = bounds->get(TrapezoidBounds::eHalfLengthY);
88 
89  CHECK_CLOSE_ABS(hxmin, std::min(hXminY, hXmaxY), s_epsilon);
90  CHECK_CLOSE_ABS(hxmax, std::max(hXminY, hXmaxY), s_epsilon);
91  CHECK_CLOSE_ABS(hy, hY, s_epsilon);
92 
93  // Check if the surface is the (negative) identity
94  auto transform = plane->transform(tgContext);
95  auto rotation = transform.rotation();
96  const Vector3 offset{(-5.5 + (itrd++) * 2.5) * hxmax, 0., 0.};
98  Translation3{offset} * Transform3::Identity());
99  const Vector3 center = plane->center(tgContext) + offset;
101  objVis, center, center + 1.2 * (hXminY + hXmaxY) * rotation.col(0), 4.,
102  2.5, red);
104  objVis, center, center + 1.2 * hY * rotation.col(1), 4., 2.5, green);
106  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
107  }
108 
109  // Check exceptions for not allowed axis definition
110  std::vector<std::string> notAllowed = {"XY*", "YZ*", "ZX*", "ZY*"};
111  for (const auto &naxis : notAllowed) {
112  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
113  *gGeoIdentity, naxis, 1),
114  std::invalid_argument);
115  }
116  objVis.write("TGeoConversion_TGeoTrd1_PlaneSurface");
117 }
118 
119 } // namespace Test
120 
121 } // namespace Acts