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/DiamondBounds.hpp"
0016 #include "Acts/Surfaces/RectangleBounds.hpp"
0017 #include "Acts/Surfaces/SurfaceBounds.hpp"
0018 
0019 #include <iostream>
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 DiamondBounds object
0028 BOOST_AUTO_TEST_CASE(DiamondBoundsConstruction) {
0029   double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
0030   // test default construction
0031   // DiamondBounds defaultConstructedDiamondBounds;  //deleted
0032   //
0033   /// Test construction with dimensions
0034   // DiamondBounds d(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0035   BOOST_CHECK_EQUAL(
0036       DiamondBounds(minHalfX, midHalfX, maxHalfX, halfY1, halfY2).type(),
0037       SurfaceBounds::eDiamond);
0038   //
0039   /// Copy constructor
0040   DiamondBounds original(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0041   DiamondBounds copied(original);
0042   BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiamond);
0043 
0044   // invalid inputs
0045   BOOST_CHECK_THROW(
0046       DiamondBounds db(midHalfX, minHalfX, maxHalfX, halfY1, halfY2),
0047       std::logic_error);
0048   BOOST_CHECK_THROW(
0049       DiamondBounds db(minHalfX, maxHalfX, midHalfX, halfY1, halfY2),
0050       std::logic_error);
0051 }
0052 /// Unit tests for DiamondBounds properties
0053 BOOST_AUTO_TEST_CASE(DiamondBoundsProperties) {
0054   double minHalfX(10.), midHalfX(50.), maxHalfX(30.), halfY1(10.), halfY2(20.);
0055   /// Test clone
0056   DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
0057                                     halfY2);
0058   //
0059   /// Test type() (redundant; already used in constructor confirmation)
0060   BOOST_CHECK_EQUAL(diamondBoundsObject.type(), SurfaceBounds::eDiamond);
0061   // //redundant test
0062   //
0063   /// Test the half length at negative y
0064   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXnegY),
0065                     minHalfX);
0066   //
0067   /// Test the half length at the x axis
0068   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXzeroY),
0069                     midHalfX);
0070   //
0071   /// Test the half length at positive y
0072   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXposY),
0073                     maxHalfX);
0074   //
0075   /// Test half length into the negative side
0076   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYneg),
0077                     halfY1);
0078   //
0079   /// Test half length into the positive side
0080   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYpos),
0081                     halfY2);
0082   //
0083   /// Test boundingBox
0084   BOOST_CHECK_EQUAL(diamondBoundsObject.boundingBox(),
0085                     RectangleBounds(Vector2{-50., -10.}, Vector2{50., 20.}));
0086   //
0087   // clone already tested
0088   //
0089   /// Test distanceToBoundary
0090   Vector2 origin(0., 0.);
0091   Vector2 outsideBy10(0., 30.);
0092   Vector2 inRectangle(15., 0.);
0093 
0094   /// Test dump
0095   // Acts::DiamondBounds:  (minHlengthX, medHlengthX, maxHlengthX, hlengthY1,
0096   // hlengthY2 ) = (30.0000000, 10.0000000, 50.0000000, 10.0000000,
0097   // 20.0000000)
0098   diamondBoundsObject.toStream(std::cout);
0099   boost::test_tools::output_test_stream dumpOuput;
0100   diamondBoundsObject.toStream(dumpOuput);
0101   BOOST_CHECK(
0102       dumpOuput.is_equal("Acts::DiamondBounds: (halfXatYneg, halfXatYzero, "
0103                          "halfXatYpos, halfYneg, halfYpos) = (10.0000000, "
0104                          "50.0000000, 30.0000000, 10.0000000, 20.0000000)"));
0105   //
0106   /// Test inside
0107   BOOST_CHECK(diamondBoundsObject.inside(origin, BoundaryCheck(true)));
0108   // dont understand why this is so:
0109   BOOST_CHECK(!diamondBoundsObject.inside(outsideBy10, BoundaryCheck(true)));
0110   //
0111   /// Test vertices (does this need to be implemented in this class??
0112   // auto v=diamondBoundsObject.vertices();
0113   std::vector<Vector2> referenceVertices{
0114       {-minHalfX, -halfY1}, {minHalfX, -halfY1}, {midHalfX, 0.},
0115       {maxHalfX, halfY2},   {-maxHalfX, halfY2}, {-midHalfX, 0.}};
0116   const auto& actualVertices = diamondBoundsObject.vertices();
0117   BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
0118                                 referenceVertices.cbegin(),
0119                                 referenceVertices.cend());
0120 }
0121 /// Unit test for testing DiamondBounds assignment
0122 BOOST_AUTO_TEST_CASE(DiamondBoundsAssignment) {
0123   double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
0124   DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
0125                                     halfY2);
0126   DiamondBounds similarlyConstructeDiamondBoundsObject(
0127       minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0128   /// Test operator ==
0129   BOOST_CHECK_EQUAL(diamondBoundsObject,
0130                     similarlyConstructeDiamondBoundsObject);
0131   //
0132   /// Test assignment
0133   DiamondBounds assignedDiamondBoundsObject(
0134       2 * minHalfX, 2 * midHalfX, 2 * maxHalfX, 2 * halfY1, 2 * halfY2);
0135   // object, in some sense
0136   assignedDiamondBoundsObject = diamondBoundsObject;
0137   BOOST_CHECK_EQUAL(assignedDiamondBoundsObject, diamondBoundsObject);
0138 }
0139 
0140 BOOST_AUTO_TEST_SUITE_END()
0141 
0142 }  // namespace Test
0143 
0144 }  // namespace Acts