File indexing completed on 2025-01-18 09:13:12
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/Plugins/TGeo/TGeoSurfaceConverter.hpp"
0014 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 #include "Acts/Visualization/GeometryView3D.hpp"
0018 #include "Acts/Visualization/ObjVisualization3D.hpp"
0019 #include "Acts/Visualization/ViewConfig.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 namespace Acts::Test {
0036
0037 GeometryContext tgContext = GeometryContext();
0038
0039 ViewConfig red{.color = {200, 0, 0}};
0040 ViewConfig green{.color = {0, 200, 0}};
0041 ViewConfig blue{.color = {0, 0, 200}};
0042
0043
0044
0045
0046 BOOST_AUTO_TEST_CASE(TGeoArb8_to_PlaneSurface) {
0047 ObjVisualization3D objVis;
0048
0049 new TGeoManager("arb8", "poza12");
0050 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
0051 TGeoMedium *med = new TGeoMedium("MED", 1, mat);
0052 TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
0053 gGeoManager->SetTopVolume(top);
0054
0055
0056
0057 double dZ = 1.;
0058 TGeoArb8 *arb = new TGeoArb8(dZ);
0059 arb->SetVertex(0, -30, -25);
0060 arb->SetVertex(1, -25, 25);
0061 arb->SetVertex(2, 5, 25);
0062 arb->SetVertex(3, 25, -25);
0063 arb->SetVertex(4, -30, -25);
0064 arb->SetVertex(5, -25, 25);
0065 arb->SetVertex(6, 5, 25);
0066 arb->SetVertex(7, 25, -25);
0067 TGeoVolume *vol = new TGeoVolume("ARB8", arb, med);
0068 top->AddNode(vol, 1);
0069 gGeoManager->CloseGeometry();
0070
0071
0072 std::vector<std::string> allowedAxes = {"XY*", "xy*", "Xy*", "xY*",
0073 "YX*", "yx*", "Yx*", "yX*"};
0074
0075 std::size_t iarb8 = 0;
0076 for (const auto &axes : allowedAxes) {
0077 auto [plane, thickness] = TGeoSurfaceConverter::toSurface(
0078 *vol->GetShape(), *gGeoIdentity, axes, 1);
0079 BOOST_REQUIRE_NE(plane, nullptr);
0080 BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
0081 BOOST_CHECK_EQUAL(thickness, dZ * 2.);
0082
0083 auto bounds =
0084 dynamic_cast<const ConvexPolygonBounds<4> *>(&(plane->bounds()));
0085 BOOST_CHECK_NE(bounds, nullptr);
0086
0087
0088 auto transform = plane->transform(tgContext);
0089 auto rotation = transform.rotation();
0090 GeometryView3D::drawSurface(objVis, *plane, tgContext);
0091 const Vector3 center = plane->center(tgContext);
0092 GeometryView3D::drawArrowForward(
0093 objVis, center, center + 30 * rotation.col(0), 4., 2.5, red);
0094 GeometryView3D::drawArrowForward(
0095 objVis, center, center + 30 * rotation.col(1), 4., 2.5, green);
0096 GeometryView3D::drawArrowForward(
0097 objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
0098
0099 objVis.write("TGeoConversion_TGeoArb8_PlaneSurface_" +
0100 std::to_string(iarb8++));
0101 objVis.clear();
0102 }
0103
0104
0105 std::vector<std::string> notAllowed = {
0106 "XZ*", "xz*", "xZ*", "Xz*", "ZX*", "zx*", "zX*", "Zx*",
0107 "YZ*", "yz*", "yZ*", "Yz*", "ZY*", "zy*", "Zy*", "zY*"};
0108 for (const auto &naxis : notAllowed) {
0109 BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
0110 *gGeoIdentity, naxis, 1),
0111 std::invalid_argument);
0112 }
0113 }
0114
0115 }