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/Definitions/Tolerance.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Plugins/TGeo/TGeoSurfaceConverter.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Surfaces/SurfaceBounds.hpp"
0018 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0019 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0020 #include "Acts/Visualization/GeometryView3D.hpp"
0021 #include "Acts/Visualization/ObjVisualization3D.hpp"
0022 #include "Acts/Visualization/ViewConfig.hpp"
0023 
0024 #include <algorithm>
0025 #include <cstddef>
0026 #include <memory>
0027 #include <stdexcept>
0028 #include <string>
0029 #include <utility>
0030 #include <vector>
0031 
0032 #include "TGeoManager.h"
0033 #include "TGeoMaterial.h"
0034 #include "TGeoMatrix.h"
0035 #include "TGeoMedium.h"
0036 #include "TGeoTrd1.h"
0037 #include "TGeoVolume.h"
0038 #include "TView.h"
0039 
0040 namespace Acts::Test {
0041 
0042 GeometryContext tgContext = GeometryContext();
0043 
0044 ViewConfig red({200, 0, 0});
0045 ViewConfig green({0, 200, 0});
0046 ViewConfig blue({0, 0, 200});
0047 
0048 /// @brief Unit test to convert a TGeoTrd1 into a Plane
0049 ///
0050 /// * The TGeoTrd1 can only have (x/X)(z/Z) orientation
0051 BOOST_AUTO_TEST_CASE(TGeoTrd1_to_PlaneSurface) {
0052   ObjVisualization3D objVis;
0053 
0054   double hxmin = 10.;
0055   double hxmax = 30.;
0056   double ht = 1.;  // half thickness
0057   double hy = 40.;
0058 
0059   new TGeoManager("trd1", "poza9");
0060   TGeoMaterial *mat = new TGeoMaterial("Al", 26.98, 13, 2.7);
0061   TGeoMedium *med = new TGeoMedium("MED", 1, mat);
0062   TGeoVolume *top = gGeoManager->MakeBox("TOP", med, 100, 100, 100);
0063   gGeoManager->SetTopVolume(top);
0064   TGeoVolume *vol = gGeoManager->MakeTrd1("Trd1", med, hxmin, hxmax, ht, hy);
0065   gGeoManager->CloseGeometry();
0066 
0067   // Check the 4 possible ways
0068   std::vector<std::string> allowedAxes = {"XZ*", "xZ*", "xz*", "Xz*"};
0069 
0070   std::size_t itrd = 0;
0071   for (const auto &axes : allowedAxes) {
0072     auto [plane, thickness] = TGeoSurfaceConverter::toSurface(
0073         *vol->GetShape(), *gGeoIdentity, axes, 1);
0074     BOOST_REQUIRE_NE(plane, nullptr);
0075     BOOST_CHECK_EQUAL(plane->type(), Surface::Plane);
0076     CHECK_CLOSE_ABS(thickness, 2 * ht, s_epsilon);
0077 
0078     auto bounds = dynamic_cast<const TrapezoidBounds *>(&(plane->bounds()));
0079     BOOST_REQUIRE_NE(bounds, nullptr);
0080     double hXminY = bounds->get(TrapezoidBounds::eHalfLengthXnegY);
0081     double hXmaxY = bounds->get(TrapezoidBounds::eHalfLengthXposY);
0082     double hY = bounds->get(TrapezoidBounds::eHalfLengthY);
0083 
0084     CHECK_CLOSE_ABS(hxmin, std::min(hXminY, hXmaxY), s_epsilon);
0085     CHECK_CLOSE_ABS(hxmax, std::max(hXminY, hXmaxY), s_epsilon);
0086     CHECK_CLOSE_ABS(hy, hY, s_epsilon);
0087 
0088     // Check if the surface is the (negative) identity
0089     auto transform = plane->transform(tgContext);
0090     auto rotation = transform.rotation();
0091     const Vector3 offset{(-5.5 + (itrd++) * 2.5) * hxmax, 0., 0.};
0092     GeometryView3D::drawSurface(objVis, *plane, tgContext,
0093                                 Translation3{offset} * Transform3::Identity());
0094     const Vector3 center = plane->center(tgContext) + offset;
0095     GeometryView3D::drawArrowForward(
0096         objVis, center, center + 1.2 * (hXminY + hXmaxY) * rotation.col(0), 4.,
0097         2.5, red);
0098     GeometryView3D::drawArrowForward(
0099         objVis, center, center + 1.2 * hY * rotation.col(1), 4., 2.5, green);
0100     GeometryView3D::drawArrowForward(
0101         objVis, center, center + 2 * rotation.col(2), 4., 2.5, blue);
0102   }
0103 
0104   // Check exceptions for not allowed axis definition
0105   std::vector<std::string> notAllowed = {"XY*", "YZ*", "ZX*", "ZY*"};
0106   for (const auto &naxis : notAllowed) {
0107     BOOST_CHECK_THROW(TGeoSurfaceConverter::toSurface(*vol->GetShape(),
0108                                                       *gGeoIdentity, naxis, 1),
0109                       std::invalid_argument);
0110   }
0111   objVis.write("TGeoConversion_TGeoTrd1_PlaneSurface");
0112 }
0113 
0114 }  // namespace Acts::Test