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