File indexing completed on 2025-11-04 09:24:15
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/GenericBoundTrackParameters.hpp"
0018 #include "Acts/EventData/TrackParameters.hpp"
0019 #include "Acts/Geometry/GeometryContext.hpp"
0020 #include "Acts/Geometry/GeometryIdentifier.hpp"
0021 #include "Acts/MagneticField/ConstantBField.hpp"
0022 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0023 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0024 #include "Acts/MagneticField/NullBField.hpp"
0025 #include "Acts/Propagator/EigenStepper.hpp"
0026 #include "Acts/Propagator/Propagator.hpp"
0027 #include "Acts/Propagator/StraightLineStepper.hpp"
0028 #include "Acts/Propagator/VoidNavigator.hpp"
0029 #include "Acts/Surfaces/PerigeeSurface.hpp"
0030 #include "Acts/Surfaces/PlaneSurface.hpp"
0031 #include "Acts/Surfaces/Surface.hpp"
0032 #include "Acts/Utilities/Intersection.hpp"
0033 #include "Acts/Utilities/Logger.hpp"
0034 #include "Acts/Utilities/Result.hpp"
0035 #include "Acts/Vertexing/ImpactPointEstimator.hpp"
0036 #include "Acts/Vertexing/Vertex.hpp"
0037 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0038
0039 #include <cmath>
0040 #include <limits>
0041 #include <memory>
0042 #include <numbers>
0043 #include <optional>
0044 #include <utility>
0045 #include <vector>
0046
0047 namespace ActsTests {
0048
0049 namespace bd = boost::unit_test::data;
0050
0051 using namespace Acts;
0052 using namespace Acts::UnitLiterals;
0053 using Acts::VectorHelpers::makeVector4;
0054
0055 using MagneticField = ConstantBField;
0056 using StraightPropagator = Propagator<StraightLineStepper>;
0057 using Stepper = EigenStepper<>;
0058 using Propagator = Acts::Propagator<Stepper>;
0059 using Estimator = ImpactPointEstimator;
0060 using StraightLineEstimator = ImpactPointEstimator;
0061
0062 const GeometryContext geoContext;
0063 const MagneticFieldContext magFieldContext;
0064
0065 MagneticFieldProvider::Cache magFieldCache() {
0066 return NullBField{}.makeCache(magFieldContext);
0067 }
0068
0069
0070
0071 auto d0s = bd::make({-25_um, 25_um});
0072 auto l0s = bd::make({-1_mm, 1_mm});
0073 auto t0s = bd::make({-2_ns, 2_ns});
0074 auto phis = bd::make({0_degree, -45_degree, 45_degree});
0075 auto thetas = bd::make({90_degree, 20_degree, 160_degree});
0076 auto ps = bd::make({0.4_GeV, 1_GeV, 10_GeV});
0077 auto qs = bd::make({-1_e, 1_e});
0078
0079 auto tracksWithoutIPs = t0s * phis * thetas * ps * qs;
0080 auto IPs = d0s * l0s;
0081 auto tracks = IPs * tracksWithoutIPs;
0082
0083
0084 auto vx0s = bd::make({0_um, -10_um, 10_um});
0085 auto vy0s = bd::make({0_um, -10_um, 10_um});
0086 auto vz0s = bd::make({0_mm, -25_mm, 25_mm});
0087 auto vt0s = bd::make({0_ns, -2_ns, 2_ns});
0088
0089 auto vertices = vx0s * vy0s * vz0s * vt0s;
0090
0091
0092 Estimator makeEstimator(double bZ) {
0093 auto field = std::make_shared<MagneticField>(Vector3(0, 0, bZ));
0094 Stepper stepper(field);
0095 Estimator::Config cfg(field,
0096 std::make_shared<Propagator>(
0097 std::move(stepper), VoidNavigator(),
0098 getDefaultLogger("Prop", Logging::Level::WARNING)));
0099 return Estimator(cfg);
0100 }
0101
0102
0103 BoundSquareMatrix makeBoundParametersCovariance(double stdDevTime = 30_ps) {
0104 BoundVector stddev;
0105 stddev[eBoundLoc0] = 15_um;
0106 stddev[eBoundLoc1] = 100_um;
0107 stddev[eBoundTime] = stdDevTime;
0108 stddev[eBoundPhi] = 1_degree;
0109 stddev[eBoundTheta] = 1_degree;
0110 stddev[eBoundQOverP] = 1_e / 100_GeV;
0111 return stddev.cwiseProduct(stddev).asDiagonal();
0112 }
0113
0114
0115 SquareMatrix4 makeVertexCovariance() {
0116 Vector4 stddev;
0117 stddev[ePos0] = 10_um;
0118 stddev[ePos1] = 10_um;
0119 stddev[ePos2] = 75_um;
0120 stddev[eTime] = 1_ns;
0121 return stddev.cwiseProduct(stddev).asDiagonal();
0122 }
0123
0124
0125 std::uniform_real_distribution<double> uniformDist(0.0, 1.0);
0126
0127 std::uniform_real_distribution<double> signDist(-1, 1);
0128
0129 BOOST_AUTO_TEST_SUITE(VertexingSuite)
0130
0131
0132
0133 BOOST_DATA_TEST_CASE(SingleTrackDistanceParametersCompatibility3D, tracks, d0,
0134 l0, t0, phi, theta, p, q) {
0135 auto particleHypothesis = ParticleHypothesis::pion();
0136
0137 BoundVector par;
0138 par[eBoundLoc0] = d0;
0139 par[eBoundLoc1] = l0;
0140 par[eBoundTime] = t0;
0141 par[eBoundPhi] = phi;
0142 par[eBoundTheta] = theta;
0143 par[eBoundQOverP] = particleHypothesis.qOverP(p, q);
0144
0145 Estimator ipEstimator = makeEstimator(2_T);
0146 Estimator::State state{magFieldCache()};
0147
0148 Vector3 refPosition(0., 0., 0.);
0149 auto perigeeSurface = Surface::makeShared<PerigeeSurface>(refPosition);
0150
0151 BoundTrackParameters myTrack(
0152 perigeeSurface, par, makeBoundParametersCovariance(), particleHypothesis);
0153
0154
0155 double distT = std::hypot(d0, l0);
0156 double dist3 =
0157 ipEstimator.calculateDistance(geoContext, myTrack, refPosition, state)
0158 .value();
0159
0160
0161
0162
0163 BOOST_CHECK((dist3 < distT) ||
0164 (theta == 90_degree && std::abs(dist3 - distT) < 1_nm));
0165
0166
0167 auto res = ipEstimator.estimate3DImpactParameters(
0168 geoContext, magFieldContext, myTrack, refPosition, state);
0169 BoundTrackParameters trackAtIP3d = *res;
0170 const auto& atPerigee = myTrack.parameters();
0171 const auto& atIp3d = trackAtIP3d.parameters();
0172
0173
0174 BOOST_CHECK_NE(atPerigee[eBoundLoc0], atIp3d[eBoundLoc0]);
0175 BOOST_CHECK_NE(atPerigee[eBoundLoc1], atIp3d[eBoundLoc1]);
0176
0177
0178 CHECK_CLOSE_ABS(atPerigee[eBoundTheta], atIp3d[eBoundTheta], 0.01_mrad);
0179 CHECK_CLOSE_REL(atPerigee[eBoundQOverP], atIp3d[eBoundQOverP],
0180 std::numeric_limits<double>::epsilon());
0181
0182
0183
0184 auto compatibility =
0185 ipEstimator.getVertexCompatibility(geoContext, &trackAtIP3d, refPosition)
0186 .value();
0187 BOOST_CHECK_GT(compatibility, 0);
0188 }
0189
0190 BOOST_DATA_TEST_CASE(TimeAtPca, tracksWithoutIPs* vertices, t0, phi, theta, p,
0191 q, vx0, vy0, vz0, vt0) {
0192 using Propagator = Acts::Propagator<Stepper>;
0193 using PropagatorOptions = Propagator::Options<>;
0194 using StraightPropagator = Acts::Propagator<StraightLineStepper>;
0195
0196
0197 auto field = std::make_shared<MagneticField>(Vector3(0, 0, 2_T));
0198 Stepper stepper(field);
0199 auto propagator = std::make_shared<Propagator>(std::move(stepper));
0200 Estimator::Config cfg(field, propagator);
0201 Estimator ipEstimator(cfg);
0202 Estimator::State ipState{magFieldCache()};
0203
0204
0205 auto zeroField = std::make_shared<MagneticField>(Vector3(0, 0, 0));
0206 StraightLineStepper straightLineStepper;
0207 auto straightLinePropagator =
0208 std::make_shared<StraightPropagator>(straightLineStepper);
0209 StraightLineEstimator::Config zeroFieldCfg(zeroField, straightLinePropagator);
0210 StraightLineEstimator zeroFieldIPEstimator(zeroFieldCfg);
0211 StraightLineEstimator::State zeroFieldIPState{magFieldCache()};
0212
0213
0214 Vector4 vtxPos(vx0, vy0, vz0, vt0);
0215 Vertex vtx(vtxPos, makeVertexCovariance(), {});
0216
0217
0218 auto vtxPerigeeSurface =
0219 Surface::makeShared<PerigeeSurface>(vtxPos.head<3>());
0220
0221
0222
0223
0224 BoundVector paramVec;
0225 paramVec[eBoundLoc0] = 0.;
0226 paramVec[eBoundLoc1] = 0.;
0227 paramVec[eBoundTime] = t0;
0228 paramVec[eBoundPhi] = phi;
0229 paramVec[eBoundTheta] = theta;
0230 paramVec[eBoundQOverP] = q / p;
0231
0232 BoundTrackParameters params(vtxPerigeeSurface, paramVec,
0233 makeBoundParametersCovariance(),
0234 ParticleHypothesis::pion());
0235
0236
0237
0238 double corrTimeDiff = t0 - vt0;
0239
0240
0241 double cosPhi = std::cos(phi);
0242 double sinPhi = std::sin(phi);
0243 double sinTheta = std::sin(theta);
0244 Vector3 corrMomDir =
0245 Vector3(cosPhi * sinTheta, sinPhi * sinTheta, std::cos(theta));
0246
0247
0248 Vector3 refPoint(2_mm, -2_mm, -5_mm);
0249
0250
0251 auto refPerigeeSurface = Surface::makeShared<PerigeeSurface>(refPoint);
0252
0253
0254 PropagatorOptions pOptions(geoContext, magFieldContext);
0255 Intersection3D intersection =
0256 refPerigeeSurface
0257 ->intersect(geoContext, params.position(geoContext),
0258 params.direction(), BoundaryTolerance::Infinite())
0259 .closest();
0260 pOptions.direction =
0261 Direction::fromScalarZeroAsPositive(intersection.pathLength());
0262
0263 StraightPropagator::Options<> straightPOptions(geoContext, magFieldContext);
0264 straightPOptions.direction = pOptions.direction;
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 = straightLinePropagator->propagate(
0273 params, *refPerigeeSurface, straightPOptions);
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 Vector4 distVec = distAndMom.first;
0305 Vector3 momDir = distAndMom.second;
0306
0307
0308
0309 double 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[eBoundPhi] = 0;
0372 paramVecClose[eBoundTheta] = std::numbers::pi / 2;
0373 paramVecClose[eBoundQOverP] = 0;
0374 paramVecClose[eBoundTime] = vt0 + sgnClose * timeDiffClose;
0375
0376 BoundVector paramVecFar = paramVecClose;
0377 paramVecFar[eBoundTime] = vt0 + sgnFar * timeDiffFar;
0378
0379
0380 BoundTrackParameters paramsClose(planeSurface, paramVecClose,
0381 makeBoundParametersCovariance(30_ns),
0382 ParticleHypothesis::pion());
0383
0384
0385
0386 BoundTrackParameters paramsCloseLargerCov(
0387 planeSurface, paramVecClose, makeBoundParametersCovariance(31_ns),
0388 ParticleHypothesis::pion());
0389
0390
0391 BoundTrackParameters paramsFar(planeSurface, paramVecFar,
0392 makeBoundParametersCovariance(30_ns),
0393 ParticleHypothesis::pion());
0394
0395
0396 double compatibilityClose =
0397 ipEstimator.getVertexCompatibility(geoContext, ¶msClose, vtxPos)
0398 .value();
0399 double compatibilityCloseLargerCov =
0400 ipEstimator
0401 .getVertexCompatibility(geoContext, ¶msCloseLargerCov, vtxPos)
0402 .value();
0403 double compatibilityFar =
0404 ipEstimator.getVertexCompatibility(geoContext, ¶msFar, vtxPos)
0405 .value();
0406
0407
0408
0409 BOOST_CHECK_LT(compatibilityClose, compatibilityFar);
0410
0411 BOOST_CHECK_LT(compatibilityCloseLargerCov, compatibilityClose);
0412 }
0413
0414
0415
0416
0417
0418
0419
0420
0421 BOOST_AUTO_TEST_CASE(SingleTrackDistanceParametersAthenaRegression) {
0422 Estimator ipEstimator = makeEstimator(1.9971546939_T);
0423 Estimator::State state{magFieldCache()};
0424
0425
0426 Vector4 pos1(2_mm, 1_mm, -10_mm, 0_ns);
0427 Vector3 mom1(400_MeV, 600_MeV, 200_MeV);
0428 Vector3 vtxPos(1.2_mm, 0.8_mm, -7_mm);
0429
0430
0431 auto perigeeSurface =
0432 Surface::makeShared<PerigeeSurface>(pos1.segment<3>(ePos0));
0433
0434 auto params1 = BoundTrackParameters::create(
0435 geoContext, perigeeSurface, pos1, mom1, 1_e / mom1.norm(),
0436 BoundTrackParameters::CovarianceMatrix::Identity(),
0437 ParticleHypothesis::pion())
0438 .value();
0439
0440
0441 auto distance =
0442 ipEstimator.calculateDistance(geoContext, params1, vtxPos, state).value();
0443 CHECK_CLOSE_ABS(distance, 3.10391_mm, 10_nm);
0444
0445 auto res2 = ipEstimator.estimate3DImpactParameters(
0446 geoContext, magFieldContext, params1, vtxPos, state);
0447 BOOST_CHECK(res2.ok());
0448 BoundTrackParameters endParams = *res2;
0449 Vector3 surfaceCenter = endParams.referenceSurface().center(geoContext);
0450
0451 BOOST_CHECK_EQUAL(surfaceCenter, vtxPos);
0452 }
0453
0454
0455
0456
0457 BOOST_AUTO_TEST_CASE(Lifetimes2d3d) {
0458 Estimator ipEstimator = makeEstimator(2_T);
0459
0460
0461 BoundVector trk_par;
0462 trk_par[eBoundLoc0] = 200_um;
0463 trk_par[eBoundLoc1] = 300_um;
0464 trk_par[eBoundTime] = 1_ns;
0465 trk_par[eBoundPhi] = 45_degree;
0466 trk_par[eBoundTheta] = 45_degree;
0467 trk_par[eBoundQOverP] = 1_e / 10_GeV;
0468
0469 Vector4 ip_pos{0., 0., 0., 0.};
0470 Vertex ip_vtx(ip_pos, makeVertexCovariance(), {});
0471
0472
0473 auto perigeeSurface = Surface::makeShared<PerigeeSurface>(ip_pos.head<3>());
0474 BoundTrackParameters track(perigeeSurface, trk_par,
0475 makeBoundParametersCovariance(),
0476 ParticleHypothesis::pion());
0477
0478 Vector3 direction{0., 1., 0.};
0479 auto lifetimes_signs = ipEstimator.getLifetimeSignOfTrack(
0480 track, ip_vtx, direction, geoContext, magFieldContext);
0481
0482
0483 BOOST_CHECK(lifetimes_signs.ok());
0484
0485
0486 BOOST_CHECK_GT((*lifetimes_signs).first, 0.);
0487
0488
0489 BOOST_CHECK_LT((*lifetimes_signs).second, 0.);
0490
0491
0492
0493 auto sign3d = ipEstimator.get3DLifetimeSignOfTrack(
0494 track, ip_vtx, direction, geoContext, magFieldContext);
0495
0496
0497 BOOST_CHECK(sign3d.ok());
0498
0499
0500 BOOST_CHECK_GT((*sign3d), 0.);
0501 }
0502
0503
0504 BOOST_DATA_TEST_CASE(SingeTrackImpactParameters, tracks* vertices, d0, l0, t0,
0505 phi, theta, p, q, vx0, vy0, vz0, vt0) {
0506 BoundVector par;
0507 par[eBoundLoc0] = d0;
0508 par[eBoundLoc1] = l0;
0509 par[eBoundTime] = t0;
0510 par[eBoundPhi] = phi;
0511 par[eBoundTheta] = theta;
0512 par[eBoundQOverP] = q / p;
0513 Vector4 vtxPos;
0514 vtxPos[ePos0] = vx0;
0515 vtxPos[ePos1] = vy0;
0516 vtxPos[ePos2] = vz0;
0517 vtxPos[eTime] = vt0;
0518
0519 Estimator ipEstimator = makeEstimator(1_T);
0520 Estimator::State state{magFieldCache()};
0521
0522
0523 Vector3 refPosition(0., 0., 0.);
0524 auto perigeeSurface = Surface::makeShared<PerigeeSurface>(refPosition);
0525
0526 BoundTrackParameters track(perigeeSurface, par,
0527 makeBoundParametersCovariance(),
0528 ParticleHypothesis::pionLike(std::abs(q)));
0529 Vertex myConstraint(vtxPos, makeVertexCovariance(), {});
0530
0531
0532 ImpactParametersAndSigma output =
0533 ipEstimator
0534 .getImpactParameters(track, myConstraint, geoContext, magFieldContext)
0535 .value();
0536 BOOST_CHECK_NE(output.d0, 0.);
0537 BOOST_CHECK_NE(output.z0, 0.);
0538
0539
0540 }
0541
0542 BOOST_AUTO_TEST_SUITE_END()
0543
0544 }