Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-07 09:17:25

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