Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:28

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