Back to home page

EIC code displayed by LXR

 
 

    


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

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