File indexing completed on 2026-07-16 08:09:05
0001
0002
0003
0004
0005
0006
0007
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/GeoTrd.h>
0030 #include <GeoModelKernel/GeoTube.h>
0031
0032 using namespace Acts;
0033 using namespace ActsPlugins;
0034
0035 namespace ActsTests {
0036
0037 BOOST_AUTO_TEST_SUITE(GeoModelSuite)
0038
0039 struct GeoDims {
0040 std::vector<double> boxO;
0041 std::vector<double> boxI;
0042 std::vector<double> tube;
0043 std::vector<std::vector<double>> trapVerts;
0044 std::vector<double> trapHls;
0045 std::vector<std::vector<double>> polyVerts;
0046 };
0047
0048 void test(const GeoModelDetectorObjectFactory::Cache& cache, GeoDims geoDims) {
0049 for (const auto& convertedObj : cache.volumeBoxFPVs) {
0050 const auto& box = convertedObj.volume;
0051 const VolumeBounds& bounds = box->volumeBounds();
0052 for (std::size_t i = 0; i < geoDims.boxO.size(); i++) {
0053 BOOST_CHECK(geoDims.boxO[i] == bounds.values()[i]);
0054 }
0055 for (const auto& surface : convertedObj.surfaces) {
0056 const SurfaceBounds& sbounds = surface->bounds();
0057
0058 if (surface->type() == Surface::SurfaceType::Straw) {
0059 const auto* lineBounds = dynamic_cast<const LineBounds*>(&sbounds);
0060 BOOST_CHECK(geoDims.tube[1] == lineBounds->get(LineBounds::eR));
0061 BOOST_CHECK(geoDims.tube[2] ==
0062 lineBounds->get(LineBounds::eHalfLengthZ));
0063 }
0064
0065 if (sbounds.type() == SurfaceBounds::eRectangle) {
0066 double csxmin = sbounds.values()[0];
0067 double csymin = sbounds.values()[1];
0068 double csxmax = sbounds.values()[2];
0069 double csymax = sbounds.values()[3];
0070 BOOST_CHECK(geoDims.boxI[0] == -csxmin);
0071 BOOST_CHECK(geoDims.boxI[1] == -csymin);
0072 BOOST_CHECK(geoDims.boxI[0] == csxmax);
0073 BOOST_CHECK(geoDims.boxI[1] == csymax);
0074 }
0075
0076 if (sbounds.type() == SurfaceBounds::eTrapezoid) {
0077 const auto* trapBounds = dynamic_cast<const TrapezoidBounds*>(&sbounds);
0078 std::vector<Vector2> trapVerts = trapBounds->vertices();
0079
0080 for (std::size_t i = 0; i < trapVerts.size(); i++) {
0081 BOOST_CHECK(trapVerts[i][0] == geoDims.trapVerts[i][0]);
0082 BOOST_CHECK(trapVerts[i][1] == geoDims.trapVerts[i][1]);
0083 }
0084 }
0085 }
0086 }
0087 }
0088 struct GeoGeometry {
0089 std::vector<GeoIntrusivePtr<GeoFullPhysVol>> fpvs;
0090 GeoDims dim;
0091 };
0092 GeoGeometry constructGeoModel() {
0093
0094 auto material = make_intrusive<GeoMaterial>("Material", 1.0);
0095 auto al = make_intrusive<GeoMaterial>("Aluminium", 1.0);
0096
0097
0098 GeoDims geoDims;
0099 geoDims.boxO = {100, 200, 2};
0100 geoDims.boxI = {100, 150, 1};
0101 geoDims.trapVerts = {{-103, -50}, {103, -50}, {183, 50}, {-183, 50}};
0102 geoDims.polyVerts = {{-60, -50}, {60, -50}, {153, 0},
0103 {123, 50}, {-123, 50}, {-153, 0}};
0104 geoDims.tube = {5, 6, 100};
0105 geoDims.trapHls = {
0106 std::abs(geoDims.trapVerts[0][0] - geoDims.trapVerts[1][0]) / 2,
0107 std::abs(geoDims.trapVerts[2][0] - geoDims.trapVerts[3][0]) / 2,
0108 std::abs(geoDims.trapVerts[0][1] - geoDims.trapVerts[2][1]) / 2};
0109
0110
0111 auto boxXY =
0112 make_intrusive<GeoBox>(geoDims.boxO[0], geoDims.boxO[1], geoDims.boxO[2]);
0113 auto tube = make_intrusive<GeoTube>(geoDims.tube[0], geoDims.tube[1],
0114 geoDims.tube[2]);
0115 auto ssurface =
0116 make_intrusive<GeoBox>(geoDims.boxI[0], geoDims.boxI[1], geoDims.boxI[2]);
0117 auto trd = make_intrusive<GeoTrd>(1, 1, geoDims.trapHls[0],
0118 geoDims.trapHls[1], geoDims.trapHls[2]);
0119
0120
0121 auto logXY = make_intrusive<GeoLogVol>("LogVolumeXY", boxXY, material);
0122 auto logTube = make_intrusive<GeoLogVol>("LogTube", tube, al);
0123 auto logSurface = make_intrusive<GeoLogVol>("LogSurface", ssurface, al);
0124 auto logTrd = make_intrusive<GeoLogVol>("LogTrd", trd, al);
0125
0126
0127 std::vector<GeoIntrusivePtr<GeoFullPhysVol>> fpvs;
0128 fpvs.push_back(make_intrusive<GeoFullPhysVol>(logXY));
0129 fpvs.push_back(make_intrusive<GeoFullPhysVol>(logTube));
0130 fpvs.push_back(make_intrusive<GeoFullPhysVol>(logSurface));
0131 fpvs.push_back(make_intrusive<GeoFullPhysVol>(logTrd));
0132 GeoGeometry ret;
0133 ret.fpvs = fpvs;
0134 ret.dim = geoDims;
0135 return ret;
0136 }
0137
0138 BOOST_AUTO_TEST_CASE(GeoModelDetectorObjectFactoryCase) {
0139 GeoGeometry geom = constructGeoModel();
0140 GeoDims geoDims = geom.dim;
0141 std::vector<GeoIntrusivePtr<GeoFullPhysVol>> fpvs = geom.fpvs;
0142
0143 int index = 0;
0144 GeoFullPhysVol* parentVol = fpvs[index];
0145 fpvs.erase(fpvs.begin() + index);
0146
0147 for (const auto& fpv : fpvs) {
0148 parentVol->add(fpv);
0149 }
0150
0151
0152 GeoModelDetectorObjectFactory::Config gmConfig;
0153 gmConfig.convertBox = {"LogVolumeXY"};
0154 auto gContext = GeometryContext::dangerouslyDefaultConstruct();
0155 GeoModelDetectorObjectFactory::Cache gmCache;
0156
0157
0158 GeoModelDetectorObjectFactory factory(gmConfig);
0159
0160 factory.convertFpv("LogVolumeXY", parentVol, gmCache, gContext);
0161
0162
0163 test(gmCache, geoDims);
0164 }
0165
0166 BOOST_AUTO_TEST_SUITE_END()
0167
0168 }