@@ -603,17 +603,25 @@ struct UpcCandProducer {
603603 // "uncorrected" bcs
604604 template <int32_t tracksSwitch, typename TBCs, typename TAmbTracks>
605605 void collectAmbTrackBCs (std::unordered_map<int64_t , uint64_t >& ambTrIds,
606+ TBCs const & bcs,
606607 TAmbTracks ambTracks)
607608 {
608609 for (const auto & ambTrk : ambTracks) {
609610 auto trkId = getAmbTrackId<tracksSwitch>(ambTrk);
610- const auto & bcSlice = ambTrk.template bc_as <TBCs>();
611- uint64_t trackBC = -1 ;
612- if (bcSlice.size () != 0 ) {
613- auto first = bcSlice.begin ();
614- trackBC = first.globalBC ();
611+
612+ const auto & bcIds = ambTrk.bcIds ();
613+ if (bcIds.size () == 0 )
614+ continue ;
615+
616+ const auto firstBcId = static_cast <int64_t >(*bcIds.begin ());
617+ if (firstBcId < 0 || firstBcId >= static_cast <int64_t >(bcs.size ())) {
618+ LOGP (debug,
619+ " Skipping ambiguous track {}: invalid first bcId {} (nBCs = {})" ,
620+ trkId, firstBcId, bcs.size ());
621+ continue ;
615622 }
616- ambTrIds[trkId] = trackBC;
623+
624+ ambTrIds[trkId] = bcs.iteratorAt (firstBcId).globalBC ();
617625 }
618626 }
619627
@@ -649,16 +657,22 @@ struct UpcCandProducer {
649657 continue ;
650658 int64_t trkId = trk.globalIndex ();
651659 int32_t nContrib = -1 ;
660+ bool hasTrackBC = false ;
652661 uint64_t trackBC = 0 ;
653662 if (trk.has_collision ()) {
654663 const auto & col = trk.collision ();
655664 nContrib = col.numContrib ();
656665 trackBC = col.bc_as <TBCs>().globalBC ();
666+ hasTrackBC = true ;
657667 } else {
658668 auto ambIter = ambBarrelTrBCs.find (trkId);
659- if (ambIter != ambBarrelTrBCs.end ())
669+ if (ambIter != ambBarrelTrBCs.end ()) {
660670 trackBC = ambIter->second ;
671+ hasTrackBC = true ;
672+ }
661673 }
674+ if (!hasTrackBC)
675+ continue ;
662676 int64_t tint = TMath::FloorNint (trk.trackTime () / o2::constants::lhc::LHCBunchSpacingNS + static_cast <float >(fBarrelTrackTShift ));
663677 uint64_t bc = trackBC + tint;
664678 if (nContrib > upcCuts.getMaxNContrib ())
@@ -683,15 +697,22 @@ struct UpcCandProducer {
683697 continue ;
684698 int64_t trkId = trk.globalIndex ();
685699 int32_t nContrib = -1 ;
700+ bool hasTrackBC = false ;
686701 uint64_t trackBC = 0 ;
687702 auto ambIter = ambFwdTrBCs.find (trkId);
688703 if (ambIter == ambFwdTrBCs.end ()) {
704+ if (!trk.has_collision ())
705+ continue ;
689706 const auto & col = trk.collision ();
690707 nContrib = col.numContrib ();
691708 trackBC = col.bc_as <TBCs>().globalBC ();
709+ hasTrackBC = true ;
692710 } else {
693711 trackBC = ambIter->second ;
712+ hasTrackBC = true ;
694713 }
714+ if (!hasTrackBC)
715+ continue ;
695716 int64_t tint = TMath::FloorNint (trk.trackTime () / o2::constants::lhc::LHCBunchSpacingNS + static_cast <float >(fMuonTrackTShift ));
696717 uint64_t bc = trackBC + tint;
697718 if (nContrib > upcCuts.getMaxNContrib ())
@@ -716,9 +737,12 @@ struct UpcCandProducer {
716737 continue ;
717738 int64_t trkId = trk.globalIndex ();
718739 int32_t nContrib = -1 ;
740+ bool hasTrackBC = false ;
719741 uint64_t trackBC = 0 ;
720742 auto ambIter = ambFwdTrBCs.find (trkId);
721743 if (ambIter == ambFwdTrBCs.end ()) {
744+ if (!trk.has_collision ())
745+ continue ;
722746 const auto & col = trk.collision ();
723747 nContrib = col.numContrib ();
724748 trackBC = col.bc_as <TBCs>().globalBC ();
@@ -729,9 +753,13 @@ struct UpcCandProducer {
729753 if (fRequireNoITSROFrameBorder && !bc.selection_bit (o2::aod::evsel::kNoITSROFrameBorder )) {
730754 continue ; // skip this track if the kNoITSROFrameBorder bit is required but not set
731755 }
756+ hasTrackBC = true ;
732757 } else {
733758 trackBC = ambIter->second ;
759+ hasTrackBC = true ;
734760 }
761+ if (!hasTrackBC)
762+ continue ;
735763 int64_t tint = TMath::FloorNint (trk.trackTime () / o2::constants::lhc::LHCBunchSpacingNS + static_cast <float >(fMuonTrackTShift ));
736764 uint64_t bc = trackBC + tint;
737765 if (nContrib > upcCuts.getMaxNContrib ())
@@ -800,7 +828,7 @@ struct UpcCandProducer {
800828 // trackID -> index in amb. track table
801829 std::unordered_map<int64_t , uint64_t > ambBarrelTrBCs;
802830 if (upcCuts.getAmbigSwitch () != 1 )
803- collectAmbTrackBCs<0 , BCsWithBcSels>(ambBarrelTrBCs, ambBarrelTracks);
831+ collectAmbTrackBCs<0 , BCsWithBcSels>(ambBarrelTrBCs, bcs, ambBarrelTracks);
804832
805833 collectBarrelTracks (bcsMatchedTrIdsTOF,
806834 0 ,
@@ -1101,10 +1129,10 @@ struct UpcCandProducer {
11011129
11021130 // trackID -> index in amb. track table
11031131 std::unordered_map<int64_t , uint64_t > ambBarrelTrBCs;
1104- collectAmbTrackBCs<0 , BCsWithBcSels>(ambBarrelTrBCs, ambBarrelTracks);
1132+ collectAmbTrackBCs<0 , BCsWithBcSels>(ambBarrelTrBCs, bcs, ambBarrelTracks);
11051133
11061134 std::unordered_map<int64_t , uint64_t > ambFwdTrBCs;
1107- collectAmbTrackBCs<1 , BCsWithBcSels>(ambFwdTrBCs, ambFwdTracks);
1135+ collectAmbTrackBCs<1 , BCsWithBcSels>(ambFwdTrBCs, bcs, ambFwdTracks);
11081136
11091137 collectForwardTracks (bcsMatchedTrIdsMID,
11101138 o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack,
@@ -1301,7 +1329,7 @@ struct UpcCandProducer {
13011329
13021330 // trackID -> index in amb. track table
13031331 std::unordered_map<int64_t , uint64_t > ambFwdTrBCs;
1304- collectAmbTrackBCs<1 , BCsWithBcSels>(ambFwdTrBCs, ambFwdTracks);
1332+ collectAmbTrackBCs<1 , BCsWithBcSels>(ambFwdTrBCs, bcs, ambFwdTracks);
13051333
13061334 collectForwardTracks (bcsMatchedTrIdsMID,
13071335 o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack,
@@ -1556,7 +1584,7 @@ struct UpcCandProducer {
15561584
15571585 // trackID -> index in amb. track table
15581586 std::unordered_map<int64_t , uint64_t > ambFwdTrBCs;
1559- collectAmbTrackBCs<1 , BCsWithBcSels>(ambFwdTrBCs, ambFwdTracks);
1587+ collectAmbTrackBCs<1 , BCsWithBcSels>(ambFwdTrBCs, bcs, ambFwdTracks);
15601588
15611589 collectForwardTracks (bcsMatchedTrIdsMID,
15621590 o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack,
0 commit comments