Back to home page

EIC code displayed by LXR

 
 

    


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

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/ConeBounds.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <cmath>
0020 #include <numbers>
0021 #include <stdexcept>
0022 #include <vector>
0023 
0024 // Note on nomenclature:
0025 // - alpha = cone opening half angle
0026 // - z is the axis of symmetry
0027 // - zMin, zMax define limits for truncated cone
0028 // - phi is clock angle around cone, with x axis corresponding to phi=0
0029 // - Cone segments may be defined with the averagePhi (central position of
0030 // segment) and halfPhi (extent in phi of cone segment either side of the
0031 // averagePhi)
0032 // - Local coords are z, rphi
0033 
0034 namespace Acts::Test {
0035 
0036 BOOST_AUTO_TEST_SUITE(Surfaces)
0037 
0038 const double alpha = std::numbers::pi / 8.;
0039 const double zMin = 3.;
0040 const double zMax = 6.;
0041 const double halfPhi = std::numbers::pi / 4.;
0042 const double averagePhi = 0.;
0043 const bool symmetric = false;
0044 
0045 /// Unit test for creating compliant/non-compliant ConeBounds object
0046 BOOST_AUTO_TEST_CASE(ConeBoundsConstruction) {
0047   /// Test default construction
0048   // default construction is deleted
0049 
0050   BOOST_TEST_CHECKPOINT("Four parameter constructor (last two at default)");
0051   ConeBounds defaultConeBounds(alpha, symmetric);
0052   BOOST_CHECK_EQUAL(defaultConeBounds.type(), SurfaceBounds::eCone);
0053 
0054   BOOST_TEST_CHECKPOINT("Four parameter constructor");
0055   ConeBounds fourParameterConstructed(alpha, symmetric, halfPhi, averagePhi);
0056   BOOST_CHECK_EQUAL(fourParameterConstructed.type(), SurfaceBounds::eCone);
0057 
0058   BOOST_TEST_CHECKPOINT("Five parameter constructor (last two at default)");
0059   ConeBounds defaulted5ParamConeBounds(alpha, zMin, zMax);
0060   BOOST_CHECK_EQUAL(defaulted5ParamConeBounds.type(), SurfaceBounds::eCone);
0061 
0062   BOOST_TEST_CHECKPOINT("Five parameter constructor)");
0063   ConeBounds fiveParamConstructedConeBounds(alpha, zMin, zMax, halfPhi,
0064                                             averagePhi);
0065   BOOST_CHECK_EQUAL(fiveParamConstructedConeBounds.type(),
0066                     SurfaceBounds::eCone);
0067 
0068   BOOST_TEST_CHECKPOINT("Copy constructor");
0069   ConeBounds copyConstructedConeBounds(fiveParamConstructedConeBounds);
0070   BOOST_CHECK_EQUAL(copyConstructedConeBounds, fiveParamConstructedConeBounds);
0071 }
0072 
0073 /// Streaning and recreation test
0074 BOOST_AUTO_TEST_CASE(ConeBoundsRecreation) {
0075   ConeBounds original(alpha, zMin, zMax, halfPhi, averagePhi);
0076   auto valvector = original.values();
0077   std::array<double, ConeBounds::eSize> values{};
0078   std::copy_n(valvector.begin(), ConeBounds::eSize, values.begin());
0079   ConeBounds recreated(values);
0080 
0081   BOOST_CHECK_EQUAL(recreated, original);
0082 }
0083 
0084 /// Unit tests for AnnulusBounds exception throwing
0085 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
0086   // Exception for opening angle smaller 0
0087   BOOST_CHECK_THROW(ConeBounds(-alpha, zMin, zMax, halfPhi, averagePhi),
0088                     std::logic_error);
0089 
0090   // Exception for opening angle bigger pi
0091   BOOST_CHECK_THROW(
0092       ConeBounds(std::numbers::pi, zMin, zMax, halfPhi, averagePhi),
0093       std::logic_error);
0094 
0095   // Exception for swapped zMin and zMax
0096   BOOST_CHECK_THROW(ConeBounds(alpha, zMax, zMin, halfPhi, averagePhi),
0097                     std::logic_error);
0098 
0099   // Exception for negative half sector phi
0100   BOOST_CHECK_THROW(ConeBounds(alpha, zMin, zMax, -halfPhi, averagePhi),
0101                     std::logic_error);
0102 
0103   // Exception for out of range phi positioning
0104   BOOST_CHECK_THROW(
0105       ConeBounds(alpha, zMin, zMax, halfPhi, 2 * std::numbers::pi),
0106       std::logic_error);
0107 }
0108 
0109 /// Unit tests for properties of ConeBounds object
0110 BOOST_AUTO_TEST_CASE(ConeBoundsProperties) {
0111   const Vector2 origin(0, 0);
0112   const Vector2 somewhere(4., 4.);
0113   ConeBounds coneBoundsObject(alpha, zMin, zMax, halfPhi, averagePhi);
0114 
0115   /// Test for type (redundant)
0116   BOOST_CHECK_EQUAL(coneBoundsObject.type(), SurfaceBounds::eCone);
0117 
0118   /// Test for inside
0119   BOOST_CHECK(!coneBoundsObject.inside(origin));
0120 
0121   /// Test for r
0122   CHECK_CLOSE_REL(coneBoundsObject.r(zMin), zMin * std::tan(alpha), 1e-6);
0123 
0124   /// Test for tanAlpha
0125   CHECK_CLOSE_REL(coneBoundsObject.tanAlpha(), std::tan(alpha), 1e-6);
0126 
0127   /// Test for alpha
0128   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eAlpha), alpha, 1e-6);
0129 
0130   /// Test for minZ
0131   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMinZ), zMin, 1e-6);
0132 
0133   /// Test for maxZ
0134   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMaxZ), zMax, 1e-6);
0135 
0136   /// Test for averagePhi
0137   CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eHalfPhiSector), halfPhi,
0138                   1e-6);
0139 
0140   /// Test for dump
0141   boost::test_tools::output_test_stream dumpOutput;
0142   coneBoundsObject.toStream(dumpOutput);
0143   BOOST_CHECK(dumpOutput.is_equal(
0144       "Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, averagePhi) = "
0145       "(0.4142136, 3.0000000, 6.0000000, 0.7853982, 0.0000000)"));
0146 }
0147 
0148 // Unit test for testing ConeBounds assignment
0149 BOOST_AUTO_TEST_CASE(ConeBoundsAssignment) {
0150   ConeBounds originalConeBounds(alpha, zMin, zMax, halfPhi, averagePhi);
0151   ConeBounds assignedConeBounds(0.1, 2.3, 4.5, 1.2, 2.1);
0152   assignedConeBounds = originalConeBounds;
0153 
0154   BOOST_CHECK_EQUAL(assignedConeBounds, originalConeBounds);
0155 }
0156 
0157 BOOST_AUTO_TEST_SUITE_END()
0158 
0159 }  // namespace Acts::Test