EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoArb8ConversionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoArb8ConversionTests.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 "TGeoArb8.h"
22 #include "TGeoManager.h"
23 #include "TGeoMaterial.h"
24 #include "TGeoMatrix.h"
25 #include "TGeoMedium.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(TGeoArb8_to_PlaneSurface) {
46  ObjVisualization3D objVis;
47 
48  new TGeoManager("arb8", "poza12");
49  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
50  TGeoMedium *med = new TGeoMedium("MED", 1, mat);
51  TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
52  gGeoManager->SetTopVolume(top);
53  TGeoArb8 *arb = new TGeoArb8(1);
54  arb->SetVertex(0, -30, -25);
55  arb->SetVertex(1, -25, 25);
56  arb->SetVertex(2, 5, 25);
57  arb->SetVertex(3, 25, -25);
58  arb->SetVertex(4, -30, -25);
59  arb->SetVertex(5, -25, 25);
60  arb->SetVertex(6, 5, 25);
61  arb->SetVertex(7, 25, -25);
62  TGeoVolume *vol = new TGeoVolume("ARB8", arb, med);
63  top->AddNode(vol, 1);
64  gGeoManager->CloseGeometry();
65 
66  // Check the 4 possible ways
67  std::vector<std::string> allowedAxes = {"XY*", "xy*", "Xy*", "xY*",
68  "YX*", "yx*", "Yx*", "yX*"};
69 
70  size_t iarb8 = 0;
71  for (const auto &axes : allowedAxes) {
72  auto plane = TGeoSurfaceConverter::toSurface(*vol->GetShape(),
73  *gGeoIdentity, axes, 1);
74  BOOST_CHECK_NE(plane, nullptr);
75  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
76 
77  auto bounds =
78  dynamic_cast<const ConvexPolygonBounds<4> *>(&(plane->bounds()));
79  BOOST_CHECK_NE(bounds, nullptr);
80 
81  // Check if the surface is the (negative) identity
82  auto transform = plane->transform(tgContext);
83  auto rotation = transform.rotation();
85  const Vector3D center = plane->center(tgContext);
87  objVis, center, center + 30 * rotation.col(0), 4., 2.5, red);
89  objVis, center, center + 30 * rotation.col(1), 4., 2.5, green);
91  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
92 
93  objVis.write("TGeoConversion_TGeoArb8_PlaneSurface_" +
94  std::to_string(iarb8++));
95  objVis.clear();
96  }
97 
98  // Check exceptions for not allowed axis definition
99  std::vector<std::string> notAllowed = {
100  "XZ*", "xz*", "xZ*", "Xz*", "ZX*", "zx*", "zX*", "Zx*",
101  "YZ*", "yz*", "yZ*", "Yz*", "ZY*", "zy*", "Zy*", "zY*"};
102  for (const auto &naxis : notAllowed) {
103  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
104  *gGeoIdentity, naxis, 1),
105  std::invalid_argument);
106  }
107 }
108 
109 } // namespace Test
110 
111 } // namespace Acts