9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/unit_test.hpp>
38 #include <type_traits>
44 using namespace Acts::UnitLiterals;
47 using namespace Acts::HashedStringLiteral;
48 using namespace Acts::Test;
54 std::default_random_engine
rng(31415);
60 template <
typename track_container_t,
typename traj_t,
61 template <
typename>
class holder_t>
64 template <
typename track_container_t,
typename traj_t>
66 using track_container_type =
69 track_container_t vtc;
71 track_container_type
tc{vtc,
mtj};
73 auto& trackContainer() {
return tc; }
74 auto& trackStateContainer() {
return mtj; }
78 template <
typename track_container_t,
typename traj_t>
80 using track_container_type =
83 track_container_type
tc{track_container_t{}, traj_t{}};
85 auto& trackContainer() {
return tc; }
86 auto& trackStateContainer() {
return tc.trackStateContainer(); }
87 auto&
backend() {
return tc.container(); }
90 template <
typename track_container_t,
typename traj_t>
91 struct Factory<track_container_t, traj_t, std::shared_ptr> {
92 using track_container_type =
95 std::shared_ptr<track_container_t> vtc{std::make_shared<track_container_t>()};
96 std::shared_ptr<traj_t>
mtj{std::make_shared<traj_t>()};
97 track_container_type
tc{vtc,
mtj};
99 auto& trackContainer() {
return tc; }
100 auto& trackStateContainer() {
return *
mtj; }
101 auto&
backend() {
return *vtc; }
104 template <
typename track_container_t,
typename traj_t,
105 template <
typename>
class... holders>
106 using holder_types_t =
107 std::tuple<Factory<track_container_t, traj_t, holders>...>;
114 using const_holder_types =
116 detail::ValueHolder, detail::RefHolder, std::shared_ptr>;
120 BOOST_AUTO_TEST_SUITE(EventDataTrack)
128 std::is_same_v<decltype(
tc),
131 "Incorrect deduced type");
132 BOOST_CHECK_EQUAL(&
mtj, &
tc.trackStateContainer());
133 BOOST_CHECK_EQUAL(&vtc, &
tc.container());
136 std::decay_t<decltype(tc)> copy =
tc;
137 BOOST_CHECK_EQUAL(&
mtj, ©.trackStateContainer());
138 BOOST_CHECK_EQUAL(&vtc, ©.container());
149 detail::ValueHolder>>,
150 "Incorrect deduced type");
151 std::decay_t<decltype(tc)> copy =
tc;
152 BOOST_CHECK_NE(&
tc.trackStateContainer(), ©.trackStateContainer());
153 BOOST_CHECK_NE(&
tc.container(), ©.container());
161 detail::ValueHolder>>,
162 "Incorrect deduced type");
164 std::decay_t<decltype(tc)> copy =
tc;
165 BOOST_CHECK_NE(&
tc.trackStateContainer(), ©.trackStateContainer());
166 BOOST_CHECK_NE(&
tc.container(), ©.container());
177 std::is_same_v<decltype(
tc),
180 "Incorrect deduced type");
181 BOOST_CHECK_EQUAL(&
mtj, &
tc.trackStateContainer());
182 BOOST_CHECK_EQUAL(&vtc, &
tc.container());
184 std::decay_t<decltype(tc)> copy =
tc;
185 BOOST_CHECK_EQUAL(&
mtj, ©.trackStateContainer());
186 BOOST_CHECK_EQUAL(&vtc, ©.container());
190 auto mtj = std::make_shared<VectorMultiTrajectory>();
191 auto vtc = std::make_shared<VectorTrackContainer>();
196 std::is_same_v<decltype(
tc),
199 "Incorrect deduced type");
200 BOOST_CHECK_EQUAL(
mtj.get(), &
tc.trackStateContainer());
201 BOOST_CHECK_EQUAL(vtc.get(), &
tc.container());
203 std::decay_t<decltype(tc)> copy =
tc;
204 BOOST_CHECK_EQUAL(
mtj.get(), ©.trackStateContainer());
205 BOOST_CHECK_EQUAL(vtc.get(), ©.container());
211 auto&
tc = factory.trackContainer();
213 static_assert(std::is_same_v<std::decay_t<decltype(
tc)>,
214 typename factory_t::track_container_type>,
215 "Incorrect deduction");
217 static_assert(!std::decay_t<decltype(
tc)>::ReadOnly,
218 "Should not be read only");
221 auto idx =
tc.addTrack();
222 auto t =
tc.getTrack(
idx);
224 t.template component<
IndexType,
"tipIndex"_hash>() = 5;
226 BOOST_CHECK_EQUAL((
t.template component<IndexType, "tipIndex"_hash>()), 5);
227 BOOST_CHECK_EQUAL(
t.tipIndex(), 5);
229 BOOST_CHECK_EQUAL(
t.tipIndex(), 6);
233 t.parameters() =
pars;
234 BOOST_CHECK_EQUAL(
t.parameters(),
pars);
238 t.covariance() =
cov;
239 BOOST_CHECK_EQUAL(
t.covariance(),
cov);
241 auto surface = Acts::Surface::makeShared<Acts::PlaneSurface>(
244 t.setReferenceSurface(surface);
245 BOOST_CHECK_EQUAL(surface.get(), &
t.referenceSurface());
250 t.nMeasurements() = 42;
251 BOOST_CHECK_EQUAL(
t2.nMeasurements(), 42);
252 BOOST_CHECK_EQUAL(accNMeasuements(
t), 42);
253 accNMeasuements(
t) = 89;
254 BOOST_CHECK_EQUAL(
t2.nMeasurements(), 89);
261 BOOST_CHECK_EQUAL(
t.nHoles(), 67);
264 BOOST_CHECK_EQUAL(
t.nOutliers(), 68);
266 t2.nSharedHits() = 69;
267 BOOST_CHECK_EQUAL(
t.nSharedHits(), 69);
270 BOOST_CHECK_EQUAL(
t2.chi2(), 555.0);
273 BOOST_CHECK_EQUAL(
t2.nDoF(), 123);
284 auto&
tc = factory.trackContainer();
288 auto mkts = [&](
auto prev) {
289 if constexpr (std::is_same_v<decltype(prev),
IndexType>) {
293 fillTrackState<VectorMultiTrajectory>(pc, TrackStatePropMask::All, ts);
299 fillTrackState<VectorMultiTrajectory>(pc, TrackStatePropMask::All, ts);
305 auto ts2 = mkts(ts1);
306 auto ts3 = mkts(ts2);
307 auto ts4 = mkts(ts3);
308 auto ts5 = mkts(ts4);
310 auto t =
tc.getTrack(
tc.addTrack());
311 t.tipIndex() = ts5.index();
313 std::vector<IndexType> act;
314 for (
const auto& ts :
t.trackStatesReversed()) {
315 act.push_back(ts.index());
318 std::vector<IndexType> exp;
320 std::iota(exp.rbegin(), exp.rend(), 0);
321 BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(), exp.end());
325 for (
const auto& ts : ct.trackStatesReversed()) {
329 BOOST_CHECK_EQUAL(
t.nTrackStates(), 5);
331 auto tNone =
tc.getTrack(
tc.addTrack());
332 BOOST_CHECK_EQUAL(tNone.nTrackStates(), 0);
334 auto tsRange = tNone.trackStatesReversed();
335 BOOST_CHECK(tsRange.begin() == tsRange.end());
338 for (
const auto&
state : tNone.trackStatesReversed()) {
342 BOOST_CHECK_EQUAL(i, 0);
347 auto&
tc = factory.trackContainer();
349 for (
unsigned int i = 0;
i < 10;
i++) {
350 auto t =
tc.getTrack(
tc.addTrack());
353 BOOST_CHECK_EQUAL(
tc.size(), 10);
356 for (
auto track :
tc) {
357 BOOST_CHECK_EQUAL(i, track.tipIndex());
358 track.parameters().setRandom();
362 BOOST_CHECK_EQUAL(
std::distance(tc.begin(), tc.end()), tc.size());
370 for (
unsigned int i = 0;
i < 10;
i++) {
371 auto t =
tc.getTrack(
tc.addTrack());
374 BOOST_CHECK_EQUAL(
tc.size(), 10);
378 auto it =
tc.begin();
379 BOOST_CHECK(*
it ==
tc.getTrack(0));
381 BOOST_CHECK(*it ==
tc.getTrack(1));
383 BOOST_CHECK(*it ==
tc.getTrack(2));
385 BOOST_CHECK(*it ==
tc.getTrack(1));
389 BOOST_CHECK(*it ==
tc.getTrack(2));
392 auto it =
tc.begin();
393 BOOST_CHECK(*
it ==
tc.getTrack(0));
395 BOOST_CHECK(*
it ==
tc.getTrack(4));
396 BOOST_CHECK(*(
it[-1]) ==
tc.getTrack(3));
397 BOOST_CHECK(*(
it[0]) ==
tc.getTrack(4));
398 BOOST_CHECK(*(
it[1]) ==
tc.getTrack(5));
399 BOOST_CHECK(*(
it - 2) ==
tc.getTrack(2));
403 auto it =
tc.begin();
408 BOOST_CHECK(it4 < it5);
409 BOOST_CHECK(it5 < it6);
410 BOOST_CHECK(it4 < it6);
412 BOOST_CHECK(it6 > it5);
413 BOOST_CHECK(it5 > it4);
414 BOOST_CHECK(it6 > it4);
416 BOOST_CHECK(it4 <= it4);
417 BOOST_CHECK(it4 <= it5);
418 BOOST_CHECK(it5 <= it5);
419 BOOST_CHECK(it5 <= it6);
421 BOOST_CHECK(it6 >= it6);
422 BOOST_CHECK(it6 >= it5);
432 for (
unsigned int i = 0;
i < 10;
i++) {
433 auto t =
tc.getTrack(
tc.addTrack());
438 for (
auto track :
tc) {
439 BOOST_CHECK_EQUAL(i, track.tipIndex());
440 track.parameters().setRandom();
444 for (
const auto track : tc) {
457 for (
auto track :
tc) {
458 BOOST_CHECK_EQUAL(i, track.tipIndex());
471 static_assert(!mutTc.ReadOnly,
"Unexpectedly read only");
473 auto t = mutTc.getTrack(mutTc.addTrack());
474 t.appendTrackState();
475 t.appendTrackState();
476 t.appendTrackState();
477 t = mutTc.getTrack(mutTc.addTrack());
478 t.appendTrackState();
480 BOOST_CHECK_EQUAL(mutTc.size(), 2);
481 BOOST_CHECK_EQUAL(mutMtj.
size(), 4);
487 BOOST_CHECK_EQUAL(mutTc.size(), 0);
488 BOOST_CHECK_EQUAL(mutMtj.
size(), 0);
491 static_assert(
ctc.ReadOnly,
"Unexpectedly not read only");
496 BOOST_CHECK_EQUAL(
ctc.size(), 2);
497 BOOST_CHECK_EQUAL(
mtj.
size(), 4);
499 const auto&
cvtc = vtc;
504 BOOST_CHECK_EQUAL(crtc.size(), 2);
517 auto&
tc = factory.trackContainer();
519 static_assert(std::is_same_v<std::decay_t<decltype(
tc)>,
520 typename factory_t::track_container_type>,
521 "Incorrect deduction");
523 static_assert(std::decay_t<decltype(
tc)>::ReadOnly,
"Should be read only");
529 auto&
tc = factory.trackContainer();
531 BOOST_CHECK(!
tc.hasColumn(
"col_a"_hash));
532 tc.template addColumn<float>(
"col_a");
533 BOOST_CHECK(
tc.hasColumn(
"col_a"_hash));
535 auto t =
tc.getTrack(
tc.addTrack());
536 t.template component<float>(
"col_a") = 5.6
f;
537 BOOST_CHECK_EQUAL((t.template component<float, "col_a"_hash>()), 5.6f);
542 tc.addColumn<
size_t>(
"counter");
543 tc.addColumn<
bool>(
"odd");
545 BOOST_CHECK(
tc.hasColumn(
"counter"));
546 BOOST_CHECK(
tc.hasColumn(
"odd"));
550 BOOST_CHECK(!tc2.hasColumn(
"counter"));
551 BOOST_CHECK(!tc2.hasColumn(
"odd"));
553 tc2.ensureDynamicColumns(
tc);
555 BOOST_CHECK(tc2.hasColumn(
"counter"));
556 BOOST_CHECK(tc2.hasColumn(
"odd"));
561 auto t =
tc.getTrack(
tc.addTrack());
563 std::vector<VectorMultiTrajectory::TrackStateProxy> trackStates;
564 trackStates.push_back(
t.appendTrackState());
565 trackStates.push_back(
t.appendTrackState());
566 trackStates.push_back(
t.appendTrackState());
567 trackStates.push_back(
t.appendTrackState());
568 trackStates.push_back(
t.appendTrackState());
569 trackStates.push_back(
t.appendTrackState());
571 BOOST_CHECK_EQUAL(trackStates.size(),
t.nTrackStates());
573 for (
size_t i = trackStates.size() - 1;
i > 0;
i--) {
574 BOOST_CHECK_EQUAL(trackStates.at(
i).index(),
i);
582 auto t =
tc.getTrack(
tc.addTrack());
583 for (std::size_t
i = 0;
i < 10;
i++) {
584 t.appendTrackState();
588 auto t =
tc.getTrack(
tc.addTrack());
590 auto stem =
t.appendTrackState();
591 t.appendTrackState();
592 t.appendTrackState();
593 t.appendTrackState();
594 t.appendTrackState();
596 BOOST_CHECK_THROW(
t.trackStates(), std::invalid_argument);
597 BOOST_CHECK(!
t.innermostTrackState().has_value());
601 BOOST_CHECK_EQUAL(
t.stemIndex(), stem.index());
602 BOOST_CHECK_EQUAL(
t.innermostTrackState().value().index(), stem.index());
603 t.innermostTrackState()->predicted().setRandom();
605 std::vector<IndexType> indices;
606 for (
const auto& ts :
t.trackStatesReversed()) {
607 indices.push_back(ts.index());
610 std::reverse(indices.begin(), indices.end());
612 std::vector<IndexType> act;
613 for (
auto ts :
t.trackStates()) {
614 act.push_back(ts.index());
615 ts.predicted().setRandom();
618 BOOST_CHECK_EQUAL_COLLECTIONS(indices.begin(), indices.end(), act.begin(),
621 t.reverseTrackStates();
622 BOOST_CHECK_EQUAL(
t.innermostTrackState().value().index(), indices.back());
623 t.innermostTrackState()->predicted().setRandom();
626 for (
const auto& ts :
t.trackStates()) {
627 act.push_back(ts.index());
630 BOOST_CHECK_EQUAL_COLLECTIONS(indices.rbegin(), indices.rend(), act.begin(),
636 auto t =
tc.getTrack(
tc.addTrack());
638 auto ts =
t.appendTrackState();
641 ts =
t.appendTrackState();
644 ts =
t.appendTrackState();
648 ts =
t.appendTrackState();
651 ts =
t.appendTrackState();
654 ts =
t.appendTrackState();
657 ts =
t.appendTrackState();
661 ts =
t.appendTrackState();
666 BOOST_CHECK_EQUAL(
t.nHoles(), 2);
667 BOOST_CHECK_EQUAL(
t.nMeasurements(), 3);
668 BOOST_CHECK_EQUAL(
t.nOutliers(), 3);
669 BOOST_CHECK_EQUAL(
t.nSharedHits(), 2);
672 BOOST_AUTO_TEST_SUITE_END()