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/LineBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <stdexcept>
0021 #include <vector>
0022 
0023 namespace Acts {
0024 
0025 namespace Test {
0026 BOOST_AUTO_TEST_SUITE(Surfaces)
0027 /// Unit test for creating compliant/non-compliant LineBounds object
0028 BOOST_AUTO_TEST_CASE(LineBoundsConstruction) {
0029   /// test LineBounds(double, double)
0030   double radius(0.5), halfz(10.);
0031   LineBounds lineBounds(radius, halfz);
0032   BOOST_CHECK_EQUAL(lineBounds.type(), SurfaceBounds::eLine);
0033   /// test copy construction;
0034   LineBounds copyConstructedLineBounds(lineBounds);  // implicit
0035   BOOST_CHECK_EQUAL(copyConstructedLineBounds.type(), SurfaceBounds::eLine);
0036 }
0037 
0038 /// Unit test for testing LineBounds recreation from streaming
0039 BOOST_AUTO_TEST_CASE(LineBoundsRecreation) {
0040   double nominalRadius{0.5};
0041   double nominalHalfLength{20.};
0042   LineBounds original(nominalRadius, nominalHalfLength);
0043   LineBounds recreated(original);
0044   auto valvector = original.values();
0045   std::array<double, LineBounds::eSize> values{};
0046   std::copy_n(valvector.begin(), LineBounds::eSize, values.begin());
0047   BOOST_CHECK_EQUAL(original, recreated);
0048 }
0049 
0050 /// Unit test for testing LineBounds exceptions
0051 BOOST_AUTO_TEST_CASE(LineBoundsExceptions) {
0052   double nominalRadius{0.5};
0053   double nominalHalfLength{20.};
0054   // Negative radius
0055   BOOST_CHECK_THROW(LineBounds(-nominalRadius, nominalHalfLength),
0056                     std::logic_error);
0057   // Negative half length
0058   BOOST_CHECK_THROW(LineBounds(nominalRadius, -nominalHalfLength),
0059                     std::logic_error);
0060 
0061   // Negative radius and half length
0062   BOOST_CHECK_THROW(LineBounds(-nominalRadius, -nominalHalfLength),
0063                     std::logic_error);
0064 }
0065 
0066 /// Unit test for testing LineBounds assignment
0067 BOOST_AUTO_TEST_CASE(LineBoundsAssignment) {
0068   double nominalRadius{0.5};
0069   double nominalHalfLength{20.};
0070   LineBounds lineBoundsObject(nominalRadius, nominalHalfLength);
0071   LineBounds assignedLineBounds = lineBoundsObject;
0072   BOOST_CHECK_EQUAL(assignedLineBounds, lineBoundsObject);
0073 }
0074 
0075 /// Unit tests for LineBounds properties
0076 BOOST_AUTO_TEST_CASE(LineBoundsProperties) {
0077   // LineBounds object of radius 0.5 and halfz 20
0078   double nominalRadius{0.5};
0079   double nominalHalfLength{20.};
0080   LineBounds lineBoundsObject(nominalRadius, nominalHalfLength);
0081 
0082   /// test for type()
0083   BOOST_CHECK_EQUAL(lineBoundsObject.type(), SurfaceBounds::eLine);
0084 
0085   /// test for inside()
0086   const Vector2 origin{0., 0.};
0087   const Vector2 atRadius{0.5, 10.};
0088   const Vector2 beyondEnd{0.0, 30.0};
0089   const Vector2 unitZ{0.0, 1.0};
0090   const Vector2 unitR{1.0, 0.0};
0091   const BoundaryCheck trueBoundaryCheckWithTolerance(true, true, 0.1, 0.1);
0092   // This fails because the bounds are not inclusive.
0093   BOOST_CHECK(
0094       !lineBoundsObject.inside(atRadius, trueBoundaryCheckWithTolerance));
0095   BOOST_CHECK(
0096       !lineBoundsObject.inside(beyondEnd, trueBoundaryCheckWithTolerance));
0097   BOOST_CHECK(lineBoundsObject.inside(unitZ, trueBoundaryCheckWithTolerance));
0098   BOOST_CHECK(!lineBoundsObject.inside(unitR, trueBoundaryCheckWithTolerance));
0099 
0100   /// Test negative redius inside
0101 
0102   BOOST_CHECK(lineBoundsObject.inside(Vector2{-0.2, 10},
0103                                       trueBoundaryCheckWithTolerance));
0104   BOOST_CHECK(!lineBoundsObject.inside(Vector2{-0.8, 10},
0105                                        trueBoundaryCheckWithTolerance));
0106 
0107   /// test for r()
0108   BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eR), nominalRadius);
0109 
0110   /// test for halflengthZ (NOTE: Naming violation)
0111   BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eHalfLengthZ),
0112                     nominalHalfLength);
0113 
0114   /// test for dump
0115   boost::test_tools::output_test_stream dumpOuput;
0116   lineBoundsObject.toStream(dumpOuput);
0117   BOOST_CHECK(dumpOuput.is_equal(
0118       "Acts::LineBounds: (radius, halflengthInZ) = (0.5000000, 20.0000000)"));
0119 }
0120 
0121 BOOST_AUTO_TEST_SUITE_END()
0122 
0123 }  // namespace Test
0124 
0125 }  // namespace Acts