1010// or submit itself to any jurisdiction.
1111
1212#include " GlobalTracking/MatchGlobalFwd.h"
13+ #include < queue>
1314
1415using 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