Analysis Software
Documentation for sPHENIX simulation 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 #pragma once
10 
12 
13 namespace bdata = boost::unit_test::data;
16 
19 
20 Test::CubicBVHTrackingGeometry grid(NBOXES, 1000, 5);
21 
22 auto volumes = grid.volumes;
23 auto tg = grid.trackingGeometry;
24 
26  bvhnavigation_test,
27  bdata::random((bdata::seed = 7, bdata::engine = std::mt19937(),
28  bdata::distribution = std::uniform_real_distribution<>(-5,
29  5))) ^
30  bdata::random((bdata::seed = 2, bdata::engine = std::mt19937(),
31  bdata::distribution =
32  std::uniform_real_distribution<>(-M_PI, M_PI))) ^
33  bdata::random((bdata::seed = 3, bdata::engine = std::mt19937(),
34  bdata::distribution =
35  std::uniform_real_distribution<>(-100, 100))) ^
36  bdata::random((bdata::seed = 4, bdata::engine = std::mt19937(),
37  bdata::distribution =
38  std::uniform_real_distribution<>(-100, 100))) ^
39  bdata::random((bdata::seed = 5, bdata::engine = std::mt19937(),
40  bdata::distribution =
41  std::uniform_real_distribution<>(-100, 100))) ^
42  bdata::xrange(NTESTS),
43  eta, phi, x, y, z, index) {
44  using namespace Acts::UnitLiterals;
45  (void)index;
46 
47  // construct ray from parameters
48  double theta = 2 * std::atan(std::exp(-eta));
49  Acts::Vector3 dir;
50  dir << std::cos(phi), std::sin(phi), 1. / std::tan(theta);
51  dir.normalize();
52  Ray ray({x, y, z}, dir);
53 
54  // naive collection: iterate over all the boxes
55  std::vector<SurfaceIntersection> hits;
56  for (const auto& vol : volumes) {
57  const auto& absVol = dynamic_cast<const AbstractVolume&>(*vol);
58  auto bndSurfaces = absVol.boundarySurfaces();
59  // collect all surfaces that are hit
60  for (const auto& bndSrf : bndSurfaces) {
61  const auto& srf = bndSrf->surfaceRepresentation();
62  auto srmi = srf.intersect(tgContext, ray.origin(), ray.dir(), true);
63  for (const auto& sri : srmi.split()) {
64  if (sri and sri.pathLength() >= s_onSurfaceTolerance) {
65  // does intersect
66  hits.push_back(sri);
67  }
68  }
69  }
70  }
71 
72  // sort by path length
73  std::sort(hits.begin(), hits.end(), SurfaceIntersection::forwardOrder);
74  std::vector<const Surface*> expHits;
75  expHits.reserve(hits.size());
76  for (const auto& hit : hits) {
77  expHits.push_back(hit.object());
78  }
79 
80  // now do the same through a propagator
81  using SteppingLogger = Acts::detail::SteppingLogger;
82  using Stepper = StraightLineStepper;
83  using PropagatorType = Propagator<Stepper, Navigator>;
84 
85  Stepper stepper{};
86  Navigator navigator({tg});
87  PropagatorType propagator(stepper, navigator);
88 
89  using ActionList = Acts::ActionList<SteppingLogger>;
90  using AbortConditions = Acts::AbortList<>;
91 
93  mfContext);
94 
95  options.pathLimit = 20_m;
96 
97  Acts::Vector4 pos4 = Acts::Vector4::Zero();
98  pos4.segment<3>(Acts::ePos0) = ray.origin();
99  // momentum value should be irrelevant.
101  pos4, ray.dir(), 1_e / 50_GeV, std::nullopt, ParticleHypothesis::pion());
102 
103  const auto result = propagator.propagate(startPar, options).value();
104 
105  // collect surfaces
106  std::vector<const Surface*> actHits;
107  auto steppingResults =
108  result.template get<SteppingLogger::result_type>().steps;
109  for (const auto& step : steppingResults) {
110  if (!step.surface) {
111  continue;
112  }
113 
114  auto sensitiveID = step.surface->geometryId().sensitive();
115  if (sensitiveID != 0) {
116  actHits.push_back(step.surface.get());
117  }
118  }
119 
120  BOOST_CHECK_EQUAL(expHits.size(), actHits.size());
121  for (size_t i = 0; i < expHits.size(); i++) {
122  const Surface* exp = expHits[i];
123  const Surface* act = actHits[i];
124 
125  BOOST_CHECK_EQUAL(exp, act);
126  BOOST_CHECK_EQUAL(exp->geometryId(), act->geometryId());
127  }
128 }