Project
Loading...
Searching...
No Matches
TrackMatcher.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#include <algorithm>
18#include <map>
19
20#include <Math/SMatrix.h>
21#include <Math/SVector.h>
22
23#include "Framework/Logger.h"
26
27namespace o2
28{
29namespace muon
30{
31
35
36//_________________________________________________________________________________________________
39{
40 // set the maximum chi2 used for matching (4 parameters matched)
41 const auto& trackMatcherParam = TrackMatcherParam::Instance();
42 mMaxChi2 = 4. * trackMatcherParam.sigmaCut * trackMatcherParam.sigmaCut;
43}
44
45//_________________________________________________________________________________________________
47void TrackMatcher::match(gsl::span<const mch::ROFRecord>& mchROFs, gsl::span<const mch::TrackMCH>& mchTracks,
48 gsl::span<const mid::ROFRecord>& midROFs, gsl::span<const mid::Track>& midTracks)
49{
50 mMuons.clear();
51
52 if (mchROFs.empty() || midROFs.empty()) {
53 return;
54 }
55
56 // sort the MID ROFs in increasing time
57 std::map<InteractionRecord, int> midSortedROFs{};
58 for (int i = 0; i < midROFs.size(); ++i) {
59 midSortedROFs[midROFs[i].interactionRecord] = i;
60 }
61
62 for (const auto& mchROF : mchROFs) {
63
64 // find the MID ROFs in time with the MCH ROF
65 auto itStartMIDROF = midSortedROFs.lower_bound(mchROF.getBCData());
66 auto itEndMIDROF = midSortedROFs.upper_bound(mchROF.getBCData() + (mchROF.getBCWidth() - 1));
67
68 for (auto iMCHTrack = mchROF.getFirstIdx(); iMCHTrack <= mchROF.getLastIdx(); ++iMCHTrack) {
69
70 double bestMatchChi2(mMaxChi2);
71 int iBestMIDROF(-1);
72 uint32_t iBestMIDTrack(0);
73
74 for (auto itMIDROF = itStartMIDROF; itMIDROF != itEndMIDROF; ++itMIDROF) {
75
76 const auto& midROF = midROFs[itMIDROF->second];
77 for (auto iMIDTrack = midROF.firstEntry; iMIDTrack < midROF.firstEntry + midROF.nEntries; ++iMIDTrack) {
78
79 // try to match the current MCH track with the current MID track and keep the best matching
80 double matchChi2 = match(mchTracks[iMCHTrack], midTracks[iMIDTrack]);
81 if (matchChi2 < bestMatchChi2) {
82 bestMatchChi2 = matchChi2;
83 iBestMIDROF = itMIDROF->second;
84 iBestMIDTrack = uint32_t(iMIDTrack);
85 }
86 }
87 }
88
89 // store the muon track if the matching succeeded
90 if (iBestMIDROF >= 0) {
91 mMuons.emplace_back(uint32_t(iMCHTrack), iBestMIDTrack, midROFs[iBestMIDROF].interactionRecord,
92 bestMatchChi2 / 4.);
93 }
94 }
95 }
96
97 // sort the MUON tracks in increasing BC time
98 std::stable_sort(mMuons.begin(), mMuons.end(), [](const TrackMCHMID& mu1, const TrackMCHMID& mu2) {
99 return mu1.getIR() < mu2.getIR();
100 });
101}
102
103//_________________________________________________________________________________________________
105double TrackMatcher::match(const mch::TrackMCH& mchTrack, const mid::Track& midTrack)
106{
107 // compute the (X, slopeX, Y, slopeY) parameters difference between the 2 tracks at the z-position of the MID track
108 const double* mchParam = mchTrack.getParametersAtMID();
109 double dZ = midTrack.getPositionZ() - mchTrack.getZAtMID();
110 SVector4 paramDiff(mchParam[0] + mchParam[1] * dZ - midTrack.getPositionX(),
111 mchParam[1] - midTrack.getDirectionX(),
112 mchParam[2] + mchParam[3] * dZ - midTrack.getPositionY(),
113 mchParam[3] - midTrack.getDirectionY());
114
115 // propagate the MCH track covariances to the z-position of the MID track
116 SMatrixSym4 mchCov(mchTrack.getCovariancesAtMID(), 10);
117 SMatrix4 jacobian(ROOT::Math::SMatrixIdentity{});
118 jacobian(0, 1) = dZ;
119 jacobian(2, 3) = dZ;
120 auto sumCov = ROOT::Math::Similarity(jacobian, mchCov);
121
122 // add the MID track covariances
129
130 // compute the chi2
131 if (!sumCov.Invert()) {
132 LOG(error) << "Covariance matrix inversion failed: " << sumCov;
133 return mMaxChi2;
134 }
135 return ROOT::Math::Similarity(paramDiff, sumCov);
136}
137
138} // namespace muon
139} // namespace o2
int32_t i
Configurable parameters for MCH-MID track matching.
Definition of a class to match MCH and MID tracks.
MUON track external format.
Definition TrackMCHMID.h:33
MCH track external format.
Definition TrackMCH.h:34
double getZAtMID() const
get the track z position on the MID side where the parameters are evaluated
Definition TrackMCH.h:80
const double * getCovariancesAtMID() const
get the track parameter covariances on the MID side
Definition TrackMCH.h:90
const double * getParametersAtMID() const
get the track parameters on the MID side
Definition TrackMCH.h:85
This class defines the MID track.
Definition Track.h:30
float getDirectionY() const
Gets the track y direction.
Definition Track.h:48
float getDirectionX() const
Gets the track x direction.
Definition Track.h:46
@ VarX
Variance on X position.
@ VarY
Variance on Y position.
@ CovXSlopeX
Covariance on X position and slope.
@ CovYSlopeY
Covariance on Y position and slope.
float getPositionY() const
Gets the track y position.
Definition Track.h:35
float getCovarianceParameter(CovarianceParamIndex covParam) const
returns the covariance parameter covParam
Definition Track.h:70
float getPositionX() const
Gets the track x position.
Definition Track.h:33
float getPositionZ() const
Gets the track z position.
Definition Track.h:37
void init()
prepare to run the matching algorithm
void match(gsl::span< const mch::ROFRecord > &mchROFs, gsl::span< const mch::TrackMCH > &mchTracks, gsl::span< const mid::ROFRecord > &midROFs, gsl::span< const mid::Track > &midTracks)
run the matching algorithm
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< o2::mid::ROFRecord > midROFs
std::vector< o2::mch::ROFRecord > mchROFs
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"