@@ -143,6 +143,7 @@ DECLARE_SOA_COLUMN(Chi2Glob, chi2Glob, float);
143143DECLARE_SOA_COLUMN (Chi2Match, chi2Match, float );
144144DECLARE_SOA_COLUMN (IsAmbig, isAmbig, bool );
145145DECLARE_SOA_COLUMN (MFTMult, mftMult, int );
146+ DECLARE_SOA_COLUMN (MatchAttempts, matchAttempts, int );
146147DECLARE_SOA_COLUMN (DCAX , dcaX, float );
147148DECLARE_SOA_COLUMN (DCAY , dcaY, float );
148149DECLARE_SOA_COLUMN (McMaskGlob, mcMaskGlob, int );
@@ -207,6 +208,7 @@ DECLARE_SOA_TABLE(FwdMatchMLCandidates, "AOD", "FWDMLCAND",
207208 fwdmatchcandidates::DCAY ,
208209 fwdmatchcandidates::IsAmbig,
209210 fwdmatchcandidates::MFTMult,
211+ fwdmatchcandidates::MatchAttempts,
210212 fwdmatchcandidates::McMaskMCH,
211213 fwdmatchcandidates::McMaskMFT,
212214 fwdmatchcandidates::McMaskGlob,
@@ -268,7 +270,6 @@ struct mftMchMatcher {
268270 kMatchTypeUndefined
269271 };
270272
271- double mBzAtMftCenter {0 };
272273 o2::globaltracking::MatchGlobalFwd mExtrap ;
273274
274275 int mRunNumber {0 }; // needed to detect if the run changed and trigger update of magnetic field
@@ -470,7 +471,7 @@ struct mftMchMatcher {
470471 }
471472 }
472473 }
473- for (auto & pairCand : mCandidates ) {
474+ for (const auto & pairCand : mCandidates ) {
474475 fBestMatch [pairCand.second .second ] = true ;
475476 }
476477 }
@@ -593,14 +594,50 @@ struct mftMchMatcher {
593594
594595 return result;
595596 }
597+ template <class EVT , class BC , class TMUON , class TMFTS >
598+ int getMftMchMatchAttempts (EVT const & collisions,
599+ BC const & bcs,
600+ TMUON const & mchTrack,
601+ TMFTS const & mftTracks)
602+ {
603+ if (!mchTrack.has_collision ()) {
604+ return 0 ;
605+ }
606+ const auto & collMch = collisions.rawIteratorAt (mchTrack.collisionId ());
607+ const auto & bcMch = bcs.rawIteratorAt (collMch.bcId ());
608+
609+ int attempts{0 };
610+ for (const auto & mftTrack : mftTracks) {
611+ if (!mftTrack.has_collision ()) {
612+ continue ;
613+ }
614+
615+ const auto & collMft = collisions.rawIteratorAt (mftTrack.collisionId ());
616+ const auto & bcMft = bcs.rawIteratorAt (collMft.bcId ());
617+
618+ int64_t deltaBc = static_cast <int64_t >(bcMft.globalBC ()) - static_cast <int64_t >(bcMch.globalBC ());
619+ double deltaBcNS = o2::constants::lhc::LHCBunchSpacingNS * deltaBc;
620+ double deltaTrackTime = mftTrack.trackTime () - mchTrack.trackTime () + deltaBcNS;
621+ double trackTimeResTot = mftTrack.trackTimeRes () + mchTrack.trackTimeRes ();
622+
623+ if (std::fabs (deltaTrackTime) > trackTimeResTot) {
624+ continue ;
625+ }
626+ attempts += 1 ;
627+ }
628+
629+ return attempts;
630+ }
596631
597632 template <bool isMc, class TCOLLS , class TBCS , class TMUONS , class TMFTS , class TCOVS >
598633 void fillTable (TCOLLS const & collisions,
599- TBCS const & /* bcs*/ ,
634+ TBCS const & bcs,
600635 TMUONS const & muonTracks,
601636 TMFTS const & mftTracks,
602637 TCOVS const & mftCovs)
603638 {
639+ std::unordered_map<int64_t , int > matchAttemptsMap;
640+
604641 registry.get <TH1 >(HIST (" acceptedEvents" ))->Fill (0 );
605642 // reject a randomly selected fraction of events
606643 if (fSamplingFraction < 1.0 ) {
@@ -670,6 +707,14 @@ struct mftMchMatcher {
670707
671708 bool IsAmbig = (muon.compatibleCollIds ().size () != 1 );
672709 int MFTMult = collision.mftNtracks ();
710+ int matchAttempts = 0 ;
711+ auto matchAttemptsIt = matchAttemptsMap.find (muontrack.globalIndex ());
712+ if (matchAttemptsIt == matchAttemptsMap.end ()) {
713+ matchAttempts = getMftMchMatchAttempts (collisions, bcs, muontrack, mftTracks);
714+ matchAttemptsMap.insert (std::make_pair (static_cast <int64_t >(muontrack.globalIndex ()), matchAttempts));
715+ } else {
716+ matchAttempts = matchAttemptsIt->second ;
717+ }
673718
674719 auto matchType = kMatchTypeUndefined ;
675720 if constexpr (isMc) {
@@ -789,6 +834,7 @@ struct mftMchMatcher {
789834 muon.fwdDcaY (),
790835 IsAmbig,
791836 MFTMult,
837+ matchAttempts,
792838 mcMaskMuon,
793839 mcMaskMft,
794840 ncMaskGlob,
0 commit comments