File indexing completed on 2025-12-16 09:25:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 #include "Acts/Visualization/GeometryView3D.hpp"
0017 #include "Acts/Visualization/ObjVisualization3D.hpp"
0018 #include "Acts/Visualization/ViewConfig.hpp"
0019 #include "ActsPlugins/Root/TGeoSurfaceConverter.hpp"
0020
0021 #include <cstddef>
0022 #include <memory>
0023 #include <stdexcept>
0024 #include <string>
0025 #include <vector>
0026
0027 #include "TGeoArb8.h"
0028 #include "TGeoManager.h"
0029 #include "TGeoMaterial.h"
0030 #include "TGeoMatrix.h"
0031 #include "TGeoMedium.h"
0032 #include "TGeoVolume.h"
0033 #include "TView.h"
0034
0035 using namespace Acts;
0036 using namespace ActsPlugins;
0037
0038 namespace ActsTests {
0039
0040 GeometryContext tgContext = GeometryContext();
0041
0042 ViewConfig red{.color = {200, 0, 0}};
0043 ViewConfig green{.color = {0, 200, 0}};
0044 ViewConfig blue{.color = {0, 0, 200}};
0045
0046 BOOST_AUTO_TEST_SUITE(RootSuite)
0047
0048
0049
0050
0051 BOOST_AUTO_TEST_CASE(TGeoArb8_to_PlaneSurface) {
0052 ObjVisualization3D objVis;
0053
0054 new TGeoManager("arb8", "poza12");
0055 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
0056 TGeoMedium *med = new TGeoMedium("MED", 1, mat);
0057 TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
0058 gGeoManager->SetTopVolume(top);
0059
0060
0061
0062 double dZ = 1.;
0063 TGeoArb8 *arb = new TGeoArb8(dZ);
0064 arb->SetVertex(0, -30, -25);
0065 arb->SetVertex(1, -25, 25);
0066 arb->SetVertex(2, 5, 25);
0067 arb->SetVertex(3, 25, -25);
0068 arb->SetVertex(4, -30, -25);
0069 arb->SetVertex(5, -25, 25);
0070 arb->SetVertex(6, 5, 25);
0071 arb->SetVertex(7, 25, -25);
0072 TGeoVolume *vol = new TGeoVolume("ARB8", arb, med);
0073 top->AddNode(vol, 1);
0074 gGeoManager->CloseGeometry();
0075
0076
0077 std::vector<std::string> allowedAxes = {"XY*", "xy*", "Xy*", "xY*",
0078 "YX*", "yx*", "Yx*", "yX*"};
0079
0080 std::size_t iarb8 = 0;
0081 for (const auto &axes : allowedAxes) {
0082 auto [plane, thickness] = TGeoSurfaceConverter::toSurface(
0083 *vol->GetShape(), *gGeoIdentity, axes, 1);
0084 BOOST_REQUIRE_NE(plane, nullptr);
0085 BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
0086 BOOST_CHECK_EQUAL(thickness, dZ * 2.);
0087
0088 auto bounds =
0089 dynamic_cast<const ConvexPolygonBounds<4> *>(&(plane->bounds()));
0090 BOOST_CHECK_NE(bounds, nullptr);
0091
0092
0093 auto transform = plane->transform(tgContext);
0094 auto rotation = transform.rotation();
0095 GeometryView3D::drawSurface(objVis, *plane, tgContext);
0096 const Vector3 center = plane->center(tgContext);
0097 GeometryView3D::drawArrowForward(
0098 objVis, center, center + 30 * rotation.col(0), 4., 2.5, red);
0099 GeometryView3D::drawArrowForward(
0100 objVis, center, center + 30 * rotation.col(1), 4., 2.5, green);
0101 GeometryView3D::drawArrowForward(
0102 objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
0103
0104 objVis.write("TGeoConversion_TGeoArb8_PlaneSurface_" +
0105 std::to_string(iarb8++));
0106 objVis.clear();
0107 }
0108
0109
0110 std::vector<std::string> notAllowed = {
0111 "XZ*", "xz*", "xZ*", "Xz*", "ZX*", "zx*", "zX*", "Zx*",
0112 "YZ*", "yz*", "yZ*", "Yz*", "ZY*", "zy*", "Zy*", "zY*"};
0113 for (const auto &naxis : notAllowed) {
0114 BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
0115 *gGeoIdentity, naxis, 1),
0116 std::invalid_argument);
0117 }
0118 }
0119
0120 BOOST_AUTO_TEST_SUITE_END()
0121
0122 }