Skip to content

Commit 30ee83f

Browse files
mcoquet642alcaliva
authored andcommitted
MFT-MCH matching: Implementing save of N best matching candidates (#13478)
* Implementing saving N matching candidates * Clang format * Adding comments * Fixing mistake in merging
1 parent fb0d7e3 commit 30ee83f

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

Detectors/GlobalTracking/include/GlobalTracking/MatchGlobalFwd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,14 @@ class MatchGlobalFwd
333333
std::vector<o2::mft::TrackMFT> mMFTMatchPlaneParams; ///< MFT track parameters at matching plane
334334
std::vector<o2::track::TrackParCovFwd> mMCHMatchPlaneParams; ///< MCH track parameters at matching plane
335335

336+
std::map<int, std::vector<std::pair<int, int>>> mCandidates; ///< map each MCH track id to vector of best match candidates
337+
336338
const o2::itsmft::TopologyDictionary* mMFTDict{nullptr}; // cluster patterns dictionary
337339
o2::itsmft::ChipMappingMFT mMFTMapping;
338340
bool mMCTruthON = false; ///< Flag availability of MC truth
339341
bool mUseMIDMCHMatch = false; ///< Flag for using MCHMID matches (TrackMCHMID)
340-
int mSaveMode = 0; ///< Output mode [0 = SaveBestMatch; 1 = SaveAllMatches; 2 = SaveTrainingData]
342+
int mSaveMode = 0; ///< Output mode [0 = SaveBestMatch; 1 = SaveAllMatches; 2 = SaveTrainingData; 3 = SaveNCandidates]
343+
int mNCandidates = 5; ///< Numbers of matching candidates to save in savemode=3
341344
MatchingType mMatchingType = MATCHINGUNDEFINED;
342345
TGeoManager* mGeoManager;
343346
};

Detectors/GlobalTracking/include/GlobalTracking/MatchGlobalFwdParam.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ namespace globaltracking
2626

2727
enum SaveMode { kBestMatch = 0,
2828
kSaveAll,
29-
kSaveTrainingData };
29+
kSaveTrainingData,
30+
kSaveNCandidates };
3031

3132
struct GlobalFwdMatchingParam : public o2::conf::ConfigurableParamHelper<GlobalFwdMatchingParam> {
3233

@@ -41,6 +42,7 @@ struct GlobalFwdMatchingParam : public o2::conf::ConfigurableParamHelper<GlobalF
4142
Int_t saveMode = kBestMatch; ///< Global Forward Tracks save mode
4243
float MFTRadLength = 0.042; ///< MFT thickness in radiation length
4344
float alignResidual = 1.; ///< Alignment residual for cluster position uncertainty
45+
int nCandidates = 5; ///< Number of best matching candidates to save in savemode=3
4446

4547
bool
4648
isMatchUpstream() const

Detectors/GlobalTracking/src/MatchGlobalFwd.cxx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include "GlobalTracking/MatchGlobalFwd.h"
13+
#include <queue>
1314

1415
using namespace o2::globaltracking;
1516

@@ -66,6 +67,8 @@ void MatchGlobalFwd::init()
6667

6768
mSaveMode = matchingParam.saveMode;
6869
LOG(info) << "Save mode MFTMCH candidates = " << mSaveMode;
70+
71+
mNCandidates = matchingParam.nCandidates;
6972
}
7073

7174
//_________________________________________________________
@@ -98,6 +101,9 @@ void MatchGlobalFwd::run(const o2::globaltracking::RecoContainer& inp)
98101
case kSaveTrainingData:
99102
doMatching<kSaveTrainingData>();
100103
break;
104+
case kSaveNCandidates:
105+
doMatching<kSaveNCandidates>();
106+
break;
101107
default:
102108
LOG(fatal) << "Invalid MFTMCH save mode";
103109
}
@@ -132,6 +138,7 @@ void MatchGlobalFwd::clear()
132138
mMatchLabels.clear();
133139
mMFTTrackROFContMapping.clear();
134140
mMatchingInfo.clear();
141+
mCandidates.clear();
135142
}
136143

137144
//_________________________________________________________
@@ -400,6 +407,25 @@ void MatchGlobalFwd::doMatching()
400407
if (mMCTruthON) {
401408
LOG(info) << " MFT-MCH Matching: nFakes = " << nFakes << " nTrue = " << nTrue;
402409
}
410+
} else if constexpr (saveAllMode == SaveMode::kSaveNCandidates) {
411+
int nFakes = 0, nTrue = 0;
412+
auto& matchAllChi2 = mMatchingFunctionMap["matchALL"];
413+
for (auto MCHId = 0; MCHId < mMCHWork.size(); MCHId++) {
414+
auto& thisMCHTrack = mMCHWork[MCHId];
415+
for (auto& pairCandidate : mCandidates[MCHId]) {
416+
thisMCHTrack.setMFTTrackID(pairCandidate.second);
417+
auto& thisMFTTrack = mMFTWork[pairCandidate.second];
418+
auto chi2 = matchAllChi2(thisMCHTrack, thisMFTTrack); // Matching chi2 is stored independently
419+
thisMCHTrack.setMFTMCHMatchingScore(pairCandidate.first);
420+
thisMCHTrack.setMFTMCHMatchingChi2(chi2);
421+
mMatchedTracks.emplace_back(thisMCHTrack);
422+
mMatchingInfo.emplace_back(thisMCHTrack);
423+
if (mMCTruthON) {
424+
mMatchLabels.push_back(computeLabel(MCHId, pairCandidate.second));
425+
mMatchLabels.back().isFake() ? nFakes++ : nTrue++;
426+
}
427+
}
428+
}
403429
}
404430
}
405431

@@ -413,6 +439,10 @@ void MatchGlobalFwd::ROFMatch(int MFTROFId, int firstMCHROFId, int lastMCHROFId)
413439
const auto& lastMCHROF = mMCHTrackROFRec[lastMCHROFId];
414440
int nFakes = 0, nTrue = 0;
415441

442+
auto compare = [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
443+
return a.first < b.first;
444+
};
445+
416446
auto firstMFTTrackID = thisMFTROF.getFirstEntry();
417447
auto lastMFTTrackID = firstMFTTrackID + thisMFTROF.getNEntries() - 1;
418448

@@ -464,12 +494,21 @@ void MatchGlobalFwd::ROFMatch(int MFTROFId, int firstMCHROFId, int lastMCHROFId)
464494
}
465495
}
466496

497+
if constexpr (saveAllMode == SaveMode::kSaveNCandidates) { // In saveAllmode save all pairs to output container
498+
auto score = mMatchFunc(thisMCHTrack, thisMFTTrack);
499+
std::pair<int, int> scoreID = {score, MFTId};
500+
mCandidates[MCHId].push_back(scoreID);
501+
std::sort(mCandidates[MCHId].begin(), mCandidates[MCHId].end(), compare);
502+
if (mCandidates[MCHId].size() > mNCandidates) {
503+
mCandidates[MCHId].pop_back();
504+
}
505+
}
506+
467507
if constexpr (saveAllMode == SaveMode::kSaveTrainingData) { // In save training data mode store track parameters at matching plane
468508
thisMCHTrack.setMFTTrackID(MFTId);
469509
mMatchingInfo.emplace_back(thisMCHTrack);
470510
mMCHMatchPlaneParams.emplace_back(thisMCHTrack);
471511
mMFTMatchPlaneParams.emplace_back(static_cast<o2::mft::TrackMFT>(thisMFTTrack));
472-
473512
if (mMCTruthON) {
474513
mMatchLabels.push_back(matchLabel);
475514
mMatchLabels.back().isFake() ? nFakes++ : nTrue++;

0 commit comments

Comments
 (0)