File indexing completed on 2025-08-06 08:11:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Definitions/Common.hpp"
0014 #include "Acts/Definitions/Direction.hpp"
0015 #include "Acts/Definitions/TrackParametrization.hpp"
0016 #include "Acts/Definitions/Units.hpp"
0017 #include "Acts/EventData/Charge.hpp"
0018 #include "Acts/EventData/GenericBoundTrackParameters.hpp"
0019 #include "Acts/EventData/TrackParameters.hpp"
0020 #include "Acts/Geometry/GeometryContext.hpp"
0021 #include "Acts/Geometry/GeometryIdentifier.hpp"
0022 #include "Acts/MagneticField/ConstantBField.hpp"
0023 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0024 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0025 #include "Acts/MagneticField/NullBField.hpp"
0026 #include "Acts/Propagator/EigenStepper.hpp"
0027 #include "Acts/Propagator/Propagator.hpp"
0028 #include "Acts/Propagator/StraightLineStepper.hpp"
0029 #include "Acts/Propagator/VoidNavigator.hpp"
0030 #include "Acts/Surfaces/PerigeeSurface.hpp"
0031 #include "Acts/Surfaces/PlaneSurface.hpp"
0032 #include "Acts/Surfaces/Surface.hpp"
0033 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0034 #include "Acts/Utilities/Logger.hpp"
0035 #include "Acts/Utilities/Result.hpp"
0036 #include "Acts/Vertexing/ImpactPointEstimator.hpp"
0037 #include "Acts/Vertexing/TrackAtVertex.hpp"
0038 #include "Acts/Vertexing/Vertex.hpp"
0039
0040 #include <algorithm>
0041 #include <array>
0042 #include <cmath>
0043 #include <limits>
0044 #include <memory>
0045 #include <optional>
0046 #include <tuple>
0047 #include <utility>
0048 #include <vector>
0049
0050 namespace {
0051
0052 namespace bd = boost::unit_test::data;
0053
0054 using namespace Acts;
0055 using namespace Acts::UnitLiterals;
0056 using Acts::VectorHelpers::makeVector4;
0057
0058 using MagneticField = Acts::ConstantBField;
0059 using StraightPropagator = Acts::Propagator<StraightLineStepper>;
0060 using Stepper = Acts::EigenStepper<>;
0061 using Propagator = Acts::Propagator<Stepper>;
0062 using Estimator = Acts::ImpactPointEstimator;
0063 using StraightLineEstimator = Acts::ImpactPointEstimator;
0064
0065 const Acts::GeometryContext geoContext;
0066 const Acts::MagneticFieldContext magFieldContext;
0067
0068 Acts::MagneticFieldProvider::Cache magFieldCache() {
0069 return NullBField{}.makeCache(magFieldContext);
0070 }
0071
0072
0073
0074 auto d0s = bd::make({-25_um, 25_um});
0075 auto l0s = bd::make({-1_mm, 1_mm});
0076 auto t0s = bd::make({-2_ns, 2_ns});
0077 auto phis = bd::make({0_degree, -45_degree, 45_degree});
0078 auto thetas = bd::make({90_degree, 20_degree, 160_degree});
0079 auto ps = bd::make({0.4_GeV, 1_GeV, 10_GeV});
0080 auto qs = bd::make({-1_e, 1_e});
0081
0082 auto tracksWithoutIPs = t0s * phis * thetas * ps * qs;
0083 auto IPs = d0s * l0s;
0084 auto tracks = IPs * tracksWithoutIPs;
0085
0086
0087 auto vx0s = bd::make({0_um, -10_um, 10_um});
0088 auto vy0s = bd::make({0_um, -10_um, 10_um});
0089 auto vz0s = bd::make({0_mm, -25_mm, 25_mm});
0090 auto vt0s = bd::make({0_ns, -2_ns, 2_ns});
0091
0092 auto vertices = vx0s * vy0s * vz0s * vt0s;
0093
0094
0095 Estimator makeEstimator(double bZ) {
0096 auto field = std::make_shared<MagneticField>(Vector3(0, 0, bZ));
0097 Stepper stepper(field);
0098 Estimator::Config cfg(field,
0099 std::make_shared<Propagator>(
0100 std::move(stepper), VoidNavigator(),
0101 getDefaultLogger("Prop", Logging::Level::WARNING)));
0102 return Estimator(cfg);
0103 }
0104
0105
0106 Acts::BoundSquareMatrix makeBoundParametersCovariance(
0107 double stdDevTime = 30_ps) {
0108 BoundVector stddev;
0109 stddev[eBoundLoc0] = 15_um;
0110 stddev[eBoundLoc1] = 100_um;
0111 stddev[eBoundTime] = stdDevTime;
0112 stddev[eBoundPhi] = 1_degree;
0113 stddev[eBoundTheta] = 1_degree;
0114 stddev[eBoundQOverP] = 1_e / 100_GeV;
0115 return stddev.cwiseProduct(stddev).asDiagonal();
0116 }
0117
0118
0119 Acts::SquareMatrix4 makeVertexCovariance() {
0120 Vector4 stddev;
0121 stddev[ePos0] = 10_um;
0122 stddev[ePos1] = 10_um;
0123 stddev[ePos2] = 75_um;
0124 stddev[eTime] = 1_ns;
0125 return stddev.cwiseProduct(stddev).asDiagonal();
0126 }
0127
0128
0129 std::uniform_real_distribution<double> uniformDist(0.0, 1.0);
0130
0131 std::uniform_real_distribution<double> signDist(-1, 1);
0132 }
0133
0134 BOOST_AUTO_TEST_SUITE(VertexingImpactPointEstimator)
0135
0136
0137
0138 BOOST_DATA_TEST_CASE(SingleTrackDistanceParametersCompatibility3D, tracks, d0,
0139 l0, t0, phi, theta, p, q) {
0140 auto particleHypothesis = ParticleHypothesis::pion();
0141
0142 BoundVector par;
0143 par[eBoundLoc0] = d0;
0144 par[eBoundLoc1] = l0;
0145 par[eBoundTime] = t0;
0146 par[eBoundPhi] = phi;
0147 par[eBoundTheta] = theta;
0148 par[eBoundQOverP] = particleHypothesis.qOverP(p, q);
0149
0150 Estimator ipEstimator = makeEstimator(2_T);
0151 Estimator::State state{magFieldCache()};
0152
0153 Vector3 refPosition(0., 0., 0.);
0154 auto perigeeSurface = Surface::makeShared<PerigeeSurface>(refPosition);
0155
0156 BoundTrackParameters myTrack(
0157 perigeeSurface, par, makeBoundParametersCovariance(), particleHypothesis);
0158
0159
0160 double distT = std::hypot(d0, l0);
0161 double dist3 =
0162 ipEstimator.calculateDistance(geoContext, myTrack, refPosition, state)
0163 .value();
0164
0165
0166
0167
0168 BOOST_CHECK((dist3 < distT) ||
0169 (theta == 90_degree && std::abs(dist3 - distT) < 1_nm));
0170
0171
0172 auto res = ipEstimator.estimate3DImpactParameters(
0173 geoContext, magFieldContext, myTrack, refPosition, state);
0174 BoundTrackParameters trackAtIP3d = *res;
0175 const auto& atPerigee = myTrack.parameters();
0176 const auto& atIp3d = trackAtIP3d.parameters();
0177
0178
0179 BOOST_CHECK_NE(atPerigee[eBoundLoc0], atIp3d[eBoundLoc0]);
0180 BOOST_CHECK_NE(atPerigee[eBoundLoc1], atIp3d[eBoundLoc1]);
0181
0182
0183 CHECK_CLOSE_ABS(atPerigee[eBoundTheta], atIp3d[eBoundTheta], 0.01_mrad);
0184 CHECK_CLOSE_REL(atPerigee[eBoundQOverP], atIp3d[eBoundQOverP],
0185 std::numeric_limits<ActsScalar>::epsilon());
0186
0187
0188
0189 auto compatibility =
0190 ipEstimator.getVertexCompatibility(geoContext, &trackAtIP3d, refPosition)
0191 .value();
0192 BOOST_CHECK_GT(compatibility, 0);
0193 }
0194
0195 BOOST_DATA_TEST_CASE(TimeAtPca, tracksWithoutIPs* vertices, t0, phi, theta, p,
0196 q, vx0, vy0, vz0, vt0) {
0197 using Propagator = Acts::Propagator<Stepper>;
0198 using StraightPropagator = Acts::Propagator<StraightLineStepper>;
0199
0200
0201 auto field = std::make_shared<MagneticField>(Vector3(0, 0, 2_T));
0202 Stepper stepper(field);
0203 auto propagator = std::make_shared<Propagator>(std::move(stepper));
0204 Estimator::Config cfg(field, propagator);
0205 Estimator ipEstimator(cfg);
0206 Estimator::State ipState{magFieldCache()};
0207
0208
0209 auto zeroField = std::make_shared<MagneticField>(Vector3(0, 0, 0));
0210 StraightLineStepper straightLineStepper;
0211 auto straightLinePropagator =
0212 std::make_shared<StraightPropagator>(straightLineStepper);
0213 StraightLineEstimator::Config zeroFieldCfg(zeroField, straightLinePropagator);
0214 StraightLineEstimator zeroFieldIPEstimator(zeroFieldCfg);
0215 StraightLineEstimator::State zeroFieldIPState{magFieldCache()};
0216
0217
0218 Vector4 vtxPos(vx0, vy0, vz0, vt0);
0219 Vertex vtx(vtxPos, makeVertexCovariance(), {});
0220
0221
0222 auto vtxPerigeeSurface =
0223 Surface::makeShared<PerigeeSurface>(vtxPos.head<3>());
0224
0225
0226
0227
0228 BoundVector paramVec;
0229 paramVec[eBoundLoc0] = 0.;
0230 paramVec[eBoundLoc1] = 0.;
0231 paramVec[eBoundTime] = t0;
0232 paramVec[eBoundPhi] = phi;
0233 paramVec[eBoundTheta] = theta;
0234 paramVec[eBoundQOverP] = q / p;
0235
0236 BoundTrackParameters params(vtxPerigeeSurface, paramVec,
0237 makeBoundParametersCovariance(),
0238 ParticleHypothesis::pion());
0239
0240
0241
0242 ActsScalar corrTimeDiff = t0 - vt0;
0243
0244
0245 double cosPhi = std::cos(phi);
0246 double sinPhi = std::sin(phi);
0247 double sinTheta = std::sin(theta);
0248 Vector3 corrMomDir =
0249 Vector3(cosPhi * sinTheta, sinPhi * sinTheta, std::cos(theta));
0250
0251
0252 Vector3 refPoint(2_mm, -2_mm, -5_mm);
0253
0254
0255 auto refPerigeeSurface = Surface::makeShared<PerigeeSurface>(refPoint);
0256
0257
0258 PropagatorOptions pOptions(geoContext, magFieldContext);
0259 auto intersection = refPerigeeSurface
0260 ->intersect(geoContext, params.position(geoContext),
0261 params.direction(), BoundaryCheck(false))
0262 .closest();
0263 pOptions.direction =
0264 Direction::fromScalarZeroAsPositive(intersection.pathLength());
0265
0266
0267 auto result = propagator->propagate(params, *refPerigeeSurface, pOptions);
0268 BOOST_CHECK(result.ok());
0269 const auto& refParams = *result->endParameters;
0270
0271
0272 auto zeroFieldResult =
0273 straightLinePropagator->propagate(params, *refPerigeeSurface, pOptions);
0274 BOOST_CHECK(zeroFieldResult.ok());
0275 const auto& zeroFieldRefParams = *zeroFieldResult->endParameters;
0276
0277 BOOST_TEST_CONTEXT(
0278 "Check time at 2D PCA (i.e., function getImpactParameters) for helical "
0279 "tracks") {
0280
0281 auto ipParams = ipEstimator
0282 .getImpactParameters(refParams, vtx, geoContext,
0283 magFieldContext, true)
0284 .value();
0285
0286
0287 CHECK_CLOSE_ABS(ipParams.d0, 0., 30_nm);
0288 CHECK_CLOSE_ABS(ipParams.z0, 0., 100_nm);
0289
0290
0291 CHECK_CLOSE_OR_SMALL(ipParams.deltaT.value(), std::abs(corrTimeDiff), 1e-5,
0292 1e-3);
0293 }
0294
0295 auto checkGetDistanceAndMomentum = [&vtxPos, &corrMomDir, corrTimeDiff](
0296 const auto& ipe, const auto& rParams,
0297 auto& state) {
0298
0299
0300 auto distAndMom = ipe.template getDistanceAndMomentum<4>(
0301 geoContext, rParams, vtxPos, state)
0302 .value();
0303
0304 ActsVector<4> distVec = distAndMom.first;
0305 Vector3 momDir = distAndMom.second;
0306
0307
0308
0309 ActsScalar dist = distVec.head<3>().norm();
0310 CHECK_CLOSE_ABS(dist, 0., 30_nm);
0311
0312
0313
0314 CHECK_CLOSE_OR_SMALL(distVec[3], corrTimeDiff, 1e-5, 1e-4);
0315
0316
0317 CHECK_CLOSE_OR_SMALL(momDir, corrMomDir, 1e-5, 1e-4);
0318 };
0319
0320 BOOST_TEST_CONTEXT(
0321 "Check time at 3D PCA (i.e., function getDistanceAndMomentum) for "
0322 "straight tracks") {
0323 checkGetDistanceAndMomentum(zeroFieldIPEstimator, zeroFieldRefParams,
0324 zeroFieldIPState);
0325 }
0326 BOOST_TEST_CONTEXT(
0327 "Check time at 3D PCA (i.e., function getDistanceAndMomentum) for "
0328 "helical tracks") {
0329 checkGetDistanceAndMomentum(ipEstimator, refParams, ipState);
0330 }
0331 }
0332
0333 BOOST_DATA_TEST_CASE(VertexCompatibility4D, IPs* vertices, d0, l0, vx0, vy0,
0334 vz0, vt0) {
0335
0336 int seed = 31415;
0337 std::mt19937 gen(seed);
0338
0339
0340 Estimator ipEstimator = makeEstimator(2_T);
0341
0342
0343 Vector4 vtxPos(vx0, vy0, vz0, vt0);
0344
0345
0346 Transform3 coordinateSystem;
0347
0348 coordinateSystem.matrix().block<3, 3>(0, 0) = ActsSquareMatrix<3>::Identity();
0349
0350 coordinateSystem.matrix().block<3, 1>(0, 3) = vtxPos.head<3>();
0351
0352
0353 std::shared_ptr<PlaneSurface> planeSurface =
0354 Surface::makeShared<PlaneSurface>(coordinateSystem);
0355
0356
0357
0358
0359
0360 double timeDiffFactor = uniformDist(gen);
0361 double timeDiffClose = timeDiffFactor * 0.1_ps;
0362 double timeDiffFar = timeDiffFactor * 0.11_ps;
0363
0364
0365 double sgnClose = signDist(gen) < 0 ? -1. : 1.;
0366 double sgnFar = signDist(gen) < 0 ? -1. : 1.;
0367
0368 BoundVector paramVecClose = BoundVector::Zero();
0369 paramVecClose[eBoundLoc0] = d0;
0370 paramVecClose[eBoundLoc1] = l0;
0371 paramVecClose[eBoundTime] = vt0 + sgnClose * timeDiffClose;
0372
0373 BoundVector paramVecFar = paramVecClose;
0374 paramVecFar[eBoundTime] = vt0 + sgnFar * timeDiffFar;
0375
0376
0377 BoundTrackParameters paramsClose(planeSurface, paramVecClose,
0378 makeBoundParametersCovariance(30_ns),
0379 ParticleHypothesis::pion());
0380
0381
0382
0383 BoundTrackParameters paramsCloseLargerCov(
0384 planeSurface, paramVecClose, makeBoundParametersCovariance(31_ns),
0385 ParticleHypothesis::pion());
0386
0387
0388 BoundTrackParameters paramsFar(planeSurface, paramVecFar,
0389 makeBoundParametersCovariance(30_ns),
0390 ParticleHypothesis::pion());
0391
0392
0393 double compatibilityClose =
0394 ipEstimator.getVertexCompatibility(geoContext, ¶msClose, vtxPos)
0395 .value();
0396 double compatibilityCloseLargerCov =
0397 ipEstimator
0398 .getVertexCompatibility(geoContext, ¶msCloseLargerCov, vtxPos)
0399 .value();
0400 double compatibilityFar =
0401 ipEstimator.getVertexCompatibility(geoContext, ¶msFar, vtxPos)
0402 .value();
0403
0404
0405
0406 BOOST_CHECK_LT(compatibilityClose, compatibilityFar);
0407
0408 BOOST_CHECK_LT(compatibilityCloseLargerCov, compatibilityClose);
0409 }
0410
0411
0412
0413
0414
0415
0416
0417
0418 BOOST_AUTO_TEST_CASE(SingleTrackDistanceParametersAthenaRegression) {
0419 Estimator ipEstimator = makeEstimator(1.9971546939_T);
0420 Estimator::State state{magFieldCache()};
0421
0422
0423 Vector4 pos1(2_mm, 1_mm, -10_mm, 0_ns);
0424 Vector3 mom1(400_MeV, 600_MeV, 200_MeV);
0425 Vector3 vtxPos(1.2_mm, 0.8_mm, -7_mm);
0426
0427
0428 auto perigeeSurface =
0429 Surface::makeShared<PerigeeSurface>(pos1.segment<3>(ePos0));
0430
0431 auto params1 = BoundTrackParameters::create(
0432 perigeeSurface, geoContext, pos1, mom1, 1_e / mom1.norm(),
0433 BoundTrackParameters::CovarianceMatrix::Identity(),
0434 ParticleHypothesis::pion())
0435 .value();
0436
0437
0438 auto distance =
0439 ipEstimator.calculateDistance(geoContext, params1, vtxPos, state).value();
0440 CHECK_CLOSE_ABS(distance, 3.10391_mm, 10_nm);
0441
0442 auto res2 = ipEstimator.estimate3DImpactParameters(
0443 geoContext, magFieldContext, params1, vtxPos, state);
0444 BOOST_CHECK(res2.ok());
0445 BoundTrackParameters endParams = *res2;
0446 Vector3 surfaceCenter = endParams.referenceSurface().center(geoContext);
0447
0448 BOOST_CHECK_EQUAL(surfaceCenter, vtxPos);
0449 }
0450
0451
0452
0453
0454 BOOST_AUTO_TEST_CASE(Lifetimes2d3d) {
0455 Estimator ipEstimator = makeEstimator(2_T);
0456
0457
0458 BoundVector trk_par;
0459 trk_par[eBoundLoc0] = 200_um;
0460 trk_par[eBoundLoc1] = 300_um;
0461 trk_par[eBoundTime] = 1_ns;
0462 trk_par[eBoundPhi] = 45_degree;
0463 trk_par[eBoundTheta] = 45_degree;
0464 trk_par[eBoundQOverP] = 1_e / 10_GeV;
0465
0466 Vector4 ip_pos{0., 0., 0., 0.};
0467 Vertex ip_vtx(ip_pos, makeVertexCovariance(), {});
0468
0469
0470 auto perigeeSurface = Surface::makeShared<PerigeeSurface>(ip_pos.head<3>());
0471 BoundTrackParameters track(perigeeSurface, trk_par,
0472 makeBoundParametersCovariance(),
0473 ParticleHypothesis::pion());
0474
0475 Vector3 direction{0., 1., 0.};
0476 auto lifetimes_signs = ipEstimator.getLifetimeSignOfTrack(
0477 track, ip_vtx, direction, geoContext, magFieldContext);
0478
0479
0480 BOOST_CHECK(lifetimes_signs.ok());
0481
0482
0483 BOOST_CHECK_GT((*lifetimes_signs).first, 0.);
0484
0485
0486 BOOST_CHECK_LT((*lifetimes_signs).second, 0.);
0487
0488
0489
0490 auto sign3d = ipEstimator.get3DLifetimeSignOfTrack(
0491 track, ip_vtx, direction, geoContext, magFieldContext);
0492
0493
0494 BOOST_CHECK(sign3d.ok());
0495
0496
0497 BOOST_CHECK_GT((*sign3d), 0.);
0498 }
0499
0500
0501 BOOST_DATA_TEST_CASE(SingeTrackImpactParameters, tracks* vertices, d0, l0, t0,
0502 phi, theta, p, q, vx0, vy0, vz0, vt0) {
0503 BoundVector par;
0504 par[eBoundLoc0] = d0;
0505 par[eBoundLoc1] = l0;
0506 par[eBoundTime] = t0;
0507 par[eBoundPhi] = phi;
0508 par[eBoundTheta] = theta;
0509 par[eBoundQOverP] = q / p;
0510 Vector4 vtxPos;
0511 vtxPos[ePos0] = vx0;
0512 vtxPos[ePos1] = vy0;
0513 vtxPos[ePos2] = vz0;
0514 vtxPos[eTime] = vt0;
0515
0516 Estimator ipEstimator = makeEstimator(1_T);
0517 Estimator::State state{magFieldCache()};
0518
0519
0520 Vector3 refPosition(0., 0., 0.);
0521 auto perigeeSurface = Surface::makeShared<PerigeeSurface>(refPosition);
0522
0523 BoundTrackParameters track(perigeeSurface, par,
0524 makeBoundParametersCovariance(),
0525 ParticleHypothesis::pionLike(std::abs(q)));
0526 Vertex myConstraint(vtxPos, makeVertexCovariance(), {});
0527
0528
0529 ImpactParametersAndSigma output =
0530 ipEstimator
0531 .getImpactParameters(track, myConstraint, geoContext, magFieldContext)
0532 .value();
0533 BOOST_CHECK_NE(output.d0, 0.);
0534 BOOST_CHECK_NE(output.z0, 0.);
0535
0536
0537 }
0538
0539 BOOST_AUTO_TEST_SUITE_END()