File indexing completed on 2026-11-28 09:20:51
0001
0002
0003
0004 #include "TwoTrackVertexSeeder.h"
0005
0006 #include <Acts/Definitions/Common.hpp>
0007 #include <Acts/Utilities/Result.hpp>
0008 #include <Acts/Vertexing/TrackAtVertex.hpp>
0009 #include <Acts/Vertexing/Vertex.hpp>
0010 #include <Acts/Vertexing/VertexingOptions.hpp>
0011 #include <Eigen/Core>
0012 #include <cmath>
0013 #include <functional>
0014 #include <system_error>
0015 #include <vector>
0016
0017 namespace eicrecon {
0018
0019 namespace {
0020
0021
0022
0023 struct Helix {
0024 Acts::Vector3 origin;
0025 double phi0;
0026 double cotTheta;
0027
0028 double h;
0029
0030 Acts::Vector3 position(double s) const {
0031 if (std::abs(h * s) < 1e-9) {
0032 return origin + s * Acts::Vector3(std::cos(phi0), std::sin(phi0), cotTheta);
0033 }
0034 const double phi = phi0 + h * s;
0035 return origin + Acts::Vector3((std::sin(phi) - std::sin(phi0)) / h,
0036 (std::cos(phi0) - std::cos(phi)) / h, s * cotTheta);
0037 }
0038
0039 Acts::Vector3 tangent(double s) const {
0040 const double phi = phi0 + h * s;
0041 return {std::cos(phi), std::sin(phi), cotTheta};
0042 }
0043 };
0044
0045 Helix makeHelix(const Acts::BoundTrackParameters& track, const Acts::GeometryContext& gctx,
0046 double bz) {
0047 const double pt = track.transverseMomentum();
0048
0049 const double h = (pt > 0) ? -track.charge() * bz / pt : 0.;
0050 return {.origin = track.position(gctx),
0051 .phi0 = track.phi(),
0052 .cotTheta = 1. / std::tan(track.theta()),
0053 .h = h};
0054 }
0055
0056 }
0057
0058 Acts::Vector3 TwoTrackVertexSeeder::closestApproach(const Acts::BoundTrackParameters& track1,
0059 const Acts::BoundTrackParameters& track2,
0060 const Acts::GeometryContext& gctx,
0061 double bz) const {
0062 const Helix h1 = makeHelix(track1, gctx, bz);
0063 const Helix h2 = makeHelix(track2, gctx, bz);
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 double s1 = 0.;
0078 double s2 = 0.;
0079 for (unsigned int i = 0; i < m_cfg.maxIterations; ++i) {
0080 const Acts::Vector3 w = h1.position(s1) - h2.position(s2);
0081 const Acts::Vector3 t1 = h1.tangent(s1);
0082 const Acts::Vector3 t2 = h2.tangent(s2);
0083 const double a = t1.dot(t1);
0084 const double b = t1.dot(t2);
0085 const double c = t2.dot(t2);
0086 const double d = t1.dot(w);
0087 const double e = t2.dot(w);
0088 const double det = a * c - b * b;
0089 if (det < 1e-12 * a * c) {
0090
0091 break;
0092 }
0093 const double ds1 = (b * e - c * d) / det;
0094 const double ds2 = (a * e - b * d) / det;
0095 if (!std::isfinite(ds1) || !std::isfinite(ds2)) {
0096 break;
0097 }
0098 s1 += ds1;
0099 s2 += ds2;
0100 if (std::abs(ds1) < m_cfg.tolerance && std::abs(ds2) < m_cfg.tolerance) {
0101 break;
0102 }
0103 }
0104
0105 Acts::Vector3 seed = 0.5 * (h1.position(s1) + h2.position(s2));
0106 if (!seed.allFinite()) {
0107 seed = 0.5 * (h1.origin + h2.origin);
0108 }
0109 return seed;
0110 }
0111
0112 Acts::Result<std::vector<Acts::Vertex>>
0113 TwoTrackVertexSeeder::find(const std::vector<Acts::InputTrack>& trackVector,
0114 const Acts::VertexingOptions& vertexingOptions,
0115 Acts::IVertexFinder::State& ) const {
0116 if (trackVector.size() != 2) {
0117 return std::vector<Acts::Vertex>{};
0118 }
0119
0120 const auto& track1 = Acts::InputTrack::extractParameters(trackVector[0]);
0121 const auto& track2 = Acts::InputTrack::extractParameters(trackVector[1]);
0122 const auto& gctx = vertexingOptions.geoContext.get();
0123
0124
0125 auto cache = m_cfg.bField->makeCache(vertexingOptions.magFieldContext);
0126 const Acts::Vector3 mid = 0.5 * (track1.position(gctx) + track2.position(gctx));
0127 auto field = m_cfg.bField->getField(mid, cache);
0128 if (!field.ok()) {
0129 return field.error();
0130 }
0131
0132 Acts::Vertex seed(closestApproach(track1, track2, gctx, (*field)[Acts::eZ]));
0133 seed.setFullCovariance(vertexingOptions.constraint.fullCovariance());
0134 return std::vector<Acts::Vertex>{seed};
0135 }
0136
0137 Acts::IVertexFinder::State
0138 TwoTrackVertexSeeder::makeState(const Acts::MagneticFieldContext& ) const {
0139 return Acts::IVertexFinder::State{State{}};
0140 }
0141
0142 void TwoTrackVertexSeeder::setTracksToRemove(
0143 Acts::IVertexFinder::State& ,
0144 const std::vector<Acts::InputTrack>& ) const {
0145
0146 }
0147
0148 }