Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-12 09:43:39

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