Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:36

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