Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:12:34

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/Surface.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0016 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0017 
0018 #include <GeoModelKernel/GeoFullPhysVol.h>
0019 #include <GeoModelKernel/GeoLogVol.h>
0020 #include <GeoModelKernel/GeoMaterial.h>
0021 #include <GeoModelKernel/GeoTrd.h>
0022 
0023 Acts::GeometryContext tContext;
0024 Acts::RotationMatrix3 idRotation = Acts::RotationMatrix3::Identity();
0025 Acts::Transform3 idTransform = Acts::Transform3::Identity();
0026 
0027 BOOST_AUTO_TEST_SUITE(GeoModelPlugin)
0028 
0029 // GeoBox conversion test case
0030 BOOST_AUTO_TEST_CASE(GeoTrfToSensitiveConversion) {
0031   auto material = make_intrusive<GeoMaterial>("Material", 1.0);
0032   // Let's create a GeoFullPhysVol object
0033 
0034   // (Trapezoid object) - YZ
0035   //  GeoTrd (double XHalfLength1, double XHalfLength2, double YHalfLength1,
0036   //  double YHalfLength2, double ZHalfLength);
0037   auto trapYZ = make_intrusive<GeoTrd>(2, 2, 50, 80, 60);
0038   auto logYZ = make_intrusive<GeoLogVol>("LogVolumeYZ", trapYZ, material);
0039   auto fphysYZ = make_intrusive<GeoFullPhysVol>(logYZ);
0040 
0041   PVConstLink physYZ{make_intrusive<GeoFullPhysVol>(logYZ)};
0042 
0043   Acts::SurfaceBoundFactory boundFactory{};
0044   auto converted = Acts::GeoTrdConverter{}.toSensitiveSurface(
0045       physYZ, idTransform, boundFactory);
0046 
0047   BOOST_CHECK(converted.ok());
0048 
0049   auto [elementYZ, surfaceYZ] = converted.value();
0050 
0051   // Check the bounds
0052   const Acts::TrapezoidBounds* tBoundsYZ =
0053       dynamic_cast<const Acts::TrapezoidBounds*>(&(surfaceYZ->bounds()));
0054 
0055   BOOST_CHECK(tBoundsYZ != nullptr);
0056   CHECK_CLOSE_ABS(
0057       tBoundsYZ->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXnegY), 50,
0058       1e-6);
0059   CHECK_CLOSE_ABS(
0060       tBoundsYZ->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXposY), 80,
0061       1e-6);
0062   CHECK_CLOSE_ABS(
0063       tBoundsYZ->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthY), 60,
0064       1e-6);
0065 
0066   // Check the transform -> should be cyclic permutation of the identity
0067   const Acts::Transform3& transformYZ = surfaceYZ->transform(tContext);
0068 
0069   Acts::RotationMatrix3 rotationYZ = transformYZ.rotation();
0070   BOOST_CHECK(rotationYZ.col(0).isApprox(idRotation.col(1)));
0071   BOOST_CHECK(rotationYZ.col(1).isApprox(idRotation.col(2)));
0072   BOOST_CHECK(rotationYZ.col(2).isApprox(idRotation.col(0)));
0073 
0074   // (Trapezoid object) - YZ swapped
0075   //  GeoTrd (double XHalfLength1, double XHalfLength2, double YHalfLength1,
0076   //  double YHalfLength2, double ZHalfLength);
0077   auto trapYZs = make_intrusive<GeoTrd>(2, 2, 80, 50, 60);
0078   auto logYZs = make_intrusive<GeoLogVol>("LogVolumeYZs", trapYZs, material);
0079   auto fphysYZs = make_intrusive<GeoFullPhysVol>(logYZs);
0080 
0081   converted = Acts::GeoTrdConverter{}.toSensitiveSurface(fphysYZs, idTransform,
0082                                                          boundFactory);
0083 
0084   BOOST_CHECK(converted.ok());
0085 
0086   auto [elementYZs, surfaceYZs] = converted.value();
0087 
0088   // Check the bounds
0089   const Acts::TrapezoidBounds* tBoundsYZs =
0090       dynamic_cast<const Acts::TrapezoidBounds*>(&(surfaceYZs->bounds()));
0091 
0092   BOOST_CHECK(tBoundsYZs != nullptr);
0093   CHECK_CLOSE_ABS(
0094       tBoundsYZs->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXnegY), 50,
0095       1e-6);
0096   CHECK_CLOSE_ABS(
0097       tBoundsYZs->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXposY), 80,
0098       1e-6);
0099   CHECK_CLOSE_ABS(
0100       tBoundsYZs->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthY), 60,
0101       1e-6);
0102 
0103   // Check the transform -> should be cyclic permutation of the identity
0104   const Acts::Transform3& transformYZs = surfaceYZs->transform(tContext);
0105 
0106   Acts::RotationMatrix3 rotationYZs = transformYZs.rotation();
0107   BOOST_CHECK(rotationYZs.col(0).isApprox(idRotation.col(1)));
0108   BOOST_CHECK(rotationYZs.col(1).isApprox(-idRotation.col(2)));
0109   BOOST_CHECK(rotationYZs.col(2).isApprox(-idRotation.col(0)));
0110 
0111   // (Trapezoid object) - XZ
0112   auto trapXZ = make_intrusive<GeoTrd>(50, 80, 2, 2, 60);
0113   auto logXZ = make_intrusive<GeoLogVol>("LogVolumeXZ", trapXZ, material);
0114   auto fphysXZ = make_intrusive<GeoFullPhysVol>(logXZ);
0115 
0116   converted = Acts::GeoTrdConverter{}.toSensitiveSurface(fphysXZ, idTransform,
0117                                                          boundFactory);
0118 
0119   BOOST_CHECK(converted.ok());
0120 
0121   auto [elementXZ, surfaceXZ] = converted.value();
0122 
0123   // Check the bounds
0124   const Acts::TrapezoidBounds* tBoundsXZ =
0125       dynamic_cast<const Acts::TrapezoidBounds*>(&(surfaceXZ->bounds()));
0126 
0127   BOOST_CHECK(tBoundsXZ != nullptr);
0128   CHECK_CLOSE_ABS(
0129       tBoundsXZ->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXnegY), 50,
0130       1e-6);
0131   CHECK_CLOSE_ABS(
0132       tBoundsXZ->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXposY), 80,
0133       1e-6);
0134   CHECK_CLOSE_ABS(
0135       tBoundsXZ->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthY), 60,
0136       1e-6);
0137 
0138   // Check the transform -> cyclic permuttation not possible
0139   const Acts::Transform3& transformXZ = surfaceXZ->transform(tContext);
0140 
0141   Acts::RotationMatrix3 rotationXZ = transformXZ.rotation();
0142   BOOST_CHECK(rotationXZ.col(0).isApprox(idRotation.col(0)));
0143   BOOST_CHECK(rotationXZ.col(1).isApprox(idRotation.col(2)));
0144   BOOST_CHECK(rotationXZ.col(2).isApprox(-1 * idRotation.col(1)));
0145 
0146   // (Trapezoid object) - XZs (swapped)
0147   auto trapXZs = make_intrusive<GeoTrd>(80, 50, 2, 2, 60);
0148   auto logXZs = make_intrusive<GeoLogVol>("LogVolumeXZs", trapXZs, material);
0149   auto fphysXZs = make_intrusive<GeoFullPhysVol>(logXZs);
0150 
0151   PVConstLink physXZs{make_intrusive<GeoFullPhysVol>(logXZs)};
0152 
0153   converted = Acts::GeoTrdConverter{}.toSensitiveSurface(physXZs, idTransform,
0154                                                          boundFactory);
0155 
0156   BOOST_CHECK(converted.ok());
0157 
0158   auto [elementXZs, surfaceXZs] = converted.value();
0159 
0160   // Check the bounds
0161   const Acts::TrapezoidBounds* tBoundsXZs =
0162       dynamic_cast<const Acts::TrapezoidBounds*>(&(surfaceXZs->bounds()));
0163 
0164   BOOST_CHECK(tBoundsXZs != nullptr);
0165   CHECK_CLOSE_ABS(
0166       tBoundsXZs->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXnegY), 50,
0167       1e-6);
0168   CHECK_CLOSE_ABS(
0169       tBoundsXZs->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthXposY), 80,
0170       1e-6);
0171   CHECK_CLOSE_ABS(
0172       tBoundsXZs->get(Acts::TrapezoidBounds::BoundValues::eHalfLengthY), 60,
0173       1e-6);
0174 
0175   // Check the transform -> cyclic permuttation not possible
0176   const Acts::Transform3& transformXZs = surfaceXZs->transform(tContext);
0177 
0178   Acts::RotationMatrix3 rotationXZs = transformXZs.rotation();
0179   BOOST_CHECK(rotationXZs.col(0).isApprox(idRotation.col(0)));
0180   BOOST_CHECK(rotationXZs.col(1).isApprox(-idRotation.col(2)));
0181   BOOST_CHECK(rotationXZs.col(2).isApprox(idRotation.col(1)));
0182 
0183   // Double - trazoid -> throw exception
0184   auto trapDouble = make_intrusive<GeoTrd>(50, 80, 50, 80, 60);
0185   auto logDouble =
0186       make_intrusive<GeoLogVol>("LogVolumeDouble", trapDouble, material);
0187   auto fphysDouble = make_intrusive<GeoFullPhysVol>(logDouble);
0188 
0189   BOOST_CHECK_THROW(Acts::GeoTrdConverter{}.toSensitiveSurface(
0190                         fphysDouble, idTransform, boundFactory),
0191                     std::invalid_argument);
0192 }
0193 
0194 BOOST_AUTO_TEST_SUITE_END()