Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiTrajectoryTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MultiTrajectoryTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2020 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/data/test_case.hpp>
10 #include <boost/test/tools/context.hpp>
11 #include <boost/test/unit_test.hpp>
12 
26 
27 #include <algorithm>
28 #include <array>
29 #include <ostream>
30 #include <random>
31 #include <stdexcept>
32 #include <string>
33 #include <type_traits>
34 #include <utility>
35 #include <variant>
36 #include <vector>
37 
38 namespace {
39 
40 using namespace Acts;
41 using namespace Acts::UnitLiterals;
42 using namespace Acts::Test;
43 namespace bd = boost::unit_test::data;
44 
45 using ParametersVector = BoundTrackParameters::ParametersVector;
46 using CovarianceMatrix = BoundTrackParameters::CovarianceMatrix;
47 using Jacobian = BoundMatrix;
48 
49 const GeometryContext gctx;
50 // fixed seed for reproducible tests
51 std::default_random_engine rng(31415);
52 
53 struct Factory {
54  using trajectory_t = VectorMultiTrajectory;
55  using const_trajectory_t = ConstVectorMultiTrajectory;
56 
57  VectorMultiTrajectory create() { return {}; }
58  ConstVectorMultiTrajectory createConst() { return {}; }
59 };
60 
61 using CommonTests = MultiTrajectoryTestsCommon<Factory>;
62 
63 } // namespace
64 
65 BOOST_AUTO_TEST_SUITE(EventDataMultiTrajectory)
66 
68  CommonTests ct;
69  ct.testBuild();
70 }
71 
72 BOOST_AUTO_TEST_CASE(ConstCorrectness) {
73  // make mutable
75  auto i0 = t.addTrackState();
76 
77  BOOST_CHECK(!t.ReadOnly);
78 
79  {
81  static_cast<void>(tsp);
83  static_cast<void>(ctsp);
84 
85  tsp.predicted().setRandom();
86  // const auto& tsp_const = tsp;
87  // tsp_const.predicted().setRandom();
88  // ctsp.predicted().setRandom();
89  }
90 
91  // is this something we actually want?
93  BOOST_CHECK_EQUAL(ct.size(), t.size());
94 
96  BOOST_CHECK_EQUAL(ctm.size(), ct.size());
97 
98  {
99  static_assert(
101  decltype(ctm.getTrackState(i0))>,
102  "Got mutable track state proxy");
104  ctm.getTrackState(i0);
105  static_cast<void>(ctsp);
106 
107  // doesn't compile:
108  // ctsp.predictedCovariance().setIdentity();
109  }
110 
111  // doesn't compile:
112  // ct.clear();
113  // ct.addTrackState();
114 }
115 
117  CommonTests ct;
118  ct.testClear();
119 }
120 
121 BOOST_AUTO_TEST_CASE(ApplyWithAbort) {
122  CommonTests ct;
123  ct.testApplyWithAbort();
124 }
125 
126 BOOST_AUTO_TEST_CASE(AddTrackStateWithBitMask) {
127  CommonTests ct;
128  ct.testAddTrackStateWithBitMask();
129 }
130 
131 // assert expected "cross-talk" between trackstate proxies
132 BOOST_AUTO_TEST_CASE(TrackStateProxyCrossTalk) {
133  CommonTests ct;
134  ct.testTrackStateProxyCrossTalk(rng);
135 }
136 
137 BOOST_AUTO_TEST_CASE(TrackStateReassignment) {
138  CommonTests ct;
139  ct.testTrackStateReassignment(rng);
140 }
141 
142 BOOST_DATA_TEST_CASE(TrackStateProxyStorage, bd::make({1u, 2u}),
143  nMeasurements) {
144  CommonTests ct;
145  ct.testTrackStateProxyStorage(rng, nMeasurements);
146 }
147 
148 BOOST_AUTO_TEST_CASE(TrackStateProxyAllocations) {
149  CommonTests ct;
150  ct.testTrackStateProxyAllocations(rng);
151 }
152 
153 BOOST_AUTO_TEST_CASE(TrackStateProxyGetMask) {
154  CommonTests ct;
155  ct.testTrackStateProxyGetMask();
156 }
157 
158 BOOST_AUTO_TEST_CASE(TrackStateProxyCopy) {
159  CommonTests ct;
160  ct.testTrackStateProxyCopy(rng);
161 }
162 
163 BOOST_AUTO_TEST_CASE(TrackStateProxyCopyDiffMTJ) {
164  CommonTests ct;
165  ct.testTrackStateProxyCopyDiffMTJ();
166 }
167 
168 BOOST_AUTO_TEST_CASE(ProxyAssignment) {
169  CommonTests ct;
170  ct.testProxyAssignment();
171 }
172 
173 BOOST_AUTO_TEST_CASE(CopyFromConst) {
174  CommonTests ct;
175  ct.testCopyFromConst();
176 }
177 
178 BOOST_AUTO_TEST_CASE(TrackStateProxyShare) {
179  CommonTests ct;
180  ct.testTrackStateProxyShare(rng);
181 }
182 
183 BOOST_AUTO_TEST_CASE(MultiTrajectoryExtraColumns) {
184  CommonTests ct;
185  ct.testMultiTrajectoryExtraColumns();
186 }
187 
188 BOOST_AUTO_TEST_CASE(MultiTrajectoryExtraColumnsRuntime) {
189  CommonTests ct;
190  ct.testMultiTrajectoryExtraColumnsRuntime();
191 }
192 
193 BOOST_AUTO_TEST_CASE(MemoryStats) {
194  using namespace boost::histogram;
195  using cat = axis::category<std::string>;
196 
198 
199  auto stats = mt.statistics();
200 
201  std::stringstream ss;
202  stats.toStream(ss);
203  std::string out = ss.str();
204  BOOST_CHECK(!out.empty());
205  BOOST_CHECK(out.find("total") != std::string::npos);
206 
207  const auto& h = stats.hist;
208 
209  auto column_axis = axis::get<cat>(h.axis(0));
210  auto type_axis = axis::get<axis::category<>>(h.axis(1));
211 
212  for (int t = 0; t < type_axis.size(); t++) {
213  for (int c = 0; c < column_axis.size(); c++) {
214  double v = h.at(c, t);
215  BOOST_CHECK_EQUAL(v, 0.0);
216  }
217  }
218 
219  TestTrackState pc(rng, 2u);
220  auto ts = mt.getTrackState(mt.addTrackState());
221  fillTrackState<VectorMultiTrajectory>(pc, TrackStatePropMask::All, ts);
222 
223  stats = mt.statistics();
224 
225  for (int t = 0; t < type_axis.size(); t++) {
226  BOOST_TEST_CONTEXT((type_axis.bin(t) == 1 ? "meas" : "other"))
227  for (int c = 0; c < column_axis.size(); c++) {
228  std::string key = column_axis.bin(c);
229  BOOST_TEST_CONTEXT("column: " << key) {
230  double v = h.at(c, t);
231  if (t == 0) {
232  BOOST_CHECK_NE(v, 0.0);
233  } else {
234  BOOST_CHECK_EQUAL(v, 0.0);
235  }
236  }
237  }
238  }
239 }
240 
241 BOOST_AUTO_TEST_SUITE_END()