Skip to content

Commit 7409d38

Browse files
arifferoalibuild
andauthored
[PWGUD] Fix ambiguous-track BC handling in UPCCandProducer (#15463)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent 9dc271a commit 7409d38

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

PWGUD/TableProducer/UPCCandidateProducer.cxx

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/// \author Nazar Burmasov, nazar.burmasov@cern.ch
1212
/// \author Diana Krupova, diana.krupova@cern.ch
1313
/// \since 04.06.2024
14+
/// \author Andrea Riffero, andrea.giovanni.riffero@cern.ch
15+
/// \since 19.03.2026
1416

1517
#include "PWGUD/Core/UPCCutparHolder.h"
1618
#include "PWGUD/Core/UPCHelpers.h"
@@ -622,17 +624,25 @@ struct UpcCandProducer {
622624
// "uncorrected" bcs
623625
template <int32_t tracksSwitch, typename TBCs, typename TAmbTracks>
624626
void collectAmbTrackBCs(std::unordered_map<int64_t, uint64_t>& ambTrIds,
627+
TBCs const& bcs,
625628
TAmbTracks ambTracks)
626629
{
627630
for (const auto& ambTrk : ambTracks) {
628631
auto trkId = getAmbTrackId<tracksSwitch>(ambTrk);
629-
const auto& bcSlice = ambTrk.template bc_as<TBCs>();
630-
uint64_t trackBC = -1;
631-
if (bcSlice.size() != 0) {
632-
auto first = bcSlice.begin();
633-
trackBC = first.globalBC();
632+
633+
const auto& bcIds = ambTrk.bcIds();
634+
if (bcIds.size() == 0)
635+
continue;
636+
637+
const auto firstBcId = static_cast<int64_t>(*bcIds.begin());
638+
if (firstBcId < 0 || firstBcId >= static_cast<int64_t>(bcs.size())) {
639+
LOGP(debug,
640+
"Skipping ambiguous track {}: invalid first bcId {} (nBCs = {})",
641+
trkId, firstBcId, bcs.size());
642+
continue;
634643
}
635-
ambTrIds[trkId] = trackBC;
644+
645+
ambTrIds[trkId] = bcs.iteratorAt(firstBcId).globalBC();
636646
}
637647
}
638648

@@ -668,16 +678,22 @@ struct UpcCandProducer {
668678
continue;
669679
int64_t trkId = trk.globalIndex();
670680
int32_t nContrib = -1;
681+
bool hasTrackBC = false;
671682
uint64_t trackBC = 0;
672683
if (trk.has_collision()) {
673684
const auto& col = trk.collision();
674685
nContrib = col.numContrib();
675686
trackBC = col.bc_as<TBCs>().globalBC();
687+
hasTrackBC = true;
676688
} else {
677689
auto ambIter = ambBarrelTrBCs.find(trkId);
678-
if (ambIter != ambBarrelTrBCs.end())
690+
if (ambIter != ambBarrelTrBCs.end()) {
679691
trackBC = ambIter->second;
692+
hasTrackBC = true;
693+
}
680694
}
695+
if (!hasTrackBC)
696+
continue;
681697
int64_t tint = TMath::FloorNint(trk.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + static_cast<float>(fBarrelTrackTShift));
682698
uint64_t bc = trackBC + tint;
683699
if (nContrib > upcCuts.getMaxNContrib())
@@ -702,15 +718,22 @@ struct UpcCandProducer {
702718
continue;
703719
int64_t trkId = trk.globalIndex();
704720
int32_t nContrib = -1;
721+
bool hasTrackBC = false;
705722
uint64_t trackBC = 0;
706723
auto ambIter = ambFwdTrBCs.find(trkId);
707724
if (ambIter == ambFwdTrBCs.end()) {
725+
if (!trk.has_collision())
726+
continue;
708727
const auto& col = trk.collision();
709728
nContrib = col.numContrib();
710729
trackBC = col.bc_as<TBCs>().globalBC();
730+
hasTrackBC = true;
711731
} else {
712732
trackBC = ambIter->second;
733+
hasTrackBC = true;
713734
}
735+
if (!hasTrackBC)
736+
continue;
714737
int64_t tint = TMath::FloorNint(trk.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + static_cast<float>(fMuonTrackTShift));
715738
uint64_t bc = trackBC + tint;
716739
if (nContrib > upcCuts.getMaxNContrib())
@@ -735,9 +758,12 @@ struct UpcCandProducer {
735758
continue;
736759
int64_t trkId = trk.globalIndex();
737760
int32_t nContrib = -1;
761+
bool hasTrackBC = false;
738762
uint64_t trackBC = 0;
739763
auto ambIter = ambFwdTrBCs.find(trkId);
740764
if (ambIter == ambFwdTrBCs.end()) {
765+
if (!trk.has_collision())
766+
continue;
741767
const auto& col = trk.collision();
742768
nContrib = col.numContrib();
743769
trackBC = col.bc_as<TBCs>().globalBC();
@@ -748,9 +774,13 @@ struct UpcCandProducer {
748774
if (fRequireNoITSROFrameBorder && !bc.selection_bit(o2::aod::evsel::kNoITSROFrameBorder)) {
749775
continue; // skip this track if the kNoITSROFrameBorder bit is required but not set
750776
}
777+
hasTrackBC = true;
751778
} else {
752779
trackBC = ambIter->second;
780+
hasTrackBC = true;
753781
}
782+
if (!hasTrackBC)
783+
continue;
754784
int64_t tint = TMath::FloorNint(trk.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + static_cast<float>(fMuonTrackTShift));
755785
uint64_t bc = trackBC + tint;
756786
if (nContrib > upcCuts.getMaxNContrib())
@@ -819,7 +849,7 @@ struct UpcCandProducer {
819849
// trackID -> index in amb. track table
820850
std::unordered_map<int64_t, uint64_t> ambBarrelTrBCs;
821851
if (upcCuts.getAmbigSwitch() != 1)
822-
collectAmbTrackBCs<0, BCsWithBcSels>(ambBarrelTrBCs, ambBarrelTracks);
852+
collectAmbTrackBCs<0, BCsWithBcSels>(ambBarrelTrBCs, bcs, ambBarrelTracks);
823853

824854
collectBarrelTracks(bcsMatchedTrIdsTOF,
825855
0,
@@ -1120,10 +1150,10 @@ struct UpcCandProducer {
11201150

11211151
// trackID -> index in amb. track table
11221152
std::unordered_map<int64_t, uint64_t> ambBarrelTrBCs;
1123-
collectAmbTrackBCs<0, BCsWithBcSels>(ambBarrelTrBCs, ambBarrelTracks);
1153+
collectAmbTrackBCs<0, BCsWithBcSels>(ambBarrelTrBCs, bcs, ambBarrelTracks);
11241154

11251155
std::unordered_map<int64_t, uint64_t> ambFwdTrBCs;
1126-
collectAmbTrackBCs<1, BCsWithBcSels>(ambFwdTrBCs, ambFwdTracks);
1156+
collectAmbTrackBCs<1, BCsWithBcSels>(ambFwdTrBCs, bcs, ambFwdTracks);
11271157

11281158
collectForwardTracks(bcsMatchedTrIdsMID,
11291159
o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack,
@@ -1320,7 +1350,7 @@ struct UpcCandProducer {
13201350

13211351
// trackID -> index in amb. track table
13221352
std::unordered_map<int64_t, uint64_t> ambFwdTrBCs;
1323-
collectAmbTrackBCs<1, BCsWithBcSels>(ambFwdTrBCs, ambFwdTracks);
1353+
collectAmbTrackBCs<1, BCsWithBcSels>(ambFwdTrBCs, bcs, ambFwdTracks);
13241354

13251355
collectForwardTracks(bcsMatchedTrIdsMID,
13261356
o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack,
@@ -1575,7 +1605,7 @@ struct UpcCandProducer {
15751605

15761606
// trackID -> index in amb. track table
15771607
std::unordered_map<int64_t, uint64_t> ambFwdTrBCs;
1578-
collectAmbTrackBCs<1, BCsWithBcSels>(ambFwdTrBCs, ambFwdTracks);
1608+
collectAmbTrackBCs<1, BCsWithBcSels>(ambFwdTrBCs, bcs, ambFwdTracks);
15791609

15801610
collectForwardTracks(bcsMatchedTrIdsMID,
15811611
o2::aod::fwdtrack::ForwardTrackTypeEnum::MuonStandaloneTrack,

0 commit comments

Comments
 (0)