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/Geometry/GeometryContext.hpp"
0012 #include "Acts/Plugins/GeoModel/GeoModelConverters.hpp"
0013 #include "Acts/Surfaces/RectangleBounds.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0017 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0018 
0019 #include <GeoModelKernel/GeoBox.h>
0020 #include <GeoModelKernel/GeoFullPhysVol.h>
0021 #include <GeoModelKernel/GeoLogVol.h>
0022 #include <GeoModelKernel/GeoMaterial.h>
0023 #include <GeoModelKernel/GeoTrap.h>
0024 #include <GeoModelKernel/GeoTrd.h>
0025 #include <GeoModelKernel/GeoVPhysVol.h>
0026 
0027 Acts::GeometryContext tContext;
0028 Acts::RotationMatrix3 idRotation = Acts::RotationMatrix3::Identity();
0029 Acts::Transform3 idTransform = Acts::Transform3::Identity();
0030 
0031 BOOST_AUTO_TEST_SUITE(GeoModelPlugin)
0032 
0033 // GeoBox conversion test case
0034 BOOST_AUTO_TEST_CASE(GeoBoxToSensitiveConversion) {
0035   auto material = make_intrusive<GeoMaterial>("Material", 1.0);
0036   // Let's create a GeoFullPhysVol object
0037 
0038   // (BOX object) - XY
0039   auto boxXY = new GeoBox(100, 200, 2);
0040   auto logXY = new GeoLogVol("LogVolumeXY", boxXY, material);
0041   auto fphysXY = make_intrusive<GeoFullPhysVol>(logXY);
0042 
0043   PVConstLink physXY{make_intrusive<GeoFullPhysVol>(logXY)};
0044 
0045   auto converted = Acts::GeoBoxConverter{}.toSensitiveSurface(
0046       physXY, Acts::Transform3::Identity());
0047 
0048   BOOST_CHECK(converted.ok());
0049 
0050   auto [elementXY, surfaceXY] = converted.value();
0051 
0052   BOOST_CHECK(surfaceXY->type() == Acts::Surface::SurfaceType::Plane);
0053 
0054   // Check the bounds
0055   const Acts::RectangleBounds* rBoundsXY =
0056       dynamic_cast<const Acts::RectangleBounds*>(&(surfaceXY->bounds()));
0057   BOOST_CHECK(rBoundsXY != nullptr);
0058   CHECK_CLOSE_ABS(rBoundsXY->halfLengthX(), 100, 1e-6);
0059   CHECK_CLOSE_ABS(rBoundsXY->halfLengthY(), 200, 1e-6);
0060 
0061   // Check the transform -> should be identity transform
0062   const Acts::Transform3& transformXY = surfaceXY->transform(tContext);
0063   BOOST_CHECK(transformXY.isApprox(idTransform));
0064 
0065   // (BOX object) - YZ
0066   auto boxYZ = new GeoBox(2, 200, 300);
0067   auto logYZ = new GeoLogVol("LogVolumeYZ", boxYZ, material);
0068   auto fphysYZ = make_intrusive<GeoFullPhysVol>(logYZ);
0069 
0070   converted = Acts::GeoBoxConverter{}.toSensitiveSurface(
0071       fphysYZ, Acts::Transform3::Identity());
0072 
0073   BOOST_CHECK(converted.ok());
0074 
0075   auto [elementYZ, surfaceYZ] = converted.value();
0076 
0077   BOOST_CHECK(surfaceYZ->type() == Acts::Surface::SurfaceType::Plane);
0078   const Acts::RectangleBounds* rBoundsYZ =
0079       dynamic_cast<const Acts::RectangleBounds*>(&(surfaceYZ->bounds()));
0080   BOOST_CHECK(rBoundsYZ != nullptr);
0081   CHECK_CLOSE_ABS(rBoundsYZ->halfLengthX(), 200, 1e-6);
0082   CHECK_CLOSE_ABS(rBoundsYZ->halfLengthY(), 300, 1e-6);
0083 
0084   // Check the transform -> should be cyclic permutation of the identity
0085   const Acts::Transform3& transformYZ = surfaceYZ->transform(tContext);
0086 
0087   Acts::RotationMatrix3 rotationYZ = transformYZ.rotation();
0088   BOOST_CHECK(rotationYZ.col(0).isApprox(idRotation.col(1)));
0089   BOOST_CHECK(rotationYZ.col(1).isApprox(idRotation.col(2)));
0090   BOOST_CHECK(rotationYZ.col(2).isApprox(idRotation.col(0)));
0091 
0092   // (BOX object) - XZ
0093   auto boxXZ = new GeoBox(400, 2, 300);
0094   auto logXZ = new GeoLogVol("LogVolumeXZ", boxXZ, material);
0095   auto fphysXZ = make_intrusive<GeoFullPhysVol>(logXZ);
0096 
0097   converted = Acts::GeoBoxConverter{}.toSensitiveSurface(
0098       fphysXZ, Acts::Transform3::Identity());
0099 
0100   BOOST_CHECK(converted.ok());
0101 
0102   auto [elementXZ, surfaceXZ] = converted.value();
0103 
0104   BOOST_CHECK(surfaceXZ->type() == Acts::Surface::SurfaceType::Plane);
0105 
0106   // Check the bounds
0107   const Acts::RectangleBounds* rBoundsXZ =
0108       dynamic_cast<const Acts::RectangleBounds*>(&(surfaceXZ->bounds()));
0109 
0110   BOOST_CHECK(rBoundsXZ != nullptr);
0111   CHECK_CLOSE_ABS(rBoundsXZ->halfLengthX(), 300, 1e-6);
0112   CHECK_CLOSE_ABS(rBoundsXZ->halfLengthY(), 400, 1e-6);
0113 
0114   // Check the transform -> should be cyclic permutation of the identity
0115   const Acts::Transform3& transformXZ = surfaceXZ->transform(tContext);
0116 
0117   Acts::RotationMatrix3 rotationXZ = transformXZ.rotation();
0118   BOOST_CHECK(rotationXZ.col(0).isApprox(idRotation.col(2)));
0119   BOOST_CHECK(rotationXZ.col(1).isApprox(idRotation.col(0)));
0120   BOOST_CHECK(rotationXZ.col(2).isApprox(idRotation.col(1)));
0121 }
0122 
0123 BOOST_AUTO_TEST_SUITE_END()