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/BoundaryCheck.hpp"
0015 #include "Acts/Surfaces/CylinderBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0018 
0019 #include <algorithm>
0020 #include <array>
0021 #include <cmath>
0022 #include <stdexcept>
0023 #include <vector>
0024 
0025 namespace Acts {
0026 
0027 namespace Test {
0028 BOOST_AUTO_TEST_SUITE(Surfaces)
0029 /// Unit test for creating compliant/non-compliant CylinderBounds object
0030 
0031 BOOST_AUTO_TEST_CASE(CylinderBoundsConstruction) {
0032   /// test default construction
0033   // CylinderBounds defaultConstructedCylinderBounds;  // deleted
0034   double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0),
0035       minBevelZ(-M_PI / 4), maxBevelZ(M_PI / 6);
0036   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz).type(),
0037                     SurfaceBounds::eCylinder);
0038   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi).type(),
0039                     SurfaceBounds::eCylinder);
0040   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, halfphi, averagePhi).type(),
0041                     SurfaceBounds::eCylinder);
0042   BOOST_CHECK_EQUAL(
0043       CylinderBounds(radius, halfz, (double)M_PI, (double)0., minBevelZ).type(),
0044       SurfaceBounds::eCylinder);
0045   BOOST_CHECK_EQUAL(CylinderBounds(radius, halfz, (double)M_PI, (double)0.,
0046                                    minBevelZ, maxBevelZ)
0047                         .type(),
0048                     SurfaceBounds::eCylinder);
0049   //
0050   /// test copy construction;
0051   CylinderBounds cylinderBounds(radius, halfz);
0052   CylinderBounds copyConstructedCylinderBounds(cylinderBounds);
0053   BOOST_CHECK_EQUAL(copyConstructedCylinderBounds, cylinderBounds);
0054 }
0055 
0056 BOOST_AUTO_TEST_CASE(CylinderBoundsRecreation) {
0057   /// test default construction
0058   // CylinderBounds defaultConstructedCylinderBounds;  // deleted
0059   double radius(0.5), halfz(10.);
0060   // Test construction with radii and default sector
0061   auto original = CylinderBounds(radius, halfz);
0062   auto valvector = original.values();
0063   std::array<double, CylinderBounds::eSize> values{};
0064   std::copy_n(valvector.begin(), CylinderBounds::eSize, values.begin());
0065   CylinderBounds recreated(values);
0066   BOOST_CHECK_EQUAL(original, recreated);
0067 }
0068 
0069 BOOST_AUTO_TEST_CASE(CylinderBoundsException) {
0070   double radius(0.5), halfz(10.), halfphi(M_PI / 2.0), averagePhi(M_PI / 2.0);
0071 
0072   // Negative radius
0073   BOOST_CHECK_THROW(CylinderBounds(-radius, halfz, halfphi, averagePhi),
0074                     std::logic_error);
0075 
0076   // Negative half length in z
0077   BOOST_CHECK_THROW(CylinderBounds(radius, -halfz, halfphi, averagePhi),
0078                     std::logic_error);
0079 
0080   // Negative half sector in phi
0081   BOOST_CHECK_THROW(CylinderBounds(radius, halfz, -halfphi, averagePhi),
0082                     std::logic_error);
0083 
0084   // Half sector in phi out of bounds
0085   BOOST_CHECK_THROW(CylinderBounds(radius, halfz, 4., averagePhi),
0086                     std::logic_error);
0087 
0088   // Phi position out of bounds
0089   BOOST_CHECK_THROW(CylinderBounds(radius, halfz, halfphi, 4.),
0090                     std::logic_error);
0091 }
0092 
0093 /// Unit tests for CylinderBounds properties
0094 BOOST_AUTO_TEST_CASE(CylinderBoundsProperties) {
0095   // CylinderBounds object of radius 0.5 and halfz 20
0096   double nominalRadius{0.5};
0097   double nominalHalfLength{20.};
0098   double halfphi(M_PI / 4.0);
0099   double averagePhi(0.0);
0100   double bevelMinZ(M_PI / 4);
0101   double bevelMaxZ(M_PI / 6);
0102   CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
0103   CylinderBounds cylinderBoundsSegment(nominalRadius, nominalHalfLength,
0104                                        halfphi, averagePhi);
0105   CylinderBounds cylinderBoundsBeveledObject(nominalRadius, nominalHalfLength,
0106                                              M_PI, 0., bevelMinZ, bevelMaxZ);
0107 
0108   /// test for type()
0109   BOOST_CHECK_EQUAL(cylinderBoundsObject.type(), SurfaceBounds::eCylinder);
0110 
0111   /// test for inside(), 2D coords are r or phi ,z? : needs clarification
0112   const Vector2 origin{0., 0.};
0113   const Vector2 atPiBy2{M_PI / 2., 0.0};
0114   const Vector2 atPi{M_PI, 0.0};
0115   const Vector2 beyondEnd{0, 30.0};
0116   const Vector2 unitZ{0.0, 1.0};
0117   const Vector2 unitPhi{1.0, 0.0};
0118   const Vector2 withinBevelMin{0.5, -20.012};
0119   const Vector2 outsideBevelMin{0.5, -40.};
0120   const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
0121   const BoundaryCheck trueBoundaryCheckWithLessTolerance(true, true, 0.01,
0122                                                          0.01);
0123   BOOST_CHECK(
0124       cylinderBoundsObject.inside(atPiBy2, trueBoundaryCheckWithTolerance));
0125   BOOST_CHECK(
0126       !cylinderBoundsSegment.inside(unitPhi, trueBoundaryCheckWithTolerance));
0127   BOOST_CHECK(
0128       cylinderBoundsObject.inside(origin, trueBoundaryCheckWithTolerance));
0129 
0130   BOOST_CHECK(!cylinderBoundsObject.inside(withinBevelMin,
0131                                            trueBoundaryCheckWithLessTolerance));
0132   BOOST_CHECK(cylinderBoundsBeveledObject.inside(
0133       withinBevelMin, trueBoundaryCheckWithLessTolerance));
0134   BOOST_CHECK(!cylinderBoundsBeveledObject.inside(
0135       outsideBevelMin, trueBoundaryCheckWithLessTolerance));
0136 
0137   /// test for inside3D() with Vector3 argument
0138   const Vector3 origin3D{0., 0., 0.};
0139   BOOST_CHECK(
0140       !cylinderBoundsObject.inside3D(origin3D, trueBoundaryCheckWithTolerance));
0141 
0142   /// test for r()
0143   CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eR), nominalRadius,
0144                   1e-6);
0145 
0146   /// test for averagePhi
0147   CHECK_CLOSE_OR_SMALL(cylinderBoundsObject.get(CylinderBounds::eAveragePhi),
0148                        averagePhi, 1e-6, 1e-6);
0149 
0150   /// test for halfPhiSector
0151   CHECK_CLOSE_REL(cylinderBoundsSegment.get(CylinderBounds::eHalfPhiSector),
0152                   halfphi,
0153                   1e-6);  // fail
0154 
0155   /// test for halflengthZ (NOTE: Naming violation)
0156   CHECK_CLOSE_REL(cylinderBoundsObject.get(CylinderBounds::eHalfLengthZ),
0157                   nominalHalfLength, 1e-6);
0158 
0159   /// test for bevelMinZ/MaxZ
0160   CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMinZ),
0161                   bevelMinZ, 1e-6);
0162   CHECK_CLOSE_REL(cylinderBoundsBeveledObject.get(CylinderBounds::eBevelMaxZ),
0163                   bevelMaxZ, 1e-6);
0164 
0165   /// test for dump
0166   boost::test_tools::output_test_stream dumpOuput;
0167   cylinderBoundsObject.toStream(dumpOuput);
0168   BOOST_CHECK(dumpOuput.is_equal(
0169       "Acts::CylinderBounds: (radius, halfLengthZ, halfPhiSector, "
0170       "averagePhi, bevelMinZ, bevelMaxZ) = (0.5000000, 20.0000000, 3.1415927, "
0171       "0.0000000, 0.0000000, 0.0000000)"));
0172 }
0173 /// Unit test for testing CylinderBounds assignment
0174 BOOST_AUTO_TEST_CASE(CylinderBoundsAssignment) {
0175   double nominalRadius{0.5};
0176   double nominalHalfLength{20.};
0177   CylinderBounds cylinderBoundsObject(nominalRadius, nominalHalfLength);
0178   CylinderBounds assignedCylinderBounds(10.5, 6.6);
0179   assignedCylinderBounds = cylinderBoundsObject;
0180   BOOST_CHECK_EQUAL(assignedCylinderBounds.get(CylinderBounds::eR),
0181                     cylinderBoundsObject.get(CylinderBounds::eR));
0182   BOOST_CHECK_EQUAL(assignedCylinderBounds, cylinderBoundsObject);
0183 }
0184 
0185 BOOST_AUTO_TEST_SUITE_END()
0186 
0187 }  // namespace Test
0188 
0189 }  // namespace Acts