Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-27 07:57:29

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/Surfaces/CylinderBounds.hpp"
0012 #include "Acts/Surfaces/DiamondBounds.hpp"
0013 #include "Acts/Surfaces/LineBounds.hpp"
0014 #include "Acts/Surfaces/PlaneSurface.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/StrawSurface.hpp"
0017 #include "Acts/Surfaces/Surface.hpp"
0018 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "ActsPlugins/GeoModel/GeoModelDetectorObjectFactory.hpp"
0021 #include "ActsPlugins/GeoModel/GeoModelReader.hpp"
0022 
0023 #include <typeinfo>
0024 
0025 #include <GeoModelKernel/GeoBox.h>
0026 #include <GeoModelKernel/GeoFullPhysVol.h>
0027 #include <GeoModelKernel/GeoLogVol.h>
0028 #include <GeoModelKernel/GeoMaterial.h>
0029 #include <GeoModelKernel/GeoSimplePolygonBrep.h>
0030 #include <GeoModelKernel/GeoTrd.h>
0031 #include <GeoModelKernel/GeoTube.h>
0032 
0033 using namespace Acts;
0034 using namespace ActsPlugins;
0035 
0036 namespace ActsTests {
0037 
0038 BOOST_AUTO_TEST_SUITE(GeoModelSuite)
0039 
0040 BOOST_AUTO_TEST_CASE(GeoModelDetectorObjectFactory) {
0041   auto al = make_intrusive<GeoMaterial>("Aluminium", 1.0);
0042 
0043   std::vector<std::vector<double>> trapVerts = {
0044       {-103, -50}, {103, -50}, {183, 50}, {-183, 50}};
0045   std::vector<std::vector<double>> polyVerts = {
0046       {-60, -50}, {60, -50}, {153, 0}, {123, 50}, {-123, 50}, {-153, 0}};
0047   std::vector<std::vector<double>> errVerts = {
0048       {60, -50}, {153, 0}, {123, 50}, {-123, 50}, {-153, 0}};
0049   double poly_z = 2;
0050 
0051   auto trap = make_intrusive<GeoSimplePolygonBrep>(poly_z);
0052   for (const auto& tVert : trapVerts) {
0053     trap->addVertex(tVert[0], tVert[1]);
0054   }
0055   auto poly = make_intrusive<GeoSimplePolygonBrep>(poly_z);
0056   for (const auto& pVert : polyVerts) {
0057     poly->addVertex(pVert[0], pVert[1]);
0058   }
0059   auto err = make_intrusive<GeoSimplePolygonBrep>(poly_z);
0060   for (const auto& eVert : errVerts) {
0061     err->addVertex(eVert[0], eVert[1]);
0062   }
0063   auto logTrap = make_intrusive<GeoLogVol>("LogTrap", trap, al);
0064   auto logPoly = make_intrusive<GeoLogVol>("LogPoly", poly, al);
0065   auto logErr = make_intrusive<GeoLogVol>("LogErr", err, al);
0066 
0067   auto physTrap = make_intrusive<GeoFullPhysVol>(logTrap);
0068   auto physPoly = make_intrusive<GeoFullPhysVol>(logPoly);
0069   auto physErr = make_intrusive<GeoFullPhysVol>(logErr);
0070   // create pars for conversion
0071   ActsPlugins::GeoModelDetectorObjectFactory::Config gmConfig;
0072   GeometryContext gContext;
0073   ActsPlugins::GeoModelDetectorObjectFactory::Cache trapCache;
0074   ActsPlugins::GeoModelDetectorObjectFactory::Cache polyCache;
0075   ActsPlugins::GeoModelDetectorObjectFactory::Cache errCache;
0076 
0077   // create factory instance
0078   ActsPlugins::GeoModelDetectorObjectFactory factory(gmConfig);
0079 
0080   // convert GeoFullPhysVol (to surfaces)
0081   factory.convertFpv("Trap", physTrap, trapCache, gContext);
0082   factory.convertFpv("Poly", physPoly, polyCache, gContext);
0083   BOOST_CHECK_THROW(factory.convertFpv("Error", physErr, errCache, gContext),
0084                     std::runtime_error);
0085 
0086   ActsPlugins::GeoModelSensitiveSurface trapSensSurface =
0087       trapCache.sensitiveSurfaces[0];
0088   ActsPlugins::GeoModelSensitiveSurface polySensSurface =
0089       polyCache.sensitiveSurfaces[0];
0090   std::shared_ptr<Surface> polySurface = std::get<1>(polySensSurface);
0091   std::shared_ptr<Surface> trapSurface = std::get<1>(trapSensSurface);
0092 
0093   const auto* polyBounds =
0094       dynamic_cast<const DiamondBounds*>(&polySurface->bounds());
0095   std::vector<Vector2> convPolyVerts = polyBounds->vertices();
0096   for (std::size_t i = 0; i < polyVerts.size(); i++) {
0097     BOOST_CHECK(polyVerts[i][0] == convPolyVerts[i][0]);
0098     BOOST_CHECK(polyVerts[i][1] == convPolyVerts[i][1]);
0099   }
0100 
0101   const auto* trapBounds =
0102       dynamic_cast<const TrapezoidBounds*>(&trapSurface->bounds());
0103   std::vector<Vector2> convTrapVerts = trapBounds->vertices();
0104   for (std::size_t i = 0; i < trapVerts.size(); i++) {
0105     BOOST_CHECK(trapVerts[i][0] == convTrapVerts[i][0]);
0106     BOOST_CHECK(trapVerts[i][1] == convTrapVerts[i][1]);
0107   }
0108 }
0109 BOOST_AUTO_TEST_SUITE_END()
0110 
0111 }  // namespace ActsTests