Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-02 08:54:33

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/EllipseBounds.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <cmath>
0021 #include <numbers>
0022 #include <stdexcept>
0023 #include <vector>
0024 
0025 using namespace Acts;
0026 
0027 namespace ActsTests {
0028 
0029 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0030 
0031 const double innerRx = 10.;
0032 const double innerRy = 15.;
0033 const double phiSector = std::numbers::pi / 2.;
0034 const double averagePhi = 0.;
0035 
0036 /// Unit test for creating compliant/non-compliant EllipseBounds object
0037 BOOST_AUTO_TEST_CASE(EllipseBoundsConstruction) {
0038   const double outerRx = 25.;
0039   const double outerRy = 30.;
0040 
0041   /// Test default construction
0042   // default construction is deleted
0043 
0044   /// Test construction with dimensions
0045   BOOST_CHECK_EQUAL(
0046       EllipseBounds(innerRx, innerRy, outerRx, outerRy, phiSector, averagePhi)
0047           .type(),
0048       SurfaceBounds::eEllipse);
0049 
0050   /// Copy constructor
0051   EllipseBounds original(innerRx, innerRy, outerRx, outerRy, phiSector,
0052                          averagePhi);
0053   EllipseBounds copied(original);
0054   BOOST_CHECK_EQUAL(copied, original);
0055 }
0056 
0057 // Streaning and recreation test
0058 BOOST_AUTO_TEST_CASE(EllipseBoundsRecreation) {
0059   const double outerRx = 25.;
0060   const double outerRy = 30.;
0061 
0062   EllipseBounds original(innerRx, innerRy, outerRx, outerRy, phiSector,
0063                          averagePhi);
0064   auto valvector = original.values();
0065   std::array<double, EllipseBounds::eSize> values{};
0066   std::copy_n(valvector.begin(), EllipseBounds::eSize, values.begin());
0067   EllipseBounds recreated(values);
0068   BOOST_CHECK_EQUAL(recreated, original);
0069 }
0070 
0071 // Unit tests for AnnulusBounds exception throwing
0072 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
0073   const double outerRx = 25.;
0074   const double outerRy = 30.;
0075 
0076   // Exception for innerRx < 0
0077   BOOST_CHECK_THROW(
0078       EllipseBounds(-innerRx, innerRy, outerRx, outerRy, phiSector, averagePhi),
0079       std::logic_error);
0080 
0081   // Exception for innerRy < 0
0082   BOOST_CHECK_THROW(
0083       EllipseBounds(innerRx, -innerRy, outerRx, outerRy, phiSector, averagePhi),
0084       std::logic_error);
0085 
0086   // Exception for innerRx < 0 and innerRy < 0
0087   BOOST_CHECK_THROW(EllipseBounds(-innerRx, -innerRy, outerRx, outerRy,
0088                                   phiSector, averagePhi),
0089                     std::logic_error);
0090 
0091   // Exception for opening outerRx <= 0
0092   BOOST_CHECK_THROW(
0093       EllipseBounds(innerRx, innerRy, 0., outerRy, phiSector, averagePhi),
0094       std::logic_error);
0095 
0096   // Exception for opening outerRy <= 0
0097   BOOST_CHECK_THROW(
0098       EllipseBounds(innerRx, innerRy, outerRx, 0., phiSector, averagePhi),
0099       std::logic_error);
0100 
0101   // Exception for iouterRx < 0 and outerRy < 0
0102   BOOST_CHECK_THROW(EllipseBounds(innerRx, innerRy, -outerRx, -outerRy,
0103                                   phiSector, averagePhi),
0104                     std::logic_error);
0105 
0106   // Exception for innerRx > outerRx
0107   BOOST_CHECK_THROW(
0108       EllipseBounds(outerRx, innerRy, innerRx, outerRy, phiSector, averagePhi),
0109       std::logic_error);
0110 
0111   // Exception for innerRxy > outerRy
0112   BOOST_CHECK_THROW(
0113       EllipseBounds(innerRx, outerRy, outerRx, innerRy, phiSector, averagePhi),
0114       std::logic_error);
0115 
0116   // Exception for negative phiSector
0117   BOOST_CHECK_THROW(
0118       EllipseBounds(innerRx, innerRy, outerRx, outerRy, -phiSector, averagePhi),
0119       std::logic_error);
0120 
0121   // Exception for average phi out of bound
0122   BOOST_CHECK_THROW(
0123       EllipseBounds(innerRx, innerRy, outerRx, outerRy, phiSector, 4.),
0124       std::logic_error);
0125 }
0126 
0127 /// Unit tests for EllipseBounds properties
0128 BOOST_AUTO_TEST_CASE(EllipseBoundsProperties) {
0129   const double outerRx = 15.;  // != 25
0130   const double outerRy = 20.;  // != 30
0131 
0132   /// Test clone
0133   EllipseBounds ellipseBoundsObject(innerRx, innerRy, outerRx, outerRy,
0134                                     phiSector, averagePhi);
0135 
0136   /// Test type() (redundant; already used in constructor confirmation)
0137   BOOST_CHECK_EQUAL(ellipseBoundsObject.type(), SurfaceBounds::eEllipse);
0138 
0139   /// Test distanceToBoundary
0140   Vector2 origin{0., 0.};
0141   Vector2 outsideBy15{0., 30.};
0142   Vector2 inRectangle{17., 11.};
0143 
0144   /// Test rMinX
0145   BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRx), innerRx);
0146 
0147   /// Test rMinY
0148   BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRx), outerRx);
0149 
0150   /// Test rMaxX
0151   BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRy), innerRy);
0152 
0153   /// Test rMaxY
0154   BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRy), outerRy);
0155 
0156   /// Test averagePhi
0157   BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eAveragePhi),
0158                     averagePhi);
0159 
0160   /// Test vertices
0161   // std::vector<Vector2> expectedVertices{{15, 0}, {0, 20}, {-15, 0}, {0,
0162   // -20}}; const auto& actualVertices = ellipseBoundsObject.vertices(4);
0163   // BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(),
0164   // actualVertices.cend(), expectedVertices.cbegin(), expectedVertices.cend());
0165 
0166   /// Test boundingBox
0167   BOOST_CHECK_EQUAL(ellipseBoundsObject.boundingBox(),
0168                     RectangleBounds(15., 20.));
0169 
0170   /// Test halfPhiSector
0171   BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eHalfPhiSector),
0172                     std::numbers::pi / 2.);
0173 
0174   /// Test dump
0175   boost::test_tools::output_test_stream dumpOutput;
0176   ellipseBoundsObject.toStream(dumpOutput);
0177   BOOST_CHECK(dumpOutput.is_equal(
0178       "Acts::EllipseBounds:  (innerRadius0, outerRadius0, innerRadius1, "
0179       "outerRadius1, hPhiSector, averagePhi) = (10.0000000, 15.0000000, "
0180       "15.0000000, 20.0000000, 0.0000000, 1.5707963, 0.0000000)"));
0181 
0182   /// Test inside
0183   BOOST_CHECK(
0184       !ellipseBoundsObject.inside(inRectangle, BoundaryTolerance::None()));
0185   // don't understand why this is so:
0186   BOOST_CHECK(
0187       !ellipseBoundsObject.inside(outsideBy15, BoundaryTolerance::None()));
0188 }
0189 /// Unit test for testing EllipseBounds assignment
0190 BOOST_AUTO_TEST_CASE(EllipseBoundsAssignment) {
0191   const double outerRx = 15.;  // != 25
0192   const double outerRy = 20.;  // != 30
0193 
0194   EllipseBounds ellipseBoundsObject(innerRx, outerRx, innerRy, outerRy,
0195                                     averagePhi, phiSector);
0196   EllipseBounds similarlyConstructeEllipseBoundsObject(
0197       innerRx, outerRx, innerRy, outerRy, averagePhi, phiSector);
0198   /// Test operator ==
0199   BOOST_CHECK_EQUAL(ellipseBoundsObject,
0200                     similarlyConstructeEllipseBoundsObject);
0201 
0202   /// Test assignment
0203   EllipseBounds assignedEllipseBoundsObject(11., 12., 17., 18., 1.);
0204   // object, in some sense
0205   assignedEllipseBoundsObject = ellipseBoundsObject;
0206   BOOST_CHECK_EQUAL(assignedEllipseBoundsObject, ellipseBoundsObject);
0207 }
0208 
0209 BOOST_AUTO_TEST_SUITE_END()
0210 
0211 }  // namespace ActsTests