Back to home page

EIC code displayed by LXR

 
 

    


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

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/Geometry/GeometryContext.hpp"
0014 #include "Acts/Surfaces/LineBounds.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/StrawSurface.hpp"
0017 #include "Acts/Surfaces/Surface.hpp"
0018 #include "Acts/Tests/CommonHelpers/DetectorElementStub.hpp"
0019 
0020 #include <memory>
0021 #include <string>
0022 
0023 namespace Acts::Test {
0024 
0025 // Create a test context
0026 GeometryContext tgContext = GeometryContext();
0027 
0028 BOOST_AUTO_TEST_SUITE(StrawSurfaces)
0029 
0030 const double radius = 1.;
0031 const double halfZ = 10.;
0032 Translation3 translation{0., 1., 2.};
0033 
0034 /// Unit test for creating compliant/non-compliant StrawSurface object
0035 BOOST_AUTO_TEST_CASE(StrawSurfaceConstruction) {
0036   /// Test default construction
0037   // default construction is deleted
0038 
0039   /// Constructor with transform, radius and halfZ
0040   auto pTransform = Transform3(translation);
0041   BOOST_CHECK_EQUAL(
0042       Surface::makeShared<StrawSurface>(Transform3::Identity(), radius, halfZ)
0043           ->type(),
0044       Surface::Straw);
0045   BOOST_CHECK_EQUAL(
0046       Surface::makeShared<StrawSurface>(pTransform, radius, halfZ)->type(),
0047       Surface::Straw);
0048 
0049   /// Constructor with transform and LineBounds pointer
0050   auto pLineBounds = std::make_shared<const LineBounds>(radius, halfZ);
0051   BOOST_CHECK_EQUAL(
0052       Surface::makeShared<StrawSurface>(pTransform, pLineBounds)->type(),
0053       Surface::Straw);
0054 
0055   /// Constructor with LineBounds ptr, DetectorElement
0056   std::shared_ptr<const Acts::PlanarBounds> p =
0057       std::make_shared<const RectangleBounds>(1., 10.);
0058   DetectorElementStub detElement{pTransform, p, 1., nullptr};
0059   BOOST_CHECK_EQUAL(
0060       Surface::makeShared<StrawSurface>(pLineBounds, detElement)->type(),
0061       Surface::Straw);
0062 
0063   /// Copy constructor
0064   auto strawSurfaceObject =
0065       Surface::makeShared<StrawSurface>(pTransform, radius, halfZ);
0066   auto copiedStrawSurface =
0067       Surface::makeShared<StrawSurface>(*strawSurfaceObject);
0068   BOOST_CHECK_EQUAL(copiedStrawSurface->type(), Surface::Straw);
0069   BOOST_CHECK(*copiedStrawSurface == *strawSurfaceObject);
0070 
0071   /// Copied and transformed
0072   auto copiedTransformedStrawSurface = Surface::makeShared<StrawSurface>(
0073       tgContext, *strawSurfaceObject, pTransform);
0074   BOOST_CHECK_EQUAL(copiedTransformedStrawSurface->type(), Surface::Straw);
0075 }
0076 
0077 /// Unit test for testing StrawSurface properties
0078 BOOST_AUTO_TEST_CASE(StrawSurfaceProperties) {
0079   /// Test clone method
0080   auto pTransform = Transform3(translation);
0081   auto strawSurfaceObject =
0082       Surface::makeShared<StrawSurface>(pTransform, radius, halfZ);
0083 
0084   /// Test type (redundant)
0085   BOOST_CHECK_EQUAL(strawSurfaceObject->type(), Surface::Straw);
0086 
0087   /// Test name
0088   BOOST_CHECK_EQUAL(strawSurfaceObject->name(),
0089                     std::string("Acts::StrawSurface"));
0090 
0091   /// Test dump
0092   boost::test_tools::output_test_stream dumpOutput;
0093   dumpOutput << strawSurfaceObject->toStream(tgContext);
0094   BOOST_CHECK(
0095       dumpOutput.is_equal("Acts::StrawSurface\n\
0096      Center position  (x, y, z) = (0.0000, 1.0000, 2.0000)\n\
0097      Rotation:             colX = (1.000000, 0.000000, 0.000000)\n\
0098                            colY = (0.000000, 1.000000, 0.000000)\n\
0099                            colZ = (0.000000, 0.000000, 1.000000)\n\
0100      Bounds  : Acts::LineBounds: (radius, halflengthInZ) = (1.0000000, 10.0000000)"));
0101 }
0102 
0103 BOOST_AUTO_TEST_CASE(EqualityOperators) {
0104   auto pTransform = Transform3(translation);
0105   auto strawSurfaceObject =
0106       Surface::makeShared<StrawSurface>(pTransform, radius, halfZ);
0107 
0108   auto strawSurfaceObject2 =
0109       Surface::makeShared<StrawSurface>(pTransform, radius, halfZ);
0110 
0111   /// Test equality operator
0112   BOOST_CHECK(*strawSurfaceObject == *strawSurfaceObject2);
0113 
0114   BOOST_TEST_CHECKPOINT(
0115       "Create and then assign a StrawSurface object to the existing one");
0116 
0117   /// Test assignment
0118   auto assignedStrawSurface =
0119       Surface::makeShared<StrawSurface>(Transform3::Identity(), 6.6, 33.33);
0120   *assignedStrawSurface = *strawSurfaceObject;
0121 
0122   /// Test equality of assigned to original
0123   BOOST_CHECK(*assignedStrawSurface == *strawSurfaceObject);
0124 }
0125 
0126 BOOST_AUTO_TEST_SUITE_END()
0127 
0128 }  // namespace Acts::Test