Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:13

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