|
27 | 27 | #include <Math/MatrixRepresentationsStatic.h> |
28 | 28 | #include <Math/SMatrix.h> |
29 | 29 |
|
| 30 | +#include <algorithm> |
30 | 31 | #include <array> |
| 32 | +#include <cmath> |
31 | 33 | #include <concepts> |
32 | 34 | #include <cstdint> |
33 | 35 | #include <type_traits> |
@@ -243,6 +245,68 @@ o2::dataformats::GlobalFwdTrack refitGlobalMuonCov(TFwdTrack const& muon, TMFTTr |
243 | 245 | return globalTrack; |
244 | 246 | } |
245 | 247 |
|
| 248 | +template <typename TFullFwdTrack, typename TCollision> |
| 249 | +float getFwdChi2IP(const TFullFwdTrack& fwdtrack, const TCollision& collision, const float bz, const float zShift) |
| 250 | +{ |
| 251 | + // this function returns imcompatibility of fwdtrack respect to a given PV. |
| 252 | + // fwdtracks are never PV contributors in ALICE. |
| 253 | + // chi2IP is defined as chi2^{PV}_{with fwdtrack} - chi2^{PV}_{without fwdtrack}. https://arxiv.org/abs/2604.11574 |
| 254 | + // chi2IP cannot be used to decide the best fwdtrack-to-collision match or MFT-MCH match, because it gives biases toward small muon impact parameter. |
| 255 | + // chi2IP should be used only after the best fwdtrack-to-collision association and the best MFT-MCH match are defined. |
| 256 | + |
| 257 | + o2::track::TrackParCovFwd trk = getTrackParCovFwdShift(fwdtrack, zShift, fwdtrack); |
| 258 | + |
| 259 | + if (std::abs(bz) < 1e-12) { |
| 260 | + trk.propagateToZlinear(collision.posZ()); |
| 261 | + } else { |
| 262 | + trk.propagateToZhelix(collision.posZ(), bz); |
| 263 | + } |
| 264 | + |
| 265 | + float x = trk.getX(); |
| 266 | + float y = trk.getY(); |
| 267 | + float phi = trk.getPhi(); |
| 268 | + float tgl = trk.getTanl(); |
| 269 | + |
| 270 | + if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(phi) || !std::isfinite(tgl) || std::abs(tgl) < 1e-8) { |
| 271 | + return -1.f; |
| 272 | + } |
| 273 | + |
| 274 | + float dx = x - collision.posX(); |
| 275 | + float dy = y - collision.posY(); |
| 276 | + |
| 277 | + // dx/dz and dy/dz for TrackParFwd. |
| 278 | + float tx = std::cos(phi) / tgl; |
| 279 | + float ty = std::sin(phi) / tgl; |
| 280 | + |
| 281 | + const auto& ct = trk.getCovariances(); |
| 282 | + |
| 283 | + float trkXX = ct(0, 0); |
| 284 | + float trkXY = ct(0, 1); |
| 285 | + float trkYY = ct(1, 1); |
| 286 | + |
| 287 | + float pvXX = collision.covXX() - 2.0 * tx * collision.covXZ() + tx * tx * collision.covZZ(); |
| 288 | + float pvXY = collision.covXY() - ty * collision.covXZ() - tx * collision.covYZ() + tx * ty * collision.covZZ(); |
| 289 | + float pvYY = collision.covYY() - 2.0 * ty * collision.covYZ() + ty * ty * collision.covZZ(); |
| 290 | + |
| 291 | + float sXX = trkXX + pvXX; |
| 292 | + float sXY = trkXY + pvXY; |
| 293 | + float sYY = trkYY + pvYY; |
| 294 | + |
| 295 | + float det = sXX * sYY - sXY * sXY; |
| 296 | + |
| 297 | + if (!std::isfinite(det) || det <= 0.0) { |
| 298 | + return -1.f; |
| 299 | + } |
| 300 | + |
| 301 | + float chi2 = (sYY * dx * dx - 2.0 * sXY * dx * dy + sXX * dy * dy) / det; |
| 302 | + |
| 303 | + if (!std::isfinite(chi2) || chi2 < -1e-8) { |
| 304 | + return -1.f; |
| 305 | + } |
| 306 | + |
| 307 | + return std::max(0.f, chi2); |
| 308 | +} |
| 309 | + |
246 | 310 | } // namespace fwdtrackutils |
247 | 311 | } // namespace o2::aod |
248 | 312 |
|
|
0 commit comments