File indexing completed on 2025-01-18 09:13:13
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/Definitions/Tolerance.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Plugins/TGeo/TGeoSurfaceConverter.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Surfaces/SurfaceBounds.hpp"
0018 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0019 #include "Acts/Visualization/GeometryView3D.hpp"
0020 #include "Acts/Visualization/ObjVisualization3D.hpp"
0021 #include "Acts/Visualization/ViewConfig.hpp"
0022
0023 #include <memory>
0024 #include <utility>
0025
0026 #include "TGeoBBox.h"
0027 #include "TGeoManager.h"
0028 #include "TGeoMaterial.h"
0029 #include "TGeoMatrix.h"
0030 #include "TGeoMedium.h"
0031 #include "TGeoVolume.h"
0032 #include "TView.h"
0033
0034 namespace Acts::Test {
0035
0036 GeometryContext tgContext = GeometryContext();
0037
0038 ViewConfig red{.color = {200, 0, 0}};
0039 ViewConfig green{.color = {0, 200, 0}};
0040 ViewConfig blue{.color = {0, 0, 200}};
0041
0042
0043
0044
0045
0046
0047 BOOST_AUTO_TEST_CASE(TGeoBBox_to_PlaneSurface) {
0048 ObjVisualization3D objVis;
0049
0050
0051 double dX = 10.;
0052 double dY = 30.;
0053 double dZ = 1.;
0054
0055 new TGeoManager("box", "poza1");
0056 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
0057 TGeoMedium *med = new TGeoMedium("MED", 1, mat);
0058 TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
0059 gGeoManager->SetTopVolume(top);
0060 TGeoVolume *vol = gGeoManager->MakeBox("BOX", med, dX, dY, dZ);
0061 vol->SetLineWidth(2);
0062 top->AddNode(vol, 1);
0063 gGeoManager->CloseGeometry();
0064
0065
0066 auto [plane_XYZ, thickness_XYZ] = TGeoSurfaceConverter::toSurface(
0067 *vol->GetShape(), *gGeoIdentity, "XY*", 1);
0068 BOOST_REQUIRE_NE(plane_XYZ, nullptr);
0069 BOOST_CHECK_EQUAL(plane_XYZ->type(), Surface::Plane);
0070 CHECK_CLOSE_ABS(thickness_XYZ, 2 * dZ, s_epsilon);
0071
0072 auto bounds_XYZ =
0073 dynamic_cast<const RectangleBounds *>(&(plane_XYZ->bounds()));
0074 BOOST_REQUIRE_NE(bounds_XYZ, nullptr);
0075 double maxX = bounds_XYZ->get(RectangleBounds::eMaxX);
0076 double minX = bounds_XYZ->get(RectangleBounds::eMinX);
0077 double maxY = bounds_XYZ->get(RectangleBounds::eMaxY);
0078 double minY = bounds_XYZ->get(RectangleBounds::eMinY);
0079 CHECK_CLOSE_ABS(maxX - minX, 2 * dX, s_epsilon);
0080 CHECK_CLOSE_ABS(maxY - minY, 2 * dY, s_epsilon);
0081
0082
0083 auto transform_XYZ = plane_XYZ->transform(tgContext);
0084 auto rotation_XYZ = transform_XYZ.rotation();
0085 BOOST_CHECK(transform_XYZ.isApprox(Transform3::Identity()));
0086
0087 const Vector3 offset_XYZ{-5.5 * dX, 0., 0.};
0088 GeometryView3D::drawSurface(objVis, *plane_XYZ, tgContext,
0089 Transform3(Translation3{offset_XYZ}));
0090 const Vector3 center_XYZ = plane_XYZ->center(tgContext) + offset_XYZ;
0091 GeometryView3D::drawArrowForward(
0092 objVis, center_XYZ,
0093 center_XYZ + 0.6 * (maxX - minX) * rotation_XYZ.col(0), 4., 2.5, red);
0094 GeometryView3D::drawArrowForward(
0095 objVis, center_XYZ,
0096 center_XYZ + 0.6 * (maxY - minY) * rotation_XYZ.col(1), 4., 2.5, green);
0097 GeometryView3D::drawArrowForward(
0098 objVis, center_XYZ, center_XYZ + 2 * rotation_XYZ.col(2), 4., 2.5, blue);
0099
0100
0101 auto [plane_xyz, thickness_xyz] = TGeoSurfaceConverter::toSurface(
0102 *vol->GetShape(), *gGeoIdentity, "xy*", 1);
0103 BOOST_CHECK_NE(plane_xyz, nullptr);
0104 BOOST_CHECK_EQUAL(plane_xyz->type(), Surface::Plane);
0105 CHECK_CLOSE_ABS(thickness_xyz, 2 * dZ, s_epsilon);
0106
0107 auto bounds_xyz =
0108 dynamic_cast<const RectangleBounds *>(&(plane_XYZ->bounds()));
0109 BOOST_REQUIRE_NE(bounds_xyz, nullptr);
0110 BOOST_CHECK_EQUAL(bounds_xyz, bounds_XYZ);
0111 auto transform_xyz = plane_xyz->transform(tgContext);
0112 auto rotation_xyz = transform_xyz.rotation();
0113 BOOST_CHECK(rotation_xyz.col(0).isApprox(-1 * rotation_XYZ.col(0)));
0114 BOOST_CHECK(rotation_xyz.col(1).isApprox(-1 * rotation_XYZ.col(1)));
0115 BOOST_CHECK(rotation_xyz.col(2).isApprox(rotation_XYZ.col(2)));
0116
0117 const Vector3 offset_xyz{-2 * dX, 0., 0.};
0118 GeometryView3D::drawSurface(objVis, *plane_xyz, tgContext,
0119 Transform3(Translation3{offset_xyz}));
0120 const Vector3 center_xyz = plane_xyz->center(tgContext) + offset_xyz;
0121 GeometryView3D::drawArrowForward(
0122 objVis, center_xyz,
0123 center_xyz + 0.6 * (maxX - minX) * rotation_xyz.col(0), 4., 2.5, red);
0124 GeometryView3D::drawArrowForward(
0125 objVis, center_xyz,
0126 center_xyz + 0.6 * (maxY - minY) * rotation_xyz.col(1), 4., 2.5, green);
0127 GeometryView3D::drawArrowForward(
0128 objVis, center_xyz, center_xyz + 2 * rotation_xyz.col(2), 4., 2.5, blue);
0129
0130
0131 auto [plane_xYz, thickness_xYz] = TGeoSurfaceConverter::toSurface(
0132 *vol->GetShape(), *gGeoIdentity, "xY*", 1);
0133 BOOST_REQUIRE_NE(plane_xYz, nullptr);
0134 BOOST_CHECK_EQUAL(plane_xYz->type(), Surface::Plane);
0135 CHECK_CLOSE_ABS(thickness_xYz, 2 * dZ, s_epsilon);
0136
0137 auto bounds_xYz =
0138 dynamic_cast<const RectangleBounds *>(&(plane_xYz->bounds()));
0139 BOOST_CHECK_NE(bounds_xYz, nullptr);
0140 BOOST_CHECK_EQUAL(bounds_xYz, bounds_xYz);
0141 auto transform_xYz = plane_xYz->transform(tgContext);
0142 auto rotation_xYz = transform_xYz.rotation();
0143 BOOST_CHECK(rotation_xYz.col(0).isApprox(-1 * rotation_XYZ.col(0)));
0144 BOOST_CHECK(rotation_xYz.col(1).isApprox(rotation_XYZ.col(1)));
0145 BOOST_CHECK(rotation_xYz.col(2).isApprox(-1. * rotation_XYZ.col(2)));
0146
0147 const Vector3 offset_xYz{2 * dX, 0., 0.};
0148 GeometryView3D::drawSurface(
0149 objVis, *plane_xYz, tgContext,
0150 Translation3{offset_xYz} * Transform3::Identity());
0151 const Vector3 center_xYz = plane_xYz->center(tgContext) + offset_xYz;
0152 GeometryView3D::drawArrowForward(
0153 objVis, center_xYz,
0154 center_xYz + 0.6 * (maxX - minX) * rotation_xYz.col(0), 4., 2.5, red);
0155 GeometryView3D::drawArrowForward(
0156 objVis, center_xYz,
0157 center_xYz + 0.6 * (maxY - minY) * rotation_xYz.col(1), 4., 2.5, green);
0158 GeometryView3D::drawArrowForward(
0159 objVis, center_xYz, center_xYz + 2 * rotation_xYz.col(2), 4., 2.5, blue);
0160
0161
0162 auto [plane_YXz, thickness_YXz] = TGeoSurfaceConverter::toSurface(
0163 *vol->GetShape(), *gGeoIdentity, "YX*", 1);
0164 BOOST_REQUIRE_NE(plane_YXz, nullptr);
0165 BOOST_CHECK_EQUAL(plane_YXz->type(), Surface::Plane);
0166 CHECK_CLOSE_ABS(thickness_YXz, 2 * dZ, s_epsilon);
0167
0168 auto bounds_YXz =
0169 dynamic_cast<const RectangleBounds *>(&(plane_YXz->bounds()));
0170 maxX = bounds_YXz->get(RectangleBounds::eMaxX);
0171 minX = bounds_YXz->get(RectangleBounds::eMinX);
0172 maxY = bounds_YXz->get(RectangleBounds::eMaxY);
0173 minY = bounds_YXz->get(RectangleBounds::eMinY);
0174 CHECK_CLOSE_ABS(maxX - minX, 2 * dY, s_epsilon);
0175 CHECK_CLOSE_ABS(maxY - minY, 2 * dX, s_epsilon);
0176
0177 auto transform_YXz = plane_YXz->transform(tgContext);
0178 auto rotation_YXz = transform_YXz.rotation();
0179 BOOST_CHECK(rotation_YXz.col(0).isApprox(rotation_XYZ.col(1)));
0180 BOOST_CHECK(rotation_YXz.col(1).isApprox(rotation_XYZ.col(0)));
0181 BOOST_CHECK(rotation_YXz.col(2).isApprox(-1. * rotation_XYZ.col(2)));
0182
0183 const Vector3 offset_YXz{5.5 * dX, 0., 0.};
0184 GeometryView3D::drawSurface(objVis, *plane_YXz, tgContext,
0185 Transform3(Translation3{offset_YXz}));
0186 const Vector3 center_YXz = plane_YXz->center(tgContext) + offset_YXz;
0187 GeometryView3D::drawArrowForward(
0188 objVis, center_YXz,
0189 center_YXz + 0.6 * (maxX - minX) * rotation_YXz.col(0), 4., 2.5, red);
0190 GeometryView3D::drawArrowForward(
0191 objVis, center_YXz,
0192 center_YXz + 0.6 * (maxY - minY) * rotation_YXz.col(1), 4., 2.5, green);
0193 GeometryView3D::drawArrowForward(
0194 objVis, center_YXz, center_YXz + 2 * rotation_YXz.col(2), 4., 2.5, blue);
0195
0196
0197 auto [plane_XYZ10, thickness_XYZ10] = TGeoSurfaceConverter::toSurface(
0198 *vol->GetShape(), *gGeoIdentity, "xY*", 10);
0199 BOOST_CHECK_NE(plane_XYZ10, nullptr);
0200 CHECK_CLOSE_ABS(thickness_XYZ10, 20 * dZ, s_epsilon);
0201
0202 auto bounds_XYZ10 =
0203 dynamic_cast<const RectangleBounds *>(&(plane_XYZ10->bounds()));
0204 double maxX10 = bounds_XYZ10->get(RectangleBounds::eMaxX);
0205 double minX10 = bounds_XYZ10->get(RectangleBounds::eMinX);
0206 double maxY10 = bounds_XYZ10->get(RectangleBounds::eMaxY);
0207 double minY10 = bounds_XYZ10->get(RectangleBounds::eMinY);
0208 CHECK_CLOSE_ABS(maxX10 - minX10, 20 * dX, s_epsilon);
0209 CHECK_CLOSE_ABS(maxY10 - minY10, 20 * dY, s_epsilon);
0210
0211 objVis.write("TGeoConversion_TGeoBBox_PlaneSurface");
0212 }
0213
0214 }