Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KdtSurfacesProviderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KdtSurfacesProviderTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
14 #include "Acts/Geometry/Extent.hpp"
21 
22 #include <algorithm>
23 #include <cstddef>
24 #include <iterator>
25 #include <memory>
26 #include <utility>
27 #include <vector>
28 
29 using namespace Acts;
30 using namespace Acts::Test;
31 using namespace Acts::Experimental;
32 
35 
36 namespace {
40 std::vector<std::shared_ptr<Acts::Surface>> unpackSurfaces(
41  const std::vector<const Acts::Surface*>& surfaces) {
42  std::vector<std::shared_ptr<Acts::Surface>> uSurfaces;
43  uSurfaces.reserve(surfaces.size());
44  for (const auto& s : surfaces) {
45  Surface* ncs = const_cast<Surface*>(s);
46  uSurfaces.push_back(ncs->getSharedPtr());
47  }
48  return uSurfaces;
49 }
50 
51 std::vector<std::shared_ptr<Acts::Surface>> pixelSurfaces(
53  // The surfaces for the KDTree structure
54  std::vector<std::shared_ptr<Acts::Surface>> pixelSurfaces;
55  // Fill Discs
56  std::vector<Acts::ActsScalar> pixelDiscs = {-800., -700., -600.,
57  600., 700., 800.};
58  for (const auto& z : pixelDiscs) {
59  auto rSurfaces = cGeometry.surfacesRing(dStore, 6.4, 12.4, 36., 0.125, 0.,
60  55., z, 2., 22u);
61  auto urSurfaces = unpackSurfaces(rSurfaces);
62  pixelSurfaces.insert(pixelSurfaces.end(), urSurfaces.begin(),
63  urSurfaces.end());
64  }
65  // Fill Barrels
66  std::vector<Acts::ActsScalar> pixelBarrels = {32., 72., 116., 172.};
67  std::vector<std::pair<int, int>> pixelBinning = {
68  {16, 14}, {32, 14}, {52, 14}, {78, 14}};
69  for (auto [ir, r] : enumerate(pixelBarrels)) {
70  auto cSurfaces = cGeometry.surfacesCylinder(dStore, 8.4, 36., 0.15, 0.145,
71  r, 3., 2., pixelBinning[ir]);
72 
73  auto ucSurfaces = unpackSurfaces(cSurfaces);
74  pixelSurfaces.insert(pixelSurfaces.end(), ucSurfaces.begin(),
75  ucSurfaces.end());
76  }
77  return pixelSurfaces;
78 }
79 
80 } // namespace
81 
82 BOOST_AUTO_TEST_SUITE(Detector)
83 
84 // Test only the KDT infrastructure
85 BOOST_AUTO_TEST_CASE(KdtSurfacesProvider_misconfigured) {
86  Acts::Extent region;
87  BOOST_CHECK_THROW(
88  Acts::Experimental::KdtSurfacesProvider<> end3(nullptr, region),
89  std::invalid_argument);
90 }
91 
92 // Test only the KDT infrastructure
94  // Detector store
96  auto pSurfaces = pixelSurfaces(dStore);
97  // Count the number of surfacees
98  size_t refNumber = 6u * 22u + 14u * (16u + 32u + 52u + 78u);
99  BOOST_CHECK(pSurfaces.size() == refNumber);
100 
102  auto skdt = std::make_shared<KDTS>(KDTS(tContext, pSurfaces, {binZ, binR}));
103 
104  // query: Negative disc 3, it should yield 22 surfaces
105  Acts::Extent regionND3;
106  regionND3.set(binZ, -820, -780);
107  regionND3.set(binR, 0., 200.);
108  Acts::Experimental::KdtSurfacesProvider<> end3(skdt, regionND3);
109 
110  auto nd3 = end3.surfaces(tContext);
111  BOOST_CHECK(nd3.size() == 22u);
112 
113  // query: 2nd Pixel barrel
114  Acts::Extent regionB1;
115  regionB1.set(binZ, -580, 580);
116  regionB1.set(binR, 60., 80.);
117 
118  Acts::Experimental::KdtSurfacesProvider<> ba1(skdt, regionB1);
119 
120  auto b1 = ba1.surfaces(tContext);
121  refNumber = 32u * 14u;
122  BOOST_CHECK(b1.size() == refNumber);
123 }
124 
125 BOOST_AUTO_TEST_SUITE_END()