Back to home page

EIC code displayed by LXR

 
 

    


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

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/EventData/SpacePointContainer.hpp"
0013 #include "Acts/Utilities/HashedString.hpp"
0014 #include "Acts/Utilities/Holders.hpp"
0015 
0016 #include <any>
0017 #include <cmath>
0018 #include <iterator>
0019 #include <ranges>
0020 #include <vector>
0021 
0022 namespace Acts::Test {
0023 
0024 struct SpacePoint {
0025   SpacePoint() = default;
0026   SpacePoint(float ix, float iy, float iz, float ivarR, float ivarZ)
0027       : x(ix), y(iy), z(iz), varR(ivarR), varZ(ivarZ) {}
0028   float x{};
0029   float y{};
0030   float z{};
0031   float varR{};
0032   float varZ{};
0033 };
0034 using SpacePointCollection = std::vector<SpacePoint>;
0035 
0036 class Adapter {
0037  public:
0038   friend Acts::SpacePointContainer<Adapter, Acts::detail::RefHolder>;
0039   friend Acts::SpacePointContainer<Adapter, Acts::detail::ValueHolder>;
0040   using value_type = SpacePoint;
0041   using ValueType = value_type;
0042 
0043   Adapter(SpacePointCollection&&) = delete;
0044   Adapter(const SpacePointCollection& externalCollection)
0045       : m_storage(&externalCollection) {}
0046 
0047  private:
0048   std::size_t size_impl() const { return storage().size(); }
0049 
0050   float x_impl(std::size_t idx) const { return storage()[idx].x; };
0051   float y_impl(std::size_t idx) const { return storage()[idx].y; };
0052   float z_impl(std::size_t idx) const { return storage()[idx].z; };
0053   float varianceR_impl(std::size_t idx) const { return storage()[idx].varR; }
0054   float varianceZ_impl(std::size_t idx) const { return storage()[idx].varZ; }
0055 
0056   const SpacePoint& get_impl(std::size_t idx) const { return storage()[idx]; }
0057 
0058   std::any component_impl(Acts::HashedString key, std::size_t /*n*/) const {
0059     using namespace Acts::HashedStringLiteral;
0060     switch (key) {
0061       case "TopStripVector"_hash:
0062       case "BottomStripVector"_hash:
0063       case "StripCenterDistance"_hash:
0064       case "TopStripCenterPosition"_hash:
0065         return Acts::Vector3(0., 0., 0.);
0066       default:
0067         throw std::runtime_error("no such component " + std::to_string(key));
0068     }
0069   }
0070 
0071   const SpacePointCollection& storage() const { return *m_storage; }
0072 
0073  private:
0074   const SpacePointCollection* m_storage{};
0075 };
0076 
0077 BOOST_AUTO_TEST_CASE(spacepoint_container_edm_traits) {
0078   using adapter_t = Acts::Test::Adapter;
0079   using container_t =
0080       Acts::SpacePointContainer<adapter_t, Acts::detail::RefHolder>;
0081   using proxy_t = Acts::SpacePointProxy<container_t>;
0082   using iterator_t = Acts::ContainerIndexIterator<container_t, proxy_t&, false>;
0083 
0084   static_assert(std::ranges::range<container_t>);
0085   static_assert(std::same_as<typename iterator_t::iterator_category,
0086                              std::random_access_iterator_tag>);
0087   static_assert(
0088       std::same_as<typename std::iterator_traits<iterator_t>::iterator_category,
0089                    std::random_access_iterator_tag>);
0090 }
0091 
0092 BOOST_AUTO_TEST_CASE(spacepoint_container_edm_constructors) {
0093   std::size_t nExternalPoints = 10;
0094   SpacePointCollection externalCollection(nExternalPoints);
0095 
0096   Acts::SpacePointContainerConfig spConfig;
0097   Acts::SpacePointContainerOptions spOptions;
0098 
0099   Acts::Test::Adapter adapterForRef(externalCollection);
0100   Acts::SpacePointContainer<Acts::Test::Adapter, Acts::detail::RefHolder>
0101       spContainerRef(spConfig, spOptions, adapterForRef);
0102 
0103   Acts::SpacePointContainer<Acts::Test::Adapter, Acts::detail::ValueHolder>
0104       spContainerVal(spConfig, spOptions,
0105                      Acts::Test::Adapter(externalCollection));
0106 
0107   BOOST_CHECK_EQUAL(spContainerRef.size(), nExternalPoints);
0108   BOOST_CHECK_EQUAL(spContainerVal.size(), nExternalPoints);
0109 }
0110 
0111 BOOST_AUTO_TEST_CASE(spacepoint_container_edm_functionalities) {
0112   std::size_t nExternalPoints = 100;
0113   SpacePointCollection externalCollection;
0114   externalCollection.reserve(nExternalPoints);
0115   for (std::size_t i = 0; i < nExternalPoints; ++i) {
0116     externalCollection.emplace_back(1.f * i, 1.5f * i, 2.f * i, 2.5f * i,
0117                                     3.f * i);
0118   }
0119 
0120   Acts::SpacePointContainerConfig spConfig;
0121   spConfig.useDetailedDoubleMeasurementInfo = true;
0122   Acts::SpacePointContainerOptions spOptions;
0123 
0124   Acts::Test::Adapter adapter(externalCollection);
0125   Acts::SpacePointContainer<Acts::Test::Adapter, Acts::detail::RefHolder>
0126       spContainer(spConfig, spOptions, adapter);
0127 
0128   BOOST_CHECK_EQUAL(spContainer.size(), nExternalPoints);
0129   BOOST_CHECK_EQUAL(spContainer.size(), externalCollection.size());
0130   BOOST_CHECK_EQUAL(spContainer.end() - spContainer.begin(), nExternalPoints);
0131   BOOST_CHECK_EQUAL(std::distance(spContainer.begin(), spContainer.end()),
0132                     nExternalPoints);
0133   BOOST_CHECK_EQUAL(std::distance(std::ranges::begin(spContainer),
0134                                   std::ranges::end(spContainer)),
0135                     nExternalPoints);
0136 
0137   using proxy_t = Acts::SpacePointProxy<
0138       Acts::SpacePointContainer<Acts::Test::Adapter, Acts::detail::RefHolder>>;
0139   static_assert(std::same_as<typename decltype(spContainer)::ValueType,
0140                              Acts::Test::SpacePoint>);
0141   static_assert(
0142       std::same_as<typename decltype(spContainer)::ProxyType, proxy_t>);
0143   static_assert(
0144       std::same_as<typename decltype(spContainer)::value_type, proxy_t>);
0145   static_assert(
0146       std::same_as<typename proxy_t::ContainerType, decltype(spContainer)>);
0147   static_assert(
0148       std::same_as<typename proxy_t::ValueType, Acts::Test::SpacePoint>);
0149 
0150   using iterator_t =
0151       Acts::ContainerIndexIterator<decltype(spContainer), proxy_t&, false>;
0152   using const_iterator_t =
0153       Acts::ContainerIndexIterator<decltype(spContainer), const proxy_t&, true>;
0154   static_assert(
0155       std::same_as<iterator_t, typename decltype(spContainer)::iterator>);
0156   static_assert(std::same_as<const_iterator_t,
0157                              typename decltype(spContainer)::const_iterator>);
0158   static_assert(
0159       std::same_as<iterator_t, decltype(std::ranges::begin(spContainer))>);
0160   static_assert(std::same_as<const_iterator_t,
0161                              decltype(std::ranges::cbegin(spContainer))>);
0162 
0163   std::size_t n = 0ul;
0164   for (const proxy_t& proxy : spContainer) {
0165     float refX = 1.f * n;
0166     float refY = 1.5f * n;
0167     float refZ = 2.f * n;
0168     float refCovR = 2.5f * n;
0169     float refCovZ = 3.f * n;
0170     float refRadius = std::hypot(refX, refY);
0171     float refPhi = std::atan2(refY, refX);
0172 
0173     BOOST_CHECK_EQUAL(proxy.index(), n);
0174     BOOST_CHECK_EQUAL(proxy.x(), refX);
0175     BOOST_CHECK_EQUAL(proxy.y(), refY);
0176     BOOST_CHECK_EQUAL(proxy.z(), refZ);
0177     BOOST_CHECK_EQUAL(proxy.radius(), refRadius);
0178     BOOST_CHECK_EQUAL(proxy.phi(), refPhi);
0179     BOOST_CHECK_EQUAL(proxy.varianceR(), refCovR);
0180     BOOST_CHECK_EQUAL(proxy.varianceZ(), refCovZ);
0181 
0182     const Acts::Vector3& topStripVector = proxy.topStripVector();
0183     const Acts::Vector3& bottomStripVector = proxy.bottomStripVector();
0184     const Acts::Vector3& stripCenterDistance = proxy.stripCenterDistance();
0185     const Acts::Vector3& topStripCenterPosition =
0186         proxy.topStripCenterPosition();
0187 
0188     for (std::size_t i = 0; i < 3; ++i) {
0189       BOOST_CHECK_EQUAL(topStripVector[i], 0.);
0190       BOOST_CHECK_EQUAL(bottomStripVector[i], 0.);
0191       BOOST_CHECK_EQUAL(stripCenterDistance[i], 0.);
0192       BOOST_CHECK_EQUAL(topStripCenterPosition[i], 0.);
0193     }
0194 
0195     const Acts::Test::SpacePoint& sp = proxy.externalSpacePoint();
0196     BOOST_CHECK_EQUAL(&sp, &externalCollection[n]);
0197 
0198     ++n;
0199   }
0200   BOOST_CHECK_EQUAL(n, nExternalPoints);
0201 }
0202 
0203 }  // namespace Acts::Test