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/DiscTrapezoidBounds.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <stdexcept>
0021 #include <vector>
0022 
0023 namespace Acts::Test {
0024 
0025 BOOST_AUTO_TEST_SUITE(Surfaces)
0026 
0027 const double minHalfX = 1.;
0028 const double maxHalfX = 5.;
0029 const double rMin = 2.;
0030 const double rMax = 6.;
0031 const double averagePhi = 0.;
0032 const double stereo = 0.1;
0033 
0034 /// Unit tests for DiscTrapezoidBounds constructors
0035 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsConstruction) {
0036   /// Test construction with dimensions and default stereo
0037   BOOST_CHECK_EQUAL(
0038       DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, averagePhi).type(),
0039       SurfaceBounds::eDiscTrapezoid);
0040 
0041   /// Test construction with all dimensions
0042   BOOST_CHECK_EQUAL(
0043       DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, averagePhi, stereo)
0044           .type(),
0045       SurfaceBounds::eDiscTrapezoid);
0046 
0047   /// Copy constructor
0048   DiscTrapezoidBounds original(minHalfX, maxHalfX, rMin, rMax, averagePhi);
0049   DiscTrapezoidBounds copied(original);
0050   BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiscTrapezoid);
0051 }
0052 
0053 // Streaning and recreation test
0054 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsRecreation) {
0055   DiscTrapezoidBounds original(minHalfX, maxHalfX, rMin, rMax, averagePhi,
0056                                stereo);
0057   auto valvector = original.values();
0058   std::array<double, DiscTrapezoidBounds::eSize> values{};
0059   std::copy_n(valvector.begin(), DiscTrapezoidBounds::eSize, values.begin());
0060   DiscTrapezoidBounds recreated(values);
0061   BOOST_CHECK_EQUAL(recreated, original);
0062 }
0063 
0064 // Unit tests for AnnulusBounds exception throwing
0065 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsExceptions) {
0066   // Exception for opening neg min half x < 0
0067   BOOST_CHECK_THROW(
0068       DiscTrapezoidBounds(-minHalfX, maxHalfX, rMin, rMax, averagePhi, stereo),
0069       std::logic_error);
0070 
0071   // Exception for opening neg max half x < 0
0072   BOOST_CHECK_THROW(
0073       DiscTrapezoidBounds(minHalfX, -maxHalfX, rMin, rMax, averagePhi, stereo),
0074       std::logic_error);
0075 
0076   // Exception for opening neg min and max half x < 0
0077   BOOST_CHECK_THROW(
0078       DiscTrapezoidBounds(-minHalfX, -maxHalfX, rMin, rMax, averagePhi, stereo),
0079       std::logic_error);
0080 
0081   // Exception for opening neg r min
0082   BOOST_CHECK_THROW(
0083       DiscTrapezoidBounds(minHalfX, maxHalfX, -rMin, rMax, averagePhi, stereo),
0084       std::logic_error);
0085 
0086   // Exception for opening neg r max
0087   BOOST_CHECK_THROW(
0088       DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, -rMax, averagePhi, stereo),
0089       std::logic_error);
0090 
0091   // Exception for opening neg r min and r max
0092   BOOST_CHECK_THROW(
0093       DiscTrapezoidBounds(minHalfX, maxHalfX, -rMin, -rMax, averagePhi, stereo),
0094       std::logic_error);
0095 
0096   // Exception for out of bound average phi
0097   BOOST_CHECK_THROW(
0098       DiscTrapezoidBounds(minHalfX, maxHalfX, rMin, rMax, 4., stereo),
0099       std::logic_error);
0100 }
0101 
0102 /// Unit tests for DiscTrapezoidBounds properties
0103 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsProperties) {
0104   /// Test clone
0105   DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
0106                                                 averagePhi);
0107 
0108   /// Test type() (redundant; already used in constructor confirmation)
0109   BOOST_CHECK_EQUAL(DiscTrapezoidBoundsObject.type(),
0110                     SurfaceBounds::eDiscTrapezoid);
0111 
0112   /// Test distanceToBoundary
0113   Vector2 origin(0., 0.);
0114   Vector2 outside(30., 0.);
0115   Vector2 inSurface(2.5, 0.);
0116 
0117   /// Test dump
0118   boost::test_tools::output_test_stream dumpOutput;
0119   DiscTrapezoidBoundsObject.toStream(dumpOutput);
0120   BOOST_CHECK(dumpOutput.is_equal(
0121       "Acts::DiscTrapezoidBounds: (innerRadius, outerRadius, halfLengthXminR, "
0122       "halfLengthXmaxR, halfLengthY, halfPhiSector, averagePhi, rCenter, "
0123       "stereo) = "
0124       "(2.0000000, 6.0000000, 1.0000000, 5.0000000, 0.7922870, 0.9851108, "
0125       "0.0000000, 2.5243378, 0.0000000)"));
0126 
0127   /// Test inside
0128   BOOST_CHECK(
0129       DiscTrapezoidBoundsObject.inside(inSurface, BoundaryTolerance::None()));
0130   BOOST_CHECK(
0131       !DiscTrapezoidBoundsObject.inside(outside, BoundaryTolerance::None()));
0132 
0133   /// Test rMin
0134   CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMin(), rMin, 1e-6);
0135 
0136   /// Test rMax
0137   CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rMax(), rMax, 1e-6);
0138 
0139   /// Test averagePhi
0140   CHECK_SMALL(DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eAveragePhi),
0141               1e-9);
0142 
0143   /// Test rCenter (redundant; not configurable)
0144   CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.rCenter(), 2.524337798, 1e-6);
0145 
0146   /// Test halfPhiSector (redundant; not configurable)
0147   CHECK_SMALL(DiscTrapezoidBoundsObject.stereo(), 1e-6);
0148 
0149   /// Test minHalfLengthX
0150   CHECK_CLOSE_REL(
0151       DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXminR),
0152       minHalfX, 1e-6);
0153 
0154   /// Test maxHalfLengthX
0155   CHECK_CLOSE_REL(
0156       DiscTrapezoidBoundsObject.get(DiscTrapezoidBounds::eHalfLengthXmaxR),
0157       maxHalfX, 1e-6);
0158 
0159   /// Test halfLengthY
0160   CHECK_CLOSE_REL(DiscTrapezoidBoundsObject.halfLengthY(), 0.792286991, 1e-6);
0161 }
0162 /// Unit test for testing DiscTrapezoidBounds assignment
0163 BOOST_AUTO_TEST_CASE(DiscTrapezoidBoundsAssignment) {
0164   DiscTrapezoidBounds DiscTrapezoidBoundsObject(minHalfX, maxHalfX, rMin, rMax,
0165                                                 averagePhi, stereo);
0166 
0167   /// Test operator ==
0168   // not implemented in this class
0169 
0170   /// Test assignment
0171   DiscTrapezoidBounds assignedDiscTrapezoidBoundsObject(2.1, 6.6, 3.4, 4.2, 0.3,
0172                                                         0.);
0173   assignedDiscTrapezoidBoundsObject = DiscTrapezoidBoundsObject;
0174   BOOST_CHECK_EQUAL(assignedDiscTrapezoidBoundsObject,
0175                     DiscTrapezoidBoundsObject);
0176 }
0177 
0178 BOOST_AUTO_TEST_SUITE_END()
0179 
0180 }  // namespace Acts::Test