Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:50

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 =
0128       BoundaryTolerance::AbsoluteBound(0.1, 0.1);
0129   const BoundaryTolerance lessTolerance =
0130       BoundaryTolerance::AbsoluteBound(0.01, 0.01);
0131 
0132   BOOST_CHECK(cylinderBoundsObject.inside(atPiBy2, tolerance));
0133   BOOST_CHECK(!cylinderBoundsSegment.inside(unitPhi, tolerance));
0134   BOOST_CHECK(cylinderBoundsObject.inside(origin, tolerance));
0135 
0136   BOOST_CHECK(!cylinderBoundsObject.inside(withinBevelMin, lessTolerance));
0137   BOOST_CHECK(
0138       cylinderBoundsBeveledObject.inside(withinBevelMin, lessTolerance));
0139   BOOST_CHECK(
0140       !cylinderBoundsBeveledObject.inside(outsideBevelMin, lessTolerance));
0141 
0142   /// Test for r()
0143   CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eR), radius, 1e-6);
0144 
0145   /// Test for averagePhi
0146   CHECK_CLOSE_OR_SMALL(cylinderBoundsObject.get(CylinderBounds::eAveragePhi),
0147                        averagePhi, 1e-6, 1e-6);
0148 
0149   /// Test for halfPhiSector
0150   CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
0151                   halfPhi,
0152                   1e-6);  // fail
0153 
0154   /// Test for halflengthZ (NOTE: Naming violation)
0155   CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ), halfZ,
0156                   1e-6);
0157 
0158   /// Test for bevelMinZ/MaxZ
0159   CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMinZ),
0160                   bevelMinZ, 1e-6);
0161   CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMaxZ),
0162                   bevelMaxZ, 1e-6);
0163 
0164   /// Test for dump
0165   boost::test_tools::output_test_stream dumpOutput;
0166   cylinderBoundsObject.toStream(dumpOutput);
0167   BOOST_CHECK(dumpOutput.is_equal(
0168       "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
0169       "averagePhi, bevelMinZ, bevelMaxZ) = (0.5000000, 20.0000000, 3.1415927, "
0170       "0.0000000, 0.0000000, 0.0000000)"));
0171 }
0172 
0173 /// Unit test for testing CylinderBounds assignment
0174 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
0175   const double radius = 0.5;
0176   const double halfZ = 20.;  // != 10.
0177 
0178   CylinderBounds cylinderBoundsObject(radius, halfZ);
0179   CylinderBounds assignedCylinderBounds(10.5, 6.6);
0180   assignedCylinderBounds = cylinderBoundsObject;
0181 
0182   BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
0183                     cylinderBoundsObject.get(CylinderBounds::eR));
0184   BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
0185 }
0186 
0187 BOOST_AUTO_TEST_SUITE_END()
0188 
0189 }  // namespace Acts::Test