Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-26 07:56:29

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/RadialBounds.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <numbers>
0020 #include <stdexcept>
0021 #include <vector>
0022 
0023 using namespace Acts;
0024 
0025 namespace ActsTests {
0026 
0027 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0028 
0029 const double rMin = 1.;
0030 const double rMax = 5.;
0031 const double halfPhiSector = std::numbers::pi / 8.;
0032 const double avgPhi = 0.1;
0033 
0034 /// Unit tests for RadialBounds constructors
0035 BOOST_AUTO_TEST_CASE(RadialBoundsConstruction) {
0036   /// Test default construction
0037   // default construction is deleted
0038 
0039   /// Test construction with radii and default sector
0040   BOOST_CHECK_EQUAL(RadialBounds(rMin, rMax).type(), SurfaceBounds::eDisc);
0041 
0042   /// Test construction with radii and sector half angle
0043   BOOST_CHECK_EQUAL(RadialBounds(rMin, rMax, halfPhiSector).type(),
0044                     SurfaceBounds::eDisc);
0045 
0046   /// Copy constructor
0047   RadialBounds original(rMin, rMax);
0048   RadialBounds copied(original);
0049   BOOST_CHECK_EQUAL(copied, original);
0050 }
0051 
0052 // Streaning and recreation test
0053 BOOST_AUTO_TEST_CASE(RadialBoundsRecreation) {
0054   RadialBounds original(rMin, rMax, halfPhiSector, avgPhi);
0055   // const bool symmetric(false);
0056   auto valvector = original.values();
0057   std::array<double, RadialBounds::eSize> values{};
0058   std::copy_n(valvector.begin(), RadialBounds::eSize, values.begin());
0059   RadialBounds recreated(values);
0060   BOOST_CHECK_EQUAL(original, recreated);
0061 }
0062 
0063 // Streaning and recreation test
0064 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
0065   // Negative inner radius
0066   BOOST_CHECK_THROW(RadialBounds(-rMin, rMax, halfPhiSector, avgPhi),
0067                     std::logic_error);
0068 
0069   // Negative outer radius
0070   BOOST_CHECK_THROW(RadialBounds(rMin, -rMax, halfPhiSector, avgPhi),
0071                     std::logic_error);
0072 
0073   // Negative inner and outer radius
0074   BOOST_CHECK_THROW(RadialBounds(-rMin, -rMax, halfPhiSector, avgPhi),
0075                     std::logic_error);
0076 
0077   // Swapped radii
0078   BOOST_CHECK_THROW(RadialBounds(rMax, rMin, halfPhiSector, avgPhi),
0079                     std::logic_error);
0080 
0081   // Out of bound phi sector
0082   BOOST_CHECK_THROW(RadialBounds(rMin, -rMax, -5., avgPhi), std::logic_error);
0083 
0084   // Out of bound phi position
0085   BOOST_CHECK_THROW(RadialBounds(rMin, -rMax, halfPhiSector, 5.),
0086                     std::logic_error);
0087 }
0088 
0089 /// Unit tests for RadialBounds properties
0090 BOOST_AUTO_TEST_CASE(RadialBoundsProperties) {
0091   /// Test type() (redundant; already used in constructor confirmation)
0092   RadialBounds radialBoundsObject(rMin, rMax, halfPhiSector);
0093   BOOST_CHECK_EQUAL(radialBoundsObject.type(), SurfaceBounds::eDisc);
0094 
0095   /// Test distanceToBoundary
0096   Vector2 outside(30., 0.);
0097   Vector2 inSurface(2., 0.);
0098 
0099   /// Test dump
0100   boost::test_tools::output_test_stream dumpOutput;
0101   radialBoundsObject.toStream(dumpOutput);
0102   BOOST_CHECK(
0103       dumpOutput.is_equal("Acts::RadialBounds:  (innerRadius, outerRadius, "
0104                           "hPhiSector, averagePhi) = (1.0000000, "
0105                           "5.0000000, 0.3926991, 0.0000000)"));
0106 
0107   /// Test inside
0108   BOOST_CHECK(radialBoundsObject.inside(inSurface, BoundaryTolerance::None()));
0109   BOOST_CHECK(!radialBoundsObject.inside(outside, BoundaryTolerance::None()));
0110 
0111   /// Test rMin
0112   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMinR), rMin);
0113 
0114   /// Test rMax
0115   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eMaxR), rMax);
0116 
0117   /// Test averagePhi (should be a redundant method, this is not configurable)
0118   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eAveragePhi), 0.);
0119 
0120   /// Test halfPhiSector
0121   BOOST_CHECK_EQUAL(radialBoundsObject.get(RadialBounds::eHalfPhiSector),
0122                     halfPhiSector);
0123 }
0124 /// Unit test for testing RadialBounds assignment
0125 BOOST_AUTO_TEST_CASE(RadialBoundsAssignment) {
0126   RadialBounds radialBoundsObject(rMin, rMax, halfPhiSector);
0127 
0128   /// Test operator ==
0129   // not implemented in this class
0130 
0131   /// Test assignment
0132   RadialBounds assignedRadialBoundsObject(10.1, 123.);
0133   assignedRadialBoundsObject = radialBoundsObject;
0134   BOOST_CHECK_EQUAL(assignedRadialBoundsObject, radialBoundsObject);
0135 }
0136 
0137 BOOST_AUTO_TEST_CASE(RadialBoundsCenter) {
0138   // Test radial bounds with default phi
0139   RadialBounds radial(rMin, rMax);
0140   Vector2 center = radial.center();
0141   double expectedR = 0.5 * (rMin + rMax);
0142   BOOST_CHECK_EQUAL(center.x(), expectedR);
0143   BOOST_CHECK_EQUAL(center.y(), 0.0);  // avgPhi = 0
0144 
0145   // Test radial bounds with non-zero average phi
0146   RadialBounds radialOffset(rMin, rMax, halfPhiSector, avgPhi);
0147   Vector2 centerOffset = radialOffset.center();
0148   BOOST_CHECK_EQUAL(centerOffset.x(), expectedR);
0149   BOOST_CHECK_EQUAL(centerOffset.y(), avgPhi);
0150 }
0151 
0152 BOOST_AUTO_TEST_SUITE_END()
0153 
0154 }  // namespace ActsTests