Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-20 07:53:21

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/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/AnnulusBounds.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/ConeBounds.hpp"
0015 #include "Acts/Surfaces/CylinderBounds.hpp"
0016 #include "Acts/Surfaces/DiamondBounds.hpp"
0017 #include "Acts/Surfaces/DiscTrapezoidBounds.hpp"
0018 #include "Acts/Surfaces/EllipseBounds.hpp"
0019 #include "Acts/Surfaces/LineBounds.hpp"
0020 #include "Acts/Surfaces/RadialBounds.hpp"
0021 #include "Acts/Surfaces/RectangleBounds.hpp"
0022 #include "Acts/Surfaces/SurfaceBounds.hpp"
0023 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0024 
0025 #include <cstddef>
0026 #include <iomanip>
0027 #include <memory>
0028 #include <numbers>
0029 #include <numeric>
0030 #include <ostream>
0031 #include <sstream>
0032 #include <vector>
0033 
0034 namespace Acts {
0035 
0036 /// Class to implement pure virtual method of SurfaceBounds for testing only
0037 class SurfaceBoundsStub : public SurfaceBounds {
0038  public:
0039   /// Implement ctor and pure virtual methods of SurfaceBounds
0040   explicit SurfaceBoundsStub(std::size_t nValues = 0) : m_values(nValues, 0) {
0041     std::iota(m_values.begin(), m_values.end(), 0);
0042   }
0043 
0044 #if defined(__GNUC__) && (__GNUC__ == 13 || __GNUC__ == 14) && \
0045     !defined(__clang__)
0046 #pragma GCC diagnostic push
0047 #pragma GCC diagnostic ignored "-Warray-bounds"
0048 #pragma GCC diagnostic ignored "-Wstringop-overflow"
0049 #endif
0050   SurfaceBoundsStub(const SurfaceBoundsStub& other) = default;
0051   SurfaceBoundsStub& operator=(const SurfaceBoundsStub& other) = default;
0052 #if defined(__GNUC__) && (__GNUC__ == 13 || __GNUC__ == 14) && \
0053     !defined(__clang__)
0054 #pragma GCC diagnostic pop
0055 #endif
0056 
0057   BoundsType type() const final { return eOther; }
0058 
0059   bool isCartesian() const final { return true; }
0060 
0061   SquareMatrix2 boundToCartesianJacobian(const Vector2& lposition) const final {
0062     static_cast<void>(lposition);
0063     return SquareMatrix2::Identity();
0064   }
0065 
0066   SquareMatrix2 boundToCartesianMetric(const Vector2& lposition) const final {
0067     static_cast<void>(lposition);
0068     return SquareMatrix2::Identity();
0069   }
0070 
0071   std::vector<double> values() const final { return m_values; }
0072 
0073   bool inside(const Vector2& lposition) const final {
0074     static_cast<void>(lposition);
0075     return true;
0076   }
0077 
0078   Vector2 closestPoint(const Vector2& lposition,
0079                        const SquareMatrix2& metric) const final {
0080     static_cast<void>(metric);
0081     return lposition;
0082   }
0083 
0084   Vector2 center() const final { return Vector2(0.0, 0.0); }
0085 
0086   bool inside(const Vector2& lposition,
0087               const BoundaryTolerance& boundaryTolerance) const final {
0088     static_cast<void>(lposition);
0089     static_cast<void>(boundaryTolerance);
0090     return true;
0091   }
0092 
0093   std::ostream& toStream(std::ostream& sl) const final {
0094     sl << "SurfaceBoundsStub";
0095     return sl;
0096   }
0097 
0098  private:
0099   std::vector<double> m_values;
0100 };
0101 
0102 }  // namespace Acts
0103 
0104 using namespace Acts;
0105 
0106 namespace ActsTests {
0107 
0108 namespace {
0109 
0110 struct StreamState {
0111   std::ios_base::fmtflags flags;
0112   std::streamsize precision;
0113   std::streamsize width;
0114   char fill;
0115 };
0116 
0117 StreamState setNonDefaultStreamState(std::ostringstream& stream) {
0118   stream << std::scientific << std::showpos << std::setfill('#')
0119          << std::setprecision(3);
0120   stream.width(17);
0121   return {stream.flags(), stream.precision(), stream.width(), stream.fill()};
0122 }
0123 
0124 void checkStreamState(const std::ostringstream& stream,
0125                       const StreamState& state) {
0126   BOOST_CHECK(stream.flags() == state.flags);
0127   BOOST_CHECK_EQUAL(stream.precision(), state.precision);
0128   BOOST_CHECK_EQUAL(stream.width(), state.width);
0129   BOOST_CHECK_EQUAL(stream.fill(), state.fill);
0130 }
0131 
0132 void checkStreamStatePreserved(const SurfaceBounds& bounds) {
0133   std::ostringstream stream;
0134   const auto state = setNonDefaultStreamState(stream);
0135 
0136   bounds.toStream(stream);
0137 
0138   checkStreamState(stream, state);
0139 }
0140 
0141 }  // namespace
0142 
0143 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0144 
0145 /// Unit test for creating compliant/non-compliant SurfaceBounds object
0146 BOOST_AUTO_TEST_CASE(SurfaceBoundsConstruction) {
0147   SurfaceBoundsStub u;
0148   SurfaceBoundsStub s(1);  // would act as std::size_t cast to SurfaceBounds
0149   SurfaceBoundsStub t(s);
0150   SurfaceBoundsStub v(u);
0151 }
0152 
0153 BOOST_AUTO_TEST_CASE(SurfaceBoundsProperties) {
0154   SurfaceBoundsStub surface(5);
0155   std::vector<double> reference{0, 1, 2, 3, 4};
0156   const auto& boundValues = surface.values();
0157   BOOST_CHECK_EQUAL_COLLECTIONS(reference.cbegin(), reference.cend(),
0158                                 boundValues.cbegin(), boundValues.cend());
0159 }
0160 
0161 /// Unit test for testing SurfaceBounds properties
0162 BOOST_AUTO_TEST_CASE(SurfaceBoundsEquality) {
0163   SurfaceBoundsStub surface(1);
0164   SurfaceBoundsStub copiedSurface(surface);
0165   SurfaceBoundsStub differentSurface(2);
0166   BOOST_CHECK_EQUAL(surface, copiedSurface);
0167   BOOST_CHECK_NE(surface, differentSurface);
0168 
0169   SurfaceBoundsStub assignedSurface;
0170   assignedSurface = surface;
0171   BOOST_CHECK_EQUAL(surface, assignedSurface);
0172 
0173   const auto& surfaceboundValues = surface.values();
0174   const auto& assignedboundValues = assignedSurface.values();
0175   BOOST_CHECK_EQUAL_COLLECTIONS(
0176       surfaceboundValues.cbegin(), surfaceboundValues.cend(),
0177       assignedboundValues.cbegin(), assignedboundValues.cend());
0178 }
0179 
0180 BOOST_AUTO_TEST_CASE(SurfaceBoundsToStreamPreservesStreamState) {
0181   std::vector<std::unique_ptr<SurfaceBounds>> bounds;
0182   bounds.push_back(
0183       std::make_unique<AnnulusBounds>(7.2, 12., 0.7, 1.3, Vector2{-2., 2.}));
0184   bounds.push_back(std::make_unique<ConeBounds>(std::numbers::pi / 8., 3., 6.));
0185   bounds.push_back(std::make_unique<CylinderBounds>(0.5, 10.));
0186   bounds.push_back(std::make_unique<DiamondBounds>(10., 20., 15., 5., 7.));
0187   bounds.push_back(std::make_unique<DiscTrapezoidBounds>(1., 5., 2., 6., 0.));
0188   bounds.push_back(std::make_unique<EllipseBounds>(1., 2., 3., 4.,
0189                                                    std::numbers::pi / 2., 0.));
0190   bounds.push_back(std::make_unique<LineBounds>(0.5, 20.));
0191   bounds.push_back(std::make_unique<RadialBounds>(1., 5.));
0192   bounds.push_back(std::make_unique<RectangleBounds>(10., 5.));
0193   bounds.push_back(std::make_unique<TrapezoidBounds>(1., 6., 2.));
0194 
0195   for (const auto& bound : bounds) {
0196     checkStreamStatePreserved(*bound);
0197   }
0198 }
0199 
0200 BOOST_AUTO_TEST_SUITE_END()
0201 
0202 }  // namespace ActsTests