Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:14:17

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/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/CylinderBounds.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <numbers>
0021 #include <stdexcept>
0022 #include <vector>
0023 
0024 namespace Acts::Test {
0025 
0026 BOOST_AUTO_TEST_SUITE(Surfaces)
0027 /// Unit test for creating compliant/non-compliant CylinderBounds object
0028 
0029 BOOST_AUTO_TEST_CASE(CylinderBoundsConstruction) {
0030   /// Test default construction
0031   // default construction is deleted
0032 
0033   const double radius = 0.5;
0034   const double halfZ = 10.;
0035   const double halfPhi = std::numbers::pi / 2.;
0036   const double averagePhi = std::numbers::pi / 2.;
0037   const double bevelMinZ = -std::numbers::pi / 4.;
0038   const double bevelMaxZ = std::numbers::pi / 6.;
0039 
0040   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfZ).type(),
0041                     SurfaceBounds::eCylinder);
0042   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfZ, halfPhi).type(),
0043                     SurfaceBounds::eCylinder);
0044   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfZ, halfPhi, averagePhi).type(),
0045                     SurfaceBounds::eCylinder);
0046   BOOST_CHECK_EQUAL(
0047       CylinderBounds(radius, halfZ, std::numbers::pi, 0., bevelMinZ).type(),
0048       SurfaceBounds::eCylinder);
0049   BOOST_CHECK_EQUAL(
0050       CylinderBounds(radius, halfZ, std::numbers::pi, 0., bevelMinZ, bevelMaxZ)
0051           .type(),
0052       SurfaceBounds::eCylinder);
0053 
0054   /// Test copy construction;
0055   CylinderBounds cylinderBounds(radius, halfZ);
0056   CylinderBounds copyConstructedCylinderBounds(cylinderBounds);
0057   BOOST_CHECK_EQUAL(copyConstructedCylinderBounds, cylinderBounds);
0058 }
0059 
0060 BOOST_AUTO_TEST_CASE(CylinderBoundsRecreation) {
0061   const double radius = 0.5;
0062   const double halfZ = 10.;
0063 
0064   // Test construction with radii and default sector
0065   auto original = CylinderBounds(radius, halfZ);
0066   auto valvector = original.values();
0067   std::array<double, CylinderBounds::eSize> values{};
0068   std::copy_n(valvector.begin(), CylinderBounds::eSize, values.begin());
0069   CylinderBounds recreated(values);
0070   BOOST_CHECK_EQUAL(original, recreated);
0071 }
0072 
0073 BOOST_AUTO_TEST_CASE(CylinderBoundsException) {
0074   const double radius = 0.5;
0075   const double halfZ = 10.;
0076   const double halfPhi = std::numbers::pi / 2.;
0077   const double averagePhi = std::numbers::pi / 2.;
0078 
0079   /// Negative radius
0080   BOOST_CHECK_THROW(CylinderBounds(-radius, halfZ, halfPhi, averagePhi),
0081                     std::logic_error);
0082 
0083   /// Negative half length in z
0084   BOOST_CHECK_THROW(CylinderBounds(radius, -halfZ, halfPhi, averagePhi),
0085                     std::logic_error);
0086 
0087   /// Negative half sector in phi
0088   BOOST_CHECK_THROW(CylinderBounds(radius, halfZ, -halfPhi, averagePhi),
0089                     std::logic_error);
0090 
0091   /// Half sector in phi out of bounds
0092   BOOST_CHECK_THROW(CylinderBounds(radius, halfZ, 4., averagePhi),
0093                     std::logic_error);
0094 
0095   /// Phi position out of bounds
0096   BOOST_CHECK_THROW(CylinderBounds(radius, halfZ, halfPhi, 4.),
0097                     std::logic_error);
0098 }
0099 
0100 /// Unit tests for CylinderBounds properties
0101 BOOST_AUTO_TEST_CASE(CylinderBoundsProperties) {
0102   // CylinderBounds object of radius 0.5 and halfZ 20
0103   const double radius = 0.5;
0104   const double halfZ = 20.;                        // != 10.
0105   const double halfPhi = std::numbers::pi / 4.;    // != pi/2
0106   const double averagePhi = 0.;                    // != pi/2
0107   const double bevelMinZ = std::numbers::pi / 4.;  // != -pi/4
0108   const double bevelMaxZ = std::numbers::pi / 6.;
0109 
0110   CylinderBounds cylinderBoundsObject(radius, halfZ);
0111   CylinderBounds cylinderBoundsSegment(radius, halfZ, halfPhi, averagePhi);
0112   CylinderBounds cylinderBoundsBeveledObject(radius, halfZ, std::numbers::pi,
0113                                              0., bevelMinZ, bevelMaxZ);
0114 
0115   /// Test for type()
0116   BOOST_CHECK_EQUAL(cylinderBoundsObject.type(), SurfaceBounds::eCylinder);
0117 
0118   /// Test for inside(), 2D coords are r or phi ,z? : needs clarification
0119   const Vector2 origin{0., 0.};
0120   const Vector2 atPiBy2{std::numbers::pi / 2., 0.};
0121   const Vector2 atPi{std::numbers::pi, 0.};
0122   const Vector2 beyondEnd{0, 30.};
0123   const Vector2 unitZ{0., 1.};
0124   const Vector2 unitPhi{1., 0.};
0125   const Vector2 withinBevelMin{0.5, -20.012};
0126   const Vector2 outsideBevelMin{0.5, -40.};
0127   const BoundaryTolerance tolerance = BoundaryTolerance::AbsoluteEuclidean(0.1);
0128   const BoundaryTolerance lessTolerance =
0129       BoundaryTolerance::AbsoluteEuclidean(0.01);
0130 
0131   BOOST_CHECK(cylinderBoundsObject.inside(atPiBy2, tolerance));
0132   BOOST_CHECK(!cylinderBoundsSegment.inside(unitPhi, tolerance));
0133   BOOST_CHECK(cylinderBoundsObject.inside(origin, tolerance));
0134 
0135   BOOST_CHECK(!cylinderBoundsObject.inside(withinBevelMin, lessTolerance));
0136   BOOST_CHECK(
0137       cylinderBoundsBeveledObject.inside(withinBevelMin, lessTolerance));
0138   BOOST_CHECK(
0139       !cylinderBoundsBeveledObject.inside(outsideBevelMin, lessTolerance));
0140 
0141   /// Test for r()
0142   CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eR), radius, 1e-6);
0143 
0144   /// Test for averagePhi
0145   CHECK_CLOSE_OR_SMALL(cylinderBoundsObject.get(CylinderBounds::eAveragePhi),
0146                        averagePhi, 1e-6, 1e-6);
0147 
0148   /// Test for halfPhiSector
0149   CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
0150                   halfPhi,
0151                   1e-6);  // fail
0152 
0153   /// Test for halflengthZ (NOTE: Naming violation)
0154   CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ), halfZ,
0155                   1e-6);
0156 
0157   /// Test for bevelMinZ/MaxZ
0158   CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMinZ),
0159                   bevelMinZ, 1e-6);
0160   CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMaxZ),
0161                   bevelMaxZ, 1e-6);
0162 
0163   /// Test for dump
0164   boost::test_tools::output_test_stream dumpOutput;
0165   cylinderBoundsObject.toStream(dumpOutput);
0166   BOOST_CHECK(dumpOutput.is_equal(
0167       "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
0168       "averagePhi, bevelMinZ, bevelMaxZ) = (0.5000000, 20.0000000, 3.1415927, "
0169       "0.0000000, 0.0000000, 0.0000000)"));
0170 }
0171 
0172 /// Unit test for testing CylinderBounds assignment
0173 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
0174   const double radius = 0.5;
0175   const double halfZ = 20.;  // != 10.
0176 
0177   CylinderBounds cylinderBoundsObject(radius, halfZ);
0178   CylinderBounds assignedCylinderBounds(10.5, 6.6);
0179   assignedCylinderBounds = cylinderBoundsObject;
0180 
0181   BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
0182                     cylinderBoundsObject.get(CylinderBounds::eR));
0183   BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
0184 }
0185 
0186 BOOST_AUTO_TEST_CASE(CylinderBoundsCenter) {
0187   const double radius = 5.0;
0188   const double halfZ = 10.0;
0189 
0190   // Test full cylinder
0191   CylinderBounds fullCylinder(radius, halfZ);
0192   Vector2 center = fullCylinder.center();
0193   CHECK_CLOSE_ABS(center, Vector2(0., 0.), 1e-6);
0194 
0195   // Test cylinder with average phi offset
0196   const double averagePhi = std::numbers::pi / 4.;
0197   CylinderBounds offsetCylinder(radius, halfZ, std::numbers::pi, averagePhi);
0198   Vector2 centerOffset = offsetCylinder.center();
0199   CHECK_CLOSE_ABS(centerOffset, Vector2(averagePhi, 0.), 1e-6);
0200 }
0201 
0202 BOOST_AUTO_TEST_SUITE_END()
0203 
0204 }  // namespace Acts::Test