9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
33 using namespace Acts::UnitLiterals;
42 Covariance randMat((Covariance::Random() + 1.5 * Covariance::Identity()) *
46 Covariance covMat = 0.5 * (randMat + randMat.transpose());
52 using Vector2 = Eigen::Matrix<float, 2, 1>;
53 using Matrix2 = Eigen::Matrix<float, 2, 2>;
55 const int spatialTrkGridSize = 4001;
57 const float binExtent = 3.1e-4;
60 const float z0 = -0.2;
61 Vector2 impactParameters{d0, z0};
64 Matrix2 subCovMat = covMat.block<2, 2>(0, 0).cast<float>();
66 paramVec << d0, z0, 0, 0, 0, 0;
69 std::shared_ptr<PerigeeSurface> perigeeSurface =
70 Surface::makeShared<PerigeeSurface>(
Vector3(0., 0., 0.));
82 auto trackDensityMap = grid.
addTrack(params1, mainDensityMap);
88 const Matrix2& sigmas) {
90 float coef = 1 / std::sqrt(sigmas.determinant());
91 float expo = -0.5 * diffs.transpose().dot(sigmas.inverse() * diffs);
92 return coef * std::exp(expo);
95 for (
auto const&
it : mainDensityMap) {
97 int zBin =
it.first.first;
98 float density =
it.second;
102 float correctDensity = gaussian2D(dzVec, impactParameters, subCovMat);
110 -0.5 * (subCovMat(0, 1) + subCovMat(1, 0)) / subCovMat(0, 0) * d0 + z0;
114 float correctFWHM = 2. * std::sqrt(2 * std::log(2.) *
115 subCovMat.determinant() / subCovMat(0, 0));
119 BOOST_CHECK(res.ok());
122 float maxZ = res.value().first.first;
123 float fwhm = res.value().second * 2.355f;
127 float relTolOptimization = 1
e-3;
133 compare_to_analytical_solution_for_single_track_with_time) {
135 const int spatialTrkGridSize = 401;
136 const int temporalTrkGridSize = 401;
138 const float spatialBinExtent = 3.1e-3;
139 const float temporalBinExtent = 3.1e-3;
141 const float d0 = -0.1;
142 const float z0 = -0.2;
143 const float t0 = 0.1;
144 Vector3 impactParameters{d0, z0, t0};
150 paramVec << d0, z0, 0, 0, 0, t0;
152 std::shared_ptr<PerigeeSurface> perigeeSurface =
153 Surface::makeShared<PerigeeSurface>(
Vector3(0., 0., 0.));
161 spatialBinExtent, temporalBinExtent);
169 auto trackDensityMap = grid.
addTrack(params, mainDensityMap);
177 float coef = 1 / std::sqrt(sigmas.determinant());
178 float expo = -0.5 * diffs.transpose().dot(sigmas.inverse() * diffs);
179 return coef * std::exp(expo);
182 for (
auto const&
it : mainDensityMap) {
186 float density =
it.second;
191 float correctDensity = gaussian3D(dztVec, impactParameters, ipCov);
203 ipWeights(1, 1) * ipWeights(2, 2) - ipWeights(1, 2) * ipWeights(1, 2);
206 ipWeights(0, 1) * ipWeights(2, 2) - ipWeights(0, 2) * ipWeights(1, 2);
207 ActsScalar correctMaxZ = zNom / denom * d0 + z0;
210 ipWeights(0, 2) * ipWeights(1, 1) - ipWeights(0, 1) * ipWeights(1, 2);
211 ActsScalar correctMaxT = tNom / denom * d0 + t0;
214 ActsScalar correctFWHM = 2. * std::sqrt(2 * std::log(2.) / ipWeights(1, 1));
218 BOOST_CHECK(res.ok());
221 float maxZ = res.value().first.first;
222 float maxT = res.value().first.second;
223 float fwhm = res.value().second * 2.355f;
227 float relTolOptimization = 1
e-1;
235 const int spatialTrkGridSize = 1;
236 float binExtent = 2.;
244 float correctMaxZ = -2.;
250 for (
int i = -6;
i <= 4;
i++) {
251 mainDensityMap[std::make_pair(
i, 0)] =
252 1.0 - 0.1 * std::abs(correctMaxZ - grid.
getBinCenter(
i, binExtent));
257 BOOST_CHECK(res.ok());
260 float maxZ = res.value().first.first;
261 BOOST_CHECK_EQUAL(maxZ, correctMaxZ);
265 float fwhm = res.value().second * 2.355f;
266 BOOST_CHECK_EQUAL(fwhm, 10.);
270 const int spatialTrkGridSize = 15;
272 double binExtent = 0.1;
283 paramVec0 << 100.0, -0.4, 0, 0, 0, 0;
285 paramVec1 << 0.01, -0.4, 0, 0, 0, 0;
287 paramVec2 << 0.01, 10.9, 0, 0, 0, 0;
289 paramVec3 << 0.01, 0.9, 0, 0, 0, 0;
292 std::shared_ptr<PerigeeSurface> perigeeSurface =
293 Surface::makeShared<PerigeeSurface>(
Vector3(0., 0., 0.));
308 auto trackDensityMap = grid.
addTrack(params0, mainDensityMap);
309 BOOST_CHECK(mainDensityMap.empty());
312 trackDensityMap = grid.
addTrack(params1, mainDensityMap);
313 BOOST_CHECK_EQUAL(mainDensityMap.size(), spatialTrkGridSize);
316 trackDensityMap = grid.
addTrack(params2, mainDensityMap);
317 BOOST_CHECK_EQUAL(mainDensityMap.size(), 2 * spatialTrkGridSize);
320 trackDensityMap = grid.
addTrack(params3, mainDensityMap);
321 BOOST_CHECK_EQUAL(mainDensityMap.size(), 3 * spatialTrkGridSize - 2);
324 trackDensityMap = grid.
addTrack(params1, mainDensityMap);
325 BOOST_CHECK_EQUAL(mainDensityMap.size(), 3 * spatialTrkGridSize - 2);
329 const int spatialTrkGridSize = 29;
330 const int temporalTrkGridSize = 29;
333 double binExtent = 0.05;
341 cfg2D(binExtent, binExtent);
346 Covariance covMat(Covariance::Identity() * 0.005);
350 float z0Trk2 = -10.95;
353 paramVec1 << 0.02, z0Trk1, 0, 0, 0, t0Trk1;
355 paramVec2 << 0.01, z0Trk2, 0, 0, 0, t0Trk2;
358 std::shared_ptr<PerigeeSurface> perigeeSurface =
359 Surface::makeShared<PerigeeSurface>(
Vector3(0., 0., 0.));
372 auto trackDensityMap = grid1D.
addTrack(params1, mainDensityMap1D);
374 BOOST_CHECK(firstRes.ok());
376 BOOST_CHECK_EQUAL((*firstRes).first, z0Trk1);
378 BOOST_CHECK_EQUAL((*firstRes).second, 0.);
381 auto trackDensityMap2D = grid2D.
addTrack(params1, mainDensityMap2D);
383 BOOST_CHECK(firstRes2D.ok());
385 BOOST_CHECK_EQUAL((*firstRes2D).first, z0Trk1);
387 BOOST_CHECK_EQUAL((*firstRes2D).second, t0Trk1);
390 trackDensityMap = grid1D.
addTrack(params2, mainDensityMap1D);
393 BOOST_CHECK(secondRes.ok());
396 BOOST_CHECK_EQUAL((*secondRes).first.first, z0Trk2);
398 BOOST_CHECK_EQUAL((*secondRes).first.second, 0.);
400 BOOST_CHECK((*secondRes).second > 0);
403 trackDensityMap = grid2D.
addTrack(params2, mainDensityMap2D);
406 BOOST_CHECK(secondRes2D.ok());
409 BOOST_CHECK_EQUAL((*secondRes2D).first.first, z0Trk2);
411 BOOST_CHECK_EQUAL((*secondRes2D).first.second, t0Trk2);
417 const int spatialTrkGridSize = 29;
419 double binExtent = 0.05;
427 Covariance covMat(Covariance::Identity() * 0.005);
430 float z0Trk2 = -10.95;
432 paramVec1 << 0.01, z0Trk1, 0, 0, 0, 0;
434 paramVec2 << 0.0095, z0Trk2, 0, 0, 0, 0;
437 std::shared_ptr<PerigeeSurface> perigeeSurface =
438 Surface::makeShared<PerigeeSurface>(
Vector3(0., 0., 0.));
449 auto trackDensityMap = grid.
addTrack(params1, mainDensityMap);
452 BOOST_CHECK(res1.ok());
454 BOOST_CHECK_EQUAL((*res1).first, z0Trk1);
457 trackDensityMap = grid.
addTrack(params2, mainDensityMap);
459 BOOST_CHECK(res2.ok());
462 BOOST_CHECK_EQUAL((*res2).first, z0Trk2);
465 const float densityToAdd = 0.5;
466 mainDensityMap.at(std::make_pair(4, 0)) += densityToAdd;
467 mainDensityMap.at(std::make_pair(6, 0)) += densityToAdd;
470 BOOST_CHECK(res3.ok());
474 BOOST_CHECK_EQUAL((*res3).first, z0Trk1);
478 const int spatialTrkGridSize = 29;
479 const int temporalTrkGridSize = 29;
481 int trkGridSize = spatialTrkGridSize * temporalTrkGridSize;
484 double binExtent = 0.05;
492 cfg2D(binExtent, binExtent);
500 float z0Trk1 = -0.45;
501 float t0Trk1 = -0.15;
502 float z0Trk2 = -0.25;
503 float t0Trk2 = t0Trk1;
506 paramVec0 << 0.1, z0Trk1, 0, 0, 0, t0Trk1;
508 paramVec1 << 0.1, z0Trk2, 0, 0, 0, t0Trk2;
511 std::shared_ptr<PerigeeSurface> perigeeSurface =
512 Surface::makeShared<PerigeeSurface>(
Vector3(0., 0., 0.));
525 auto densitySum = [](
const auto& densityMap) {
527 for (
auto it = densityMap.begin();
it != densityMap.end();
it++) {
534 auto firstTrackDensityMap1D = grid1D.
addTrack(params0, mainDensityMap1D);
535 BOOST_CHECK(not mainDensityMap1D.empty());
537 BOOST_CHECK_EQUAL(mainDensityMap1D.size(), spatialTrkGridSize);
538 float firstDensitySum1D = densitySum(mainDensityMap1D);
541 auto firstTrackDensityMap2D = grid2D.
addTrack(params0, mainDensityMap2D);
542 BOOST_CHECK(not mainDensityMap2D.empty());
544 BOOST_CHECK_EQUAL(mainDensityMap2D.size(), trkGridSize);
545 float firstDensitySum2D = densitySum(mainDensityMap2D);
548 firstTrackDensityMap1D = grid1D.
addTrack(params0, mainDensityMap1D);
549 BOOST_CHECK(not mainDensityMap1D.empty());
551 BOOST_CHECK_EQUAL(mainDensityMap1D.size(), spatialTrkGridSize);
553 float secondDensitySum1D = densitySum(mainDensityMap1D);
555 BOOST_CHECK(2 * firstDensitySum1D == secondDensitySum1D);
558 firstTrackDensityMap2D = grid2D.
addTrack(params0, mainDensityMap2D);
559 BOOST_CHECK(not mainDensityMap2D.empty());
561 BOOST_CHECK_EQUAL(mainDensityMap2D.size(), trkGridSize);
563 float secondDensitySum2D = densitySum(mainDensityMap2D);
565 BOOST_CHECK(2 * firstDensitySum2D == secondDensitySum2D);
568 grid1D.
subtractTrack(firstTrackDensityMap1D, mainDensityMap1D);
570 float thirdDensitySum1D = densitySum(mainDensityMap1D);
572 BOOST_CHECK(firstDensitySum1D == thirdDensitySum1D);
575 BOOST_CHECK_EQUAL(mainDensityMap1D.size(), spatialTrkGridSize);
578 grid2D.
subtractTrack(firstTrackDensityMap2D, mainDensityMap2D);
580 float thirdDensitySum2D = densitySum(mainDensityMap2D);
582 BOOST_CHECK(firstDensitySum2D == thirdDensitySum2D);
585 BOOST_CHECK_EQUAL(mainDensityMap2D.size(), trkGridSize);
588 auto secondTrackDensityMap1D = grid1D.
addTrack(params1, mainDensityMap1D);
589 int nNonOverlappingBins1D = int(std::abs(z0Trk1 - z0Trk2) / binExtent + 1);
590 BOOST_CHECK_EQUAL(mainDensityMap1D.size(),
591 spatialTrkGridSize + nNonOverlappingBins1D);
592 float fourthDensitySum1D = densitySum(mainDensityMap1D);
595 auto secondTrackDensityMap2D = grid2D.
addTrack(params1, mainDensityMap2D);
596 int nNonOverlappingBins2D = nNonOverlappingBins1D * temporalTrkGridSize;
597 BOOST_CHECK_EQUAL(mainDensityMap2D.size(),
598 trkGridSize + nNonOverlappingBins2D);
599 float fourthDensitySum2D = densitySum(mainDensityMap2D);
602 grid1D.
subtractTrack(firstTrackDensityMap1D, mainDensityMap1D);
603 float fifthDensitySum1D = densitySum(mainDensityMap1D);
605 CHECK_CLOSE_REL(fifthDensitySum1D, fourthDensitySum1D - firstDensitySum1D,
609 grid2D.
subtractTrack(firstTrackDensityMap2D, mainDensityMap2D);
610 float fifthDensitySum2D = densitySum(mainDensityMap2D);
612 CHECK_CLOSE_REL(fifthDensitySum2D, fourthDensitySum2D - firstDensitySum2D,
616 grid1D.
subtractTrack(secondTrackDensityMap1D, mainDensityMap1D);
618 BOOST_CHECK_EQUAL(mainDensityMap1D.size(),
619 spatialTrkGridSize + nNonOverlappingBins1D);
620 float sixthDensitySum1D = densitySum(mainDensityMap1D);
625 grid2D.
subtractTrack(secondTrackDensityMap2D, mainDensityMap2D);
627 BOOST_CHECK_EQUAL(mainDensityMap2D.size(),
628 trkGridSize + nNonOverlappingBins2D);
629 float sixthDensitySum2D = densitySum(mainDensityMap2D);