Back to home page

EIC code displayed by LXR

 
 

    


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

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