Analysis Software
Documentation for sPHENIX simulation 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-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 
21 
22 #include <cstddef>
23 #include <memory>
24 #include <stdexcept>
25 #include <string>
26 #include <vector>
27 
28 #include "TGeoArb8.h"
29 #include "TGeoManager.h"
30 #include "TGeoMaterial.h"
31 #include "TGeoMatrix.h"
32 #include "TGeoMedium.h"
33 #include "TGeoVolume.h"
34 #include "TView.h"
35 
36 namespace bdata = boost::unit_test::data;
37 namespace tt = boost::test_tools;
38 
39 namespace Acts {
40 
41 namespace Test {
42 
44 
45 ViewConfig red({200, 0, 0});
46 ViewConfig green({0, 200, 0});
47 ViewConfig blue({0, 0, 200});
48 
52 BOOST_AUTO_TEST_CASE(TGeoArb8_to_PlaneSurface) {
53  ObjVisualization3D objVis;
54 
55  new TGeoManager("arb8", "poza12");
56  TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
57  TGeoMedium *med = new TGeoMedium("MED", 1, mat);
58  TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
59  gGeoManager->SetTopVolume(top);
60  // The one parameter at construction is dZ, when the
61  // TGeoArb8 is spanning from -dZ to +dZ:
62  // - hence, the thickness is 2 * dZ
63  ActsScalar dZ = 1.;
64  TGeoArb8 *arb = new TGeoArb8(dZ);
65  arb->SetVertex(0, -30, -25);
66  arb->SetVertex(1, -25, 25);
67  arb->SetVertex(2, 5, 25);
68  arb->SetVertex(3, 25, -25);
69  arb->SetVertex(4, -30, -25);
70  arb->SetVertex(5, -25, 25);
71  arb->SetVertex(6, 5, 25);
72  arb->SetVertex(7, 25, -25);
73  TGeoVolume *vol = new TGeoVolume("ARB8", arb, med);
74  top->AddNode(vol, 1);
75  gGeoManager->CloseGeometry();
76 
77  // Check the 4 possible ways
78  std::vector<std::string> allowedAxes = {"XY*", "xy*", "Xy*", "xY*",
79  "YX*", "yx*", "Yx*", "yX*"};
80 
81  size_t iarb8 = 0;
82  for (const auto &axes : allowedAxes) {
84  *vol->GetShape(), *gGeoIdentity, axes, 1);
85  BOOST_CHECK_NE(plane, nullptr);
86  BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
87  BOOST_CHECK_EQUAL(thickness, dZ * 2.);
88 
89  auto bounds =
90  dynamic_cast<const ConvexPolygonBounds<4> *>(&(plane->bounds()));
91  BOOST_CHECK_NE(bounds, nullptr);
92 
93  // Check if the surface is the (negative) identity
94  auto transform = plane->transform(tgContext);
95  auto rotation = transform.rotation();
97  const Vector3 center = plane->center(tgContext);
99  objVis, center, center + 30 * rotation.col(0), 4., 2.5, red);
101  objVis, center, center + 30 * rotation.col(1), 4., 2.5, green);
103  objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
104 
105  objVis.write("TGeoConversion_TGeoArb8_PlaneSurface_" +
106  std::to_string(iarb8++));
107  objVis.clear();
108  }
109 
110  // Check exceptions for not allowed axis definition
111  std::vector<std::string> notAllowed = {
112  "XZ*", "xz*", "xZ*", "Xz*", "ZX*", "zx*", "zX*", "Zx*",
113  "YZ*", "yz*", "yZ*", "Yz*", "ZY*", "zy*", "Zy*", "zY*"};
114  for (const auto &naxis : notAllowed) {
115  BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
116  *gGeoIdentity, naxis, 1),
117  std::invalid_argument);
118  }
119 }
120 
121 } // namespace Test
122 
123 } // namespace Acts