Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:45

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020-2023 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Plugins/TGeo/TGeoSurfaceConverter.hpp"
0015 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Surfaces/SurfaceBounds.hpp"
0018 #include "Acts/Visualization/GeometryView3D.hpp"
0019 #include "Acts/Visualization/ObjVisualization3D.hpp"
0020 #include "Acts/Visualization/ViewConfig.hpp"
0021 
0022 #include <cstddef>
0023 #include <memory>
0024 #include <stdexcept>
0025 #include <string>
0026 #include <vector>
0027 
0028 #include "TGeoArb8.h"
0029 #include "TGeoManager.h"
0030 #include "TGeoMaterial.h"
0031 #include "TGeoMatrix.h"
0032 #include "TGeoMedium.h"
0033 #include "TGeoVolume.h"
0034 #include "TView.h"
0035 
0036 namespace Acts::Test {
0037 
0038 GeometryContext tgContext = GeometryContext();
0039 
0040 ViewConfig red({200, 0, 0});
0041 ViewConfig green({0, 200, 0});
0042 ViewConfig blue({0, 0, 200});
0043 
0044 /// @brief Unit test to convert a TGeoTrd2 into a Plane
0045 ///
0046 /// * The TGeoTrd2 has x/z orientation
0047 BOOST_AUTO_TEST_CASE(TGeoArb8_to_PlaneSurface) {
0048   ObjVisualization3D objVis;
0049 
0050   new TGeoManager("arb8", "poza12");
0051   TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
0052   TGeoMedium *med = new TGeoMedium("MED", 1, mat);
0053   TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
0054   gGeoManager->SetTopVolume(top);
0055   // The one parameter at construction is dZ, when the
0056   // TGeoArb8 is spanning from -dZ to +dZ:
0057   // - hence, the thickness is 2 * dZ
0058   ActsScalar dZ = 1.;
0059   TGeoArb8 *arb = new TGeoArb8(dZ);
0060   arb->SetVertex(0, -30, -25);
0061   arb->SetVertex(1, -25, 25);
0062   arb->SetVertex(2, 5, 25);
0063   arb->SetVertex(3, 25, -25);
0064   arb->SetVertex(4, -30, -25);
0065   arb->SetVertex(5, -25, 25);
0066   arb->SetVertex(6, 5, 25);
0067   arb->SetVertex(7, 25, -25);
0068   TGeoVolume *vol = new TGeoVolume("ARB8", arb, med);
0069   top->AddNode(vol, 1);
0070   gGeoManager->CloseGeometry();
0071 
0072   // Check the 4 possible ways
0073   std::vector<std::string> allowedAxes = {"XY*", "xy*", "Xy*", "xY*",
0074                                           "YX*", "yx*", "Yx*", "yX*"};
0075 
0076   std::size_t iarb8 = 0;
0077   for (const auto &axes : allowedAxes) {
0078     auto [plane, thickness] = TGeoSurfaceConverter::toSurface(
0079         *vol->GetShape(), *gGeoIdentity, axes, 1);
0080     BOOST_REQUIRE_NE(plane, nullptr);
0081     BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
0082     BOOST_CHECK_EQUAL(thickness, dZ * 2.);
0083 
0084     auto bounds =
0085         dynamic_cast<const ConvexPolygonBounds<4> *>(&(plane->bounds()));
0086     BOOST_CHECK_NE(bounds, nullptr);
0087 
0088     // Check if the surface is the (negative) identity
0089     auto transform = plane->transform(tgContext);
0090     auto rotation = transform.rotation();
0091     GeometryView3D::drawSurface(objVis, *plane, tgContext);
0092     const Vector3 center = plane->center(tgContext);
0093     GeometryView3D::drawArrowForward(
0094         objVis, center, center + 30 * rotation.col(0), 4., 2.5, red);
0095     GeometryView3D::drawArrowForward(
0096         objVis, center, center + 30 * rotation.col(1), 4., 2.5, green);
0097     GeometryView3D::drawArrowForward(
0098         objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
0099 
0100     objVis.write("TGeoConversion_TGeoArb8_PlaneSurface_" +
0101                  std::to_string(iarb8++));
0102     objVis.clear();
0103   }
0104 
0105   // Check exceptions for not allowed axis definition
0106   std::vector<std::string> notAllowed = {
0107       "XZ*", "xz*", "xZ*", "Xz*", "ZX*", "zx*", "zX*", "Zx*",
0108       "YZ*", "yz*", "yZ*", "Yz*", "ZY*", "zy*", "Zy*", "zY*"};
0109   for (const auto &naxis : notAllowed) {
0110     BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
0111                                                       *gGeoIdentity, naxis, 1),
0112                       std::invalid_argument);
0113   }
0114 }
0115 
0116 }  // namespace Acts::Test