Back to home page

EIC code displayed by LXR

 
 

    


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

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