ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BVHDataTestCase.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BVHDataTestCase.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 namespace bdata = boost::unit_test::data;
12 
15 
16 std::tuple<std::vector<const Volume*>, std::shared_ptr<TrackingGeometry>>
17 gridBoxFactory(size_t n = NBOXES, double hl = 1000, size_t octd = 5) {
18  Box::Size size(Acts::ActsVectorD<3>(2, 2, 2));
19 
20  std::shared_ptr<CuboidVolumeBounds> vbds =
21  std::make_shared<CuboidVolumeBounds>(10, 10, 10);
22 
23  double min = -hl;
24  double max = hl;
25 
26  double step = (max - min) / double(n);
27  std::vector<std::unique_ptr<const Volume>> volumes;
28  std::vector<std::unique_ptr<Box>> boxStore;
29  boxStore.reserve((n + 1) * (n + 1) * (n + 1));
30 
31  std::cout << "generating: " << (n + 1) * (n + 1) * (n + 1)
32  << " bounding boxes" << std::endl;
33 
34  std::vector<Box*> boxes;
35  boxes.reserve(boxStore.size());
36 
37  for (size_t i = 0; i <= n; i++) {
38  for (size_t j = 0; j <= n; j++) {
39  for (size_t k = 0; k <= n; k++) {
40  Vector3D pos(min + i * step, min + j * step, min + k * step);
41 
42  auto trf = std::make_shared<Transform3D>(Translation3D(pos));
43  auto vol = std::make_unique<AbstractVolume>(trf, vbds);
44 
45  volumes.push_back(std::move(vol));
46  boxStore.push_back(
47  std::make_unique<Box>(volumes.back()->boundingBox()));
48  boxes.push_back(boxStore.back().get());
49  }
50  }
51  }
52 
53  Box* top = make_octree(boxStore, boxes, octd);
54 
55  // create trackingvolume
56  // will own the volumes, so make non-owning copy first
57  std::vector<const Volume*> volumeCopy;
58  volumeCopy.reserve(volumes.size());
59  for (auto& vol : volumes) {
60  volumeCopy.push_back(vol.get());
61  }
62 
63  // box like overall shape
64  auto tvTrf = std::make_shared<Transform3D>(Transform3D::Identity());
65  auto tvBounds =
66  std::make_shared<CuboidVolumeBounds>(hl * 1.1, hl * 1.1, hl * 1.1);
67 
68  auto tv =
69  TrackingVolume::create(tvTrf, tvBounds, std::move(boxStore),
70  std::move(volumes), top, nullptr, "TheVolume");
71 
72  auto tg = std::make_shared<TrackingGeometry>(tv);
73 
74  return {std::move(volumeCopy), tg};
75 }
76 
77 auto [volumes, tg] = gridBoxFactory();
78 
80  bvhnavigation_test,
81  bdata::random((bdata::seed = 7, bdata::engine = std::mt19937(),
82  bdata::distribution = std::uniform_real_distribution<>(-5,
83  5))) ^
84  bdata::random((bdata::seed = 2, bdata::engine = std::mt19937(),
85  bdata::distribution =
86  std::uniform_real_distribution<>(-M_PI, M_PI))) ^
87  bdata::random((bdata::seed = 3, bdata::engine = std::mt19937(),
88  bdata::distribution =
89  std::uniform_real_distribution<>(-100, 100))) ^
90  bdata::random((bdata::seed = 4, bdata::engine = std::mt19937(),
91  bdata::distribution =
92  std::uniform_real_distribution<>(-100, 100))) ^
93  bdata::random((bdata::seed = 5, bdata::engine = std::mt19937(),
94  bdata::distribution =
95  std::uniform_real_distribution<>(-100, 100))) ^
96  bdata::xrange(NTESTS),
97  eta, phi, x, y, z, index) {
98  using namespace Acts::UnitLiterals;
99  (void)index;
100 
101  // construct ray from parameters
102  double theta = 2 * std::atan(std::exp(-eta));
104  dir << std::cos(phi), std::sin(phi), 1. / std::tan(theta);
105  dir.normalize();
106  Ray ray({x, y, z}, dir);
107 
108  // naive collection: iterate over all the boxes
109  std::vector<SurfaceIntersection> hits;
110  for (const auto& vol : volumes) {
111  const auto& absVol = dynamic_cast<const AbstractVolume&>(*vol);
112  auto bndSurfaces = absVol.boundarySurfaces();
113  // collect all surfaces that are hit
114  for (const auto& bndSrf : bndSurfaces) {
115  const auto& srf = bndSrf->surfaceRepresentation();
116  auto sri = srf.intersect(tgContext, ray.origin(), ray.dir(), true);
117  if (sri and sri.intersection.pathLength >= s_onSurfaceTolerance) {
118  // does intersect
119  hits.push_back(std::move(sri));
120  }
121  }
122  }
123 
124  // sort by path length
125  std::sort(hits.begin(), hits.end());
126  std::vector<const Surface*> expHits;
127  expHits.reserve(hits.size());
128  for (const auto& hit : hits) {
129  expHits.push_back(hit.object);
130  }
131 
132  // now do the same through a propagator
133  using SteppingLogger = Acts::detail::SteppingLogger;
134  using Stepper = StraightLineStepper;
135  using PropagatorType = Propagator<Stepper, Navigator>;
136 
137  Stepper stepper{};
138  Navigator navigator(tg);
139  PropagatorType propagator(std::move(stepper), navigator);
140 
143  using AbortConditions = Acts::AbortList<>;
144 
146  mfContext);
147 
148  options.debug = false;
149  options.pathLimit = 20_m;
150 
151  // this should be irrelevant.
152  double mom = 50_GeV;
153 
154  Acts::CurvilinearParameters startPar(std::nullopt, ray.origin(),
155  ray.dir() * mom, +1, 0.);
156 
157  const auto result = propagator.propagate(startPar, options).value();
158 
159  const auto debugString =
160  result.template get<DebugOutput::result_type>().debugString;
161 
162  if (options.debug) {
163  std::cout << debugString << std::endl;
164  }
165 
166  // collect surfaces
167  std::vector<const Surface*> actHits;
168  auto steppingResults =
169  result.template get<SteppingLogger::result_type>().steps;
170  for (const auto& step : steppingResults) {
171  if (!step.surface) {
172  continue;
173  }
174 
175  auto sensitiveID = step.surface->geoID().sensitive();
176  if (sensitiveID != 0) {
177  actHits.push_back(step.surface.get());
178  }
179  }
180 
181  BOOST_CHECK_EQUAL(expHits.size(), actHits.size());
182  for (size_t i = 0; i < expHits.size(); i++) {
183  const Surface* exp = expHits[i];
184  const Surface* act = actHits[i];
185 
186  BOOST_CHECK_EQUAL(exp, act);
187  BOOST_CHECK_EQUAL(exp->geoID(), act->geoID());
188  }
189 }