@@ -462,10 +462,53 @@ struct TableMakerMC {
462462
463463 auto groupedMuons = tracksMuon.sliceBy (aod::fwdtrack::collisionId, collision.globalIndex ());
464464 // loop over muons
465+
466+ // first we need to get the correct indices
467+ int nDel = 0 ;
468+ int idxPrev = -1 ;
469+ std::map<int , int > newEntryNb;
470+ std::map<int , int > newMatchIndex;
471+
465472 for (auto & muon : groupedMuons) {
466473 trackFilteringTag = uint64_t (0 );
467474 trackTempFilterMap = uint8_t (0 );
468475
476+ if (!muon.has_mcParticle ()) {
477+ continue ;
478+ }
479+
480+ VarManager::FillTrack<TMuonFillMap>(muon);
481+
482+ if (muon.index () > idxPrev + 1 ) { // checks if some muons are filtered even before the skimming function
483+ nDel += muon.index () - (idxPrev + 1 );
484+ }
485+ idxPrev = muon.index ();
486+
487+ // check the cuts and filters
488+ int i = 0 ;
489+ for (auto & cut : fMuonCuts ) {
490+ if (cut.IsSelected (VarManager::fgValues)) {
491+ trackTempFilterMap |= (uint8_t (1 ) << i);
492+ if (!fConfigNoQA ) {
493+ fHistMan ->FillHistClass (Form (" Muons_%s" , cut.GetName ()), VarManager::fgValues);
494+ }
495+ ((TH1I *)fStatsList ->At (2 ))->Fill (float (i));
496+ }
497+ i++;
498+ }
499+ if (!trackTempFilterMap) { // does not pass the cuts
500+ nDel++;
501+ } else { // it passes the cuts and will be saved in the tables
502+ newEntryNb[muon.index ()] = muon.index () - nDel;
503+ }
504+ }
505+
506+ // now let's save the muons with the correct indices and matches
507+ for (auto & muon : groupedMuons) {
508+
509+ trackFilteringTag = uint64_t (0 );
510+ trackTempFilterMap = uint8_t (0 );
511+
469512 if (!muon.has_mcParticle ()) {
470513 continue ;
471514 }
@@ -523,10 +566,33 @@ struct TableMakerMC {
523566 fCounters [0 ]++;
524567 }
525568
569+ // update the matching MCH/MFT index
570+
571+ if (int (muon.trackType ()) == 0 || int (muon.trackType ()) == 2 ) { // MCH-MFT or GLB track
572+ int matchIdx = muon.matchMCHTrackId () - muon.offsets ();
573+ if (newEntryNb.count (matchIdx) > 0 ) { // if the key exists which means the match will not get deleted
574+ newMatchIndex[muon.index ()] = newEntryNb[matchIdx]; // update the match for this muon to the updated entry of the match
575+ newMatchIndex[muon.index ()] += muonBasic.lastIndex () + 1 - newEntryNb[muon.index ()]; // adding the offset of muons, muonBasic.lastIndex() start at -1
576+ if (int (muon.trackType ()) == 0 ) { // for now only do this to global tracks
577+ newMatchIndex[matchIdx] = newEntryNb[muon.index ()]; // add the updated index of this muon as a match to mch track
578+ newMatchIndex[matchIdx] += muonBasic.lastIndex () + 1 - newEntryNb[muon.index ()]; // adding the offset, muonBasic.lastIndex() start at -1
579+ }
580+ } else {
581+ newMatchIndex[muon.index ()] = -1 ;
582+ }
583+ }
584+
585+ else if (int (muon.trackType () == 4 )) { // an MCH track
586+ // in this case the matches should be filled from the other types but we need to check
587+ if (newMatchIndex.count (muon.index ()) == 0 ) {
588+ newMatchIndex[muon.index ()] = -1 ;
589+ }
590+ }
591+
526592 muonBasic (event.lastIndex (), trackFilteringTag, muon.pt (), muon.eta (), muon.phi (), muon.sign ());
527593 muonExtra (muon.nClusters (), muon.pDca (), muon.rAtAbsorberEnd (),
528594 muon.chi2 (), muon.chi2MatchMCHMID (), muon.chi2MatchMCHMFT (),
529- muon.matchScoreMCHMFT (), muon.matchMCHTrackId () , muon.mchBitMap (), muon.midBitMap (), muon.midBoards (), muon.trackType ());
595+ muon.matchScoreMCHMFT (), newMatchIndex. find ( muon.index ())-> second , muon.mchBitMap (), muon.midBitMap (), muon.midBoards (), muon.trackType ());
530596 if constexpr (static_cast <bool >(TMuonFillMap & VarManager::ObjTypes::MuonCov)) {
531597 muonCov (muon.x (), muon.y (), muon.z (), muon.phi (), muon.tgl (), muon.signed1Pt (),
532598 muon.cXX (), muon.cXY (), muon.cYY (), muon.cPhiX (), muon.cPhiY (), muon.cPhiPhi (),
0 commit comments