9 #include <boost/test/unit_test.hpp>
50 std::optional<Measurement<SourceLink, BoundIndices, eBoundLoc0, eBoundLoc1>>
70 template <
typename track_state_t>
73 auto plane = Surface::makeShared<PlaneSurface>(
Vector3D{0., 0., 0.},
76 std::unique_ptr<FittableMeasurement<SourceLink>>
fm;
86 meas{
plane, {}, mCov, mPar[0], mPar[1], mPar[2]};
88 fm = std::make_unique<FittableMeasurement<SourceLink>>(meas);
93 ts.uncalibrated() = sourceLink;
97 pc.
meas3d = {meas.referenceObject().getSharedPtr(),
100 meas.parameters()[0],
101 meas.parameters()[1],
102 meas.parameters()[2]};
104 ts.setCalibrated(*pc.
meas3d);
106 }
else if (
dim == 2) {
113 plane, {}, mCov, mPar[0], mPar[1]};
115 fm = std::make_unique<FittableMeasurement<SourceLink>>(meas);
120 ts.uncalibrated() = sourceLink;
124 pc.
meas2d = {meas.referenceObject().getSharedPtr(), sourceLink,
125 meas.covariance(), meas.parameters()[0], meas.parameters()[1]};
127 ts.setCalibrated(*pc.
meas2d);
130 throw std::runtime_error(
"wrong dim");
137 predPar << 1, 2,
M_PI / 4.,
M_PI / 2., 5, 0.;
138 predPar.template head<2>().setRandom();
147 ts.predictedCovariance() = *pred.
covariance();
152 filtPar << 6, 7,
M_PI / 4.,
M_PI / 2., 10, 0.;
153 filtPar.template head<2>().setRandom();
167 smotPar << 11, 12,
M_PI / 4.,
M_PI / 2., 15, 0.;
168 smotPar.template head<2>().setRandom();
188 std::random_device rd;
189 std::mt19937 gen(rd());
190 std::uniform_real_distribution<> dis(1.0, 100.0);
196 return std::make_tuple(pc, std::move(fm));
212 std::vector<size_t> act;
213 auto collect = [&](
auto p) {
214 act.push_back(
p.index());
215 BOOST_CHECK(!
p.hasUncalibrated());
216 BOOST_CHECK(!
p.hasCalibrated());
217 BOOST_CHECK(!
p.hasFiltered());
218 BOOST_CHECK(!
p.hasSmoothed());
219 BOOST_CHECK(!
p.hasJacobian());
220 BOOST_CHECK(!
p.hasProjector());
223 std::vector<size_t> exp = {i2a, i1a, i0};
225 BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(), exp.end());
228 exp = {i2b, i1b, i0};
230 BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(), exp.end());
234 BOOST_CHECK_EQUAL_COLLECTIONS(act.begin(), act.end(), exp.begin(), exp.end());
251 BOOST_CHECK_EQUAL(n, 1
u);
256 if (ts.index() == i1) {
261 BOOST_CHECK_EQUAL(n, 2
u);
268 BOOST_CHECK_EQUAL(n, 3
u);
273 auto bs1 = PM::Uncalibrated;
278 auto bs2 = PM::Calibrated;
283 auto bs3 = PM::Calibrated | PM::Uncalibrated;
291 auto bs4 = PM::Predicted |
PM::Jacobian | PM::Uncalibrated;
299 auto cnv = [](
auto a) -> std::bitset<8> {
300 return static_cast<std::underlying_type<PM>::type
>(a);
303 BOOST_CHECK(cnv(PM::All).all());
304 BOOST_CHECK(cnv(PM::None).none());
307 std::array<PM, 6>
values{PM::Predicted, PM::Filtered, PM::Smoothed,
309 for (
size_t i = 0; i <
values.size(); i++) {
310 for (
size_t j = 0; j <
values.size(); j++) {
315 BOOST_CHECK(cnv(a & b).count() == 1);
317 BOOST_CHECK(cnv(a & b).none());
322 BOOST_CHECK(cnv(PM::Predicted ^ PM::Filtered).count() == 2);
323 BOOST_CHECK(cnv(PM::Predicted ^ PM::Predicted).none());
324 BOOST_CHECK(~(PM::Predicted | PM::Calibrated) ==
325 (PM::All ^ PM::Predicted ^ PM::Calibrated));
328 BOOST_CHECK(cnv(base) == 0);
330 base &= PM::Filtered;
331 BOOST_CHECK(cnv(base) == 0);
333 base |= PM::Filtered;
334 BOOST_CHECK(base == PM::Filtered);
336 base |= PM::Calibrated;
337 BOOST_CHECK(base == (PM::Filtered | PM::Calibrated));
340 BOOST_CHECK(base == ~(PM::Filtered | PM::Calibrated));
348 BOOST_CHECK(ts.hasPredicted());
349 BOOST_CHECK(ts.hasFiltered());
350 BOOST_CHECK(ts.hasSmoothed());
351 BOOST_CHECK(ts.hasUncalibrated());
352 BOOST_CHECK(ts.hasCalibrated());
353 BOOST_CHECK(ts.hasProjector());
354 BOOST_CHECK(ts.hasJacobian());
357 BOOST_CHECK(!ts.hasPredicted());
358 BOOST_CHECK(!ts.hasFiltered());
359 BOOST_CHECK(!ts.hasSmoothed());
360 BOOST_CHECK(!ts.hasUncalibrated());
361 BOOST_CHECK(!ts.hasCalibrated());
362 BOOST_CHECK(!ts.hasProjector());
363 BOOST_CHECK(!ts.hasJacobian());
366 BOOST_CHECK(ts.hasPredicted());
367 BOOST_CHECK(!ts.hasFiltered());
368 BOOST_CHECK(!ts.hasSmoothed());
369 BOOST_CHECK(!ts.hasUncalibrated());
370 BOOST_CHECK(!ts.hasCalibrated());
371 BOOST_CHECK(!ts.hasProjector());
372 BOOST_CHECK(!ts.hasJacobian());
375 BOOST_CHECK(!ts.hasPredicted());
376 BOOST_CHECK(ts.hasFiltered());
377 BOOST_CHECK(!ts.hasSmoothed());
378 BOOST_CHECK(!ts.hasUncalibrated());
379 BOOST_CHECK(!ts.hasCalibrated());
380 BOOST_CHECK(!ts.hasProjector());
381 BOOST_CHECK(!ts.hasJacobian());
384 BOOST_CHECK(!ts.hasPredicted());
385 BOOST_CHECK(!ts.hasFiltered());
386 BOOST_CHECK(ts.hasSmoothed());
387 BOOST_CHECK(!ts.hasUncalibrated());
388 BOOST_CHECK(!ts.hasCalibrated());
389 BOOST_CHECK(!ts.hasProjector());
390 BOOST_CHECK(!ts.hasJacobian());
393 BOOST_CHECK(!ts.hasPredicted());
394 BOOST_CHECK(!ts.hasFiltered());
395 BOOST_CHECK(!ts.hasSmoothed());
396 BOOST_CHECK(ts.hasUncalibrated());
397 BOOST_CHECK(!ts.hasCalibrated());
398 BOOST_CHECK(!ts.hasProjector());
399 BOOST_CHECK(!ts.hasJacobian());
402 BOOST_CHECK(!ts.hasPredicted());
403 BOOST_CHECK(!ts.hasFiltered());
404 BOOST_CHECK(!ts.hasSmoothed());
405 BOOST_CHECK(!ts.hasUncalibrated());
406 BOOST_CHECK(ts.hasCalibrated());
407 BOOST_CHECK(ts.hasProjector());
408 BOOST_CHECK(!ts.hasJacobian());
411 BOOST_CHECK(!ts.hasPredicted());
412 BOOST_CHECK(!ts.hasFiltered());
413 BOOST_CHECK(!ts.hasSmoothed());
414 BOOST_CHECK(!ts.hasUncalibrated());
415 BOOST_CHECK(!ts.hasCalibrated());
416 BOOST_CHECK(!ts.hasProjector());
417 BOOST_CHECK(ts.hasJacobian());
429 auto cts = ct.getTrackState(0);
433 BOOST_CHECK_EQUAL(cts.chi2(),
pc.chi2);
434 BOOST_CHECK_EQUAL(ts.chi2(),
pc.chi2);
435 BOOST_CHECK_EQUAL(cts.pathLength(),
pc.pathLength);
436 BOOST_CHECK_EQUAL(ts.pathLength(),
pc.pathLength);
443 BOOST_CHECK_EQUAL(cts.predicted(),
v);
445 ts.predictedCovariance() =
cov;
446 BOOST_CHECK_EQUAL(cts.predictedCovariance(),
cov);
450 BOOST_CHECK_EQUAL(cts.filtered(),
v);
452 ts.filteredCovariance() =
cov;
453 BOOST_CHECK_EQUAL(cts.filteredCovariance(),
cov);
457 BOOST_CHECK_EQUAL(cts.smoothed(),
v);
459 ts.smoothedCovariance() =
cov;
460 BOOST_CHECK_EQUAL(cts.smoothedCovariance(),
cov);
463 auto fm2 = std::make_unique<FittableMeasurement<SourceLink>>(*fm);
465 ts.uncalibrated() = sourceLink2;
466 BOOST_CHECK_EQUAL(cts.uncalibrated(), sourceLink2);
467 BOOST_CHECK_NE(cts.uncalibrated(),
SourceLink{fm.get()});
470 newMeasCov.setRandom();
471 ts.calibratedCovariance() = newMeasCov;
472 BOOST_CHECK_EQUAL(cts.calibratedCovariance(), newMeasCov);
475 newMeasPar.setRandom();
476 ts.calibrated() = newMeasPar;
477 BOOST_CHECK_EQUAL(cts.calibrated(), newMeasPar);
479 size_t measdim = ts.effectiveCalibrated().rows();
483 ts.effectiveCalibratedCovariance() = eff;
484 BOOST_CHECK_EQUAL(cts.effectiveCalibratedCovariance(), eff);
485 newMeasCov.topLeftCorner(eff.rows(), eff.rows()) = eff;
486 BOOST_CHECK_EQUAL(cts.calibratedCovariance(), newMeasCov);
491 BOOST_CHECK_EQUAL(cts.jacobian(), jac);
494 BOOST_CHECK_EQUAL(cts.chi2(), 98
u);
496 ts.pathLength() = 66;
497 BOOST_CHECK_EQUAL(cts.pathLength(), 66
u);
511 BOOST_CHECK_EQUAL(ts.calibratedSize(),
pc.meas3d->size());
512 BOOST_CHECK_EQUAL(ts.effectiveCalibrated(),
pc.meas3d->parameters());
513 BOOST_CHECK_EQUAL(ts.effectiveCalibratedCovariance(),
514 pc.meas3d->covariance());
515 BOOST_CHECK_EQUAL(ts.effectiveProjector(),
pc.meas3d->projector());
523 pc.meas3d->referenceObject().getSharedPtr(), {}, mCov, mPar[0], mPar[1]};
525 ts.setCalibrated(
m2);
527 BOOST_CHECK_EQUAL(ts.calibratedSize(), 2
u);
528 BOOST_CHECK_EQUAL(ts.effectiveCalibrated(), mPar);
529 BOOST_CHECK_EQUAL(ts.effectiveCalibratedCovariance(), mCov);
530 BOOST_CHECK_EQUAL(ts.effectiveProjector(),
m2.projector());
535 mParFull.head(2) = mPar;
536 BOOST_CHECK_EQUAL(ts.calibrated(), mParFull);
540 mCovFull.topLeftCorner(2, 2) = mCov;
541 BOOST_CHECK_EQUAL(ts.calibratedCovariance(), mCovFull);
546 BOOST_CHECK_EQUAL(ts.projector(), projFull);
557 BOOST_CHECK(ts.hasPredicted());
558 BOOST_CHECK_EQUAL(
pc.predicted->parameters(), ts.predicted());
559 BOOST_CHECK_EQUAL(*
pc.predicted->covariance(), ts.predictedCovariance());
561 BOOST_CHECK(ts.hasFiltered());
562 BOOST_CHECK_EQUAL(
pc.filtered->parameters(), ts.filtered());
563 BOOST_CHECK_EQUAL(*
pc.filtered->covariance(), ts.filteredCovariance());
565 BOOST_CHECK(ts.hasSmoothed());
566 BOOST_CHECK_EQUAL(
pc.smoothed->parameters(), ts.smoothed());
567 BOOST_CHECK_EQUAL(*
pc.smoothed->covariance(), ts.smoothedCovariance());
569 BOOST_CHECK_EQUAL(&ts.referenceSurface(), &
pc.sourceLink.referenceSurface());
571 BOOST_CHECK(ts.hasJacobian());
572 BOOST_CHECK_EQUAL(ts.jacobian(),
pc.jacobian);
574 BOOST_CHECK(ts.hasProjector());
575 BOOST_CHECK_EQUAL(ts.effectiveProjector(),
pc.meas3d->projector());
577 BOOST_CHECK(ts.hasCalibrated());
578 BOOST_CHECK_EQUAL(
pc.meas3d->parameters(), ts.effectiveCalibrated());
581 mParFull.head(
pc.meas3d->size()) =
pc.meas3d->parameters();
582 BOOST_CHECK_EQUAL(mParFull, ts.calibrated());
584 BOOST_CHECK_EQUAL(
pc.meas3d->covariance(),
585 ts.effectiveCalibratedCovariance());
588 mCovFull.topLeftCorner(
pc.meas3d->size(),
pc.meas3d->size()) =
589 pc.meas3d->covariance();
590 BOOST_CHECK_EQUAL(mCovFull, ts.calibratedCovariance());
593 BOOST_CHECK_EQUAL(
pc.meas3d->sourceLink(), ts.calibratedSourceLink());
596 BOOST_CHECK(ts.hasUncalibrated());
597 BOOST_CHECK_EQUAL(
pc.meas3d->sourceLink(), ts.uncalibrated());
604 pc.meas3d->projector();
605 BOOST_CHECK_EQUAL(ts.projector(), fullProj);
609 BOOST_CHECK_EQUAL(ts.effectiveProjector(),
pc.meas3d->projector());
618 TrackStatePropMask::Predicted | TrackStatePropMask::Filtered |
626 BOOST_CHECK(tso.hasPredicted());
627 BOOST_CHECK(tso.hasFiltered());
628 BOOST_CHECK(!tso.hasSmoothed());
629 BOOST_CHECK(tso.hasUncalibrated());
630 BOOST_CHECK(!tso.hasCalibrated());
631 BOOST_CHECK(tso.hasJacobian());
640 std::array<PM, 6>
values{PM::Predicted, PM::Filtered, PM::Smoothed,
643 PM all = std::accumulate(
values.begin(),
values.end(), PM::None,
644 [](
auto a,
auto b) {
return a | b; });
647 BOOST_CHECK(ts.getMask() == all);
650 BOOST_CHECK(ts.getMask() == (PM::Filtered | PM::Calibrated));
653 mj.
addTrackState(PM::Filtered | PM::Smoothed | PM::Predicted));
654 BOOST_CHECK(ts.getMask() == (PM::Filtered | PM::Smoothed | PM::Predicted));
658 BOOST_CHECK(ts.getMask() == mask);
667 std::array<PM, 6>
values{PM::Predicted, PM::Filtered, PM::Smoothed,
673 for (PM b : values) {
678 BOOST_CHECK_THROW(tsa.copyFrom(tsb), std::runtime_error);
679 BOOST_CHECK_THROW(tsb.copyFrom(tsa), std::runtime_error);
687 auto ts1 = mkts(PM::Filtered | PM::Predicted);
688 ts1.filtered().setRandom();
689 ts1.filteredCovariance().setRandom();
690 ts1.predicted().setRandom();
691 ts1.predictedCovariance().setRandom();
694 auto ts2 = mkts(PM::Predicted);
695 ts2.predicted().setRandom();
696 ts2.predictedCovariance().setRandom();
699 BOOST_CHECK(ts1.predicted() != ts2.predicted());
700 BOOST_CHECK(ts1.predictedCovariance() != ts2.predictedCovariance());
703 BOOST_CHECK_THROW(ts2.copyFrom(ts1), std::runtime_error);
704 BOOST_CHECK(ts1.predicted() != ts2.predicted());
705 BOOST_CHECK(ts1.predictedCovariance() != ts2.predictedCovariance());
709 BOOST_CHECK(ts1.predicted() == ts2.predicted());
710 BOOST_CHECK(ts1.predictedCovariance() == ts2.predictedCovariance());
716 auto [rts1, fm1] =
fillTrackState(ts1, TrackStatePropMask::All, 2);
717 auto [rts2, fm2] =
fillTrackState(ts2, TrackStatePropMask::All, 3);
719 auto ots1 = mkts(PM::All);
720 auto ots2 = mkts(PM::All);
725 BOOST_CHECK_NE(ts1.predicted(), ts2.predicted());
726 BOOST_CHECK_NE(ts1.predictedCovariance(), ts2.predictedCovariance());
727 BOOST_CHECK_NE(ts1.filtered(), ts2.filtered());
728 BOOST_CHECK_NE(ts1.filteredCovariance(), ts2.filteredCovariance());
729 BOOST_CHECK_NE(ts1.smoothed(), ts2.smoothed());
730 BOOST_CHECK_NE(ts1.smoothedCovariance(), ts2.smoothedCovariance());
732 BOOST_CHECK_NE(ts1.uncalibrated(), ts2.uncalibrated());
734 BOOST_CHECK_NE(ts1.calibratedSourceLink(), ts2.calibratedSourceLink());
735 BOOST_CHECK_NE(ts1.calibrated(), ts2.calibrated());
736 BOOST_CHECK_NE(ts1.calibratedCovariance(), ts2.calibratedCovariance());
737 BOOST_CHECK_NE(ts1.calibratedSize(), ts2.calibratedSize());
738 BOOST_CHECK_NE(ts1.projector(), ts2.projector());
740 BOOST_CHECK_NE(ts1.jacobian(), ts2.jacobian());
741 BOOST_CHECK_NE(ts1.chi2(), ts2.chi2());
742 BOOST_CHECK_NE(ts1.pathLength(), ts2.pathLength());
743 BOOST_CHECK_NE(&ts1.referenceSurface(), &ts2.referenceSurface());
747 BOOST_CHECK_EQUAL(ts1.predicted(), ts2.predicted());
748 BOOST_CHECK_EQUAL(ts1.predictedCovariance(), ts2.predictedCovariance());
749 BOOST_CHECK_EQUAL(ts1.filtered(), ts2.filtered());
750 BOOST_CHECK_EQUAL(ts1.filteredCovariance(), ts2.filteredCovariance());
751 BOOST_CHECK_EQUAL(ts1.smoothed(), ts2.smoothed());
752 BOOST_CHECK_EQUAL(ts1.smoothedCovariance(), ts2.smoothedCovariance());
754 BOOST_CHECK_EQUAL(ts1.uncalibrated(), ts2.uncalibrated());
756 BOOST_CHECK_EQUAL(ts1.calibratedSourceLink(), ts2.calibratedSourceLink());
757 BOOST_CHECK_EQUAL(ts1.calibrated(), ts2.calibrated());
758 BOOST_CHECK_EQUAL(ts1.calibratedCovariance(), ts2.calibratedCovariance());
759 BOOST_CHECK_EQUAL(ts1.calibratedSize(), ts2.calibratedSize());
760 BOOST_CHECK_EQUAL(ts1.projector(), ts2.projector());
762 BOOST_CHECK_EQUAL(ts1.jacobian(), ts2.jacobian());
763 BOOST_CHECK_EQUAL(ts1.chi2(), ts2.chi2());
764 BOOST_CHECK_EQUAL(ts1.pathLength(), ts2.pathLength());
765 BOOST_CHECK_EQUAL(&ts1.referenceSurface(), &ts2.referenceSurface());
768 ts2 = mkts(PM::Predicted |
PM::Jacobian | PM::Calibrated);
773 BOOST_CHECK_NE(ts1.predicted(), ts2.predicted());
774 BOOST_CHECK_NE(ts1.predictedCovariance(), ts2.predictedCovariance());
776 BOOST_CHECK_NE(ts1.calibratedSourceLink(), ts2.calibratedSourceLink());
777 BOOST_CHECK_NE(ts1.calibrated(), ts2.calibrated());
778 BOOST_CHECK_NE(ts1.calibratedCovariance(), ts2.calibratedCovariance());
779 BOOST_CHECK_NE(ts1.calibratedSize(), ts2.calibratedSize());
780 BOOST_CHECK_NE(ts1.projector(), ts2.projector());
782 BOOST_CHECK_NE(ts1.jacobian(), ts2.jacobian());
783 BOOST_CHECK_NE(ts1.chi2(), ts2.chi2());
784 BOOST_CHECK_NE(ts1.pathLength(), ts2.pathLength());
785 BOOST_CHECK_NE(&ts1.referenceSurface(), &ts2.referenceSurface());
790 BOOST_CHECK_EQUAL(ts1.predicted(), ts2.predicted());
791 BOOST_CHECK_EQUAL(ts1.predictedCovariance(), ts2.predictedCovariance());
793 BOOST_CHECK_EQUAL(ts1.calibratedSourceLink(), ts2.calibratedSourceLink());
794 BOOST_CHECK_EQUAL(ts1.calibrated(), ts2.calibrated());
795 BOOST_CHECK_EQUAL(ts1.calibratedCovariance(), ts2.calibratedCovariance());
796 BOOST_CHECK_EQUAL(ts1.calibratedSize(), ts2.calibratedSize());
797 BOOST_CHECK_EQUAL(ts1.projector(), ts2.projector());
799 BOOST_CHECK_EQUAL(ts1.jacobian(), ts2.jacobian());
800 BOOST_CHECK_EQUAL(ts1.chi2(), ts2.chi2());
801 BOOST_CHECK_EQUAL(ts1.pathLength(), ts2.pathLength());
802 BOOST_CHECK_EQUAL(&ts1.referenceSurface(),
803 &ts2.referenceSurface());