Skip to content

Commit e7f1c5c

Browse files
committed
fixing performance issues
1 parent a2ddb40 commit e7f1c5c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

PWGUD/TableProducer/upcCandProducerGlobalMuon.cxx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ struct UpcCandProducerGlobalMuon {
113113
static constexpr double fCcenterMFT[3] = {0, 0, -61.4}; // Field evaluation point at center of MFT
114114
float fZShift{0}; // z-vertex shift for forward track propagation
115115

116+
// Named constants (avoid magic numbers in expressions)
117+
static constexpr double kInvalidDCA = 999.; // Sentinel for "no valid DCA computed yet"
118+
static constexpr double kBcTimeRoundingOffset = 1.; // Offset used when rounding trackTime to BC units
119+
static constexpr uint16_t kMinTracksForPair = 2; // Minimum tracks required to compute a pair invariant mass
120+
static constexpr uint16_t kMinTracksForCandidate = 1; // Minimum contributors required to save a candidate
121+
116122
void init(InitContext&)
117123
{
118124
fUpcCuts = (UPCCutparHolder)fUpcCutsConf;
@@ -472,11 +478,11 @@ struct UpcCandProducerGlobalMuon {
472478
}
473479

474480
int newId = 0;
475-
for (auto trackId : trackIds) {
481+
for (const auto& trackId : trackIds) {
476482
auto it = clustersPerTrack.find(trackId);
477483
if (it != clustersPerTrack.end()) {
478484
const auto& clusters = it->second;
479-
for (auto clsId : clusters) {
485+
for (const auto& clsId : clusters) {
480486
const auto& clsInfo = fwdTrkCls.iteratorAt(clsId);
481487
udFwdTrkClusters(newId, clsInfo.x(), clsInfo.y(), clsInfo.z(), clsInfo.clInfo());
482488
}
@@ -623,7 +629,7 @@ struct UpcCandProducerGlobalMuon {
623629

624630
auto trackId = fwdTrack.globalIndex();
625631
int64_t indexBC = vAmbFwdTrackIndex[trackId] < 0 ? vColIndexBCs[fwdTrack.collisionId()] : vAmbFwdTrackIndexBCs[vAmbFwdTrackIndex[trackId]];
626-
auto globalBC = vGlobalBCs[indexBC] + TMath::FloorNint(fwdTrack.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + 1.);
632+
auto globalBC = vGlobalBCs[indexBC] + TMath::FloorNint(fwdTrack.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + kBcTimeRoundingOffset);
627633

628634
if (trackType == MuonStandaloneTrack) { // MCH-MID
629635
mapGlobalBcsWithMCHMIDTrackIds[globalBC].push_back(trackId);
@@ -686,7 +692,7 @@ struct UpcCandProducerGlobalMuon {
686692

687693
// Step 1: Find best collision vertex using DCA-based propagation
688694
float bestVtxX = 0., bestVtxY = 0., bestVtxZ = 0.;
689-
double bestAvgDCA = 999.;
695+
double bestAvgDCA = kInvalidDCA;
690696
bool hasVertex = false;
691697
int nCompatColls = 0;
692698

@@ -695,7 +701,7 @@ struct UpcCandProducerGlobalMuon {
695701
auto itCol = mapGlobalBCtoCollisions.find(searchBC);
696702
if (itCol == mapGlobalBCtoCollisions.end())
697703
continue;
698-
for (auto colIdx : itCol->second) {
704+
for (const auto& colIdx : itCol->second) {
699705
nCompatColls++;
700706
const auto& col = collisions.iteratorAt(colIdx);
701707
double sumDCAxy = 0.;
@@ -706,7 +712,7 @@ struct UpcCandProducerGlobalMuon {
706712
sumDCAxy += dca[0];
707713
nTracks++;
708714
}
709-
double avgDCA = nTracks > 0 ? sumDCAxy / nTracks : 999.;
715+
double avgDCA = nTracks > 0 ? sumDCAxy / nTracks : kInvalidDCA;
710716
if (!hasVertex || avgDCA < bestAvgDCA) {
711717
bestAvgDCA = avgDCA;
712718
bestVtxX = col.posX();
@@ -746,7 +752,7 @@ struct UpcCandProducerGlobalMuon {
746752

747753
// Fill invariant mass from MCH-MID-MFT anchors only
748754
uint16_t numContribAnch = numContrib;
749-
if (numContribAnch >= 2) {
755+
if (numContribAnch >= kMinTracksForPair) {
750756
double mass2 = sumE * sumE - sumPx * sumPx - sumPy * sumPy - sumPz * sumPz;
751757
histRegistry.fill(HIST("hMassGlobalMuon"), mass2 > 0. ? std::sqrt(mass2) : 0.);
752758
}
@@ -774,12 +780,12 @@ struct UpcCandProducerGlobalMuon {
774780
}
775781

776782
// Fill invariant mass including MCH-MFT tracks (only if MCH-MFT tracks were added)
777-
if (numContrib > numContribAnch && numContrib >= 2) {
783+
if (numContrib > numContribAnch && numContrib >= kMinTracksForPair) {
778784
double mass2 = sumE * sumE - sumPx * sumPx - sumPy * sumPy - sumPz * sumPz;
779785
histRegistry.fill(HIST("hMassGlobalMuonWithMCHMFT"), mass2 > 0. ? std::sqrt(mass2) : 0.);
780786
}
781787

782-
if (numContrib < 1)
788+
if (numContrib < kMinTracksForCandidate)
783789
continue;
784790

785791
eventCandidates(globalBcAnchor, runNumber, bestVtxX, bestVtxY, bestVtxZ, 0, numContrib, 0, 0);
@@ -828,7 +834,7 @@ struct UpcCandProducerGlobalMuon {
828834
numContrib++;
829835
selTrackIds.push_back(imuon);
830836
}
831-
if (numContrib < 1) // didn't save any MCH-MID tracks
837+
if (numContrib < kMinTracksForCandidate) // didn't save any MCH-MID tracks
832838
continue;
833839
std::map<int64_t, uint64_t> mapMchIdBc{};
834840
getMchTrackIds(globalBcMid, mapGlobalBcsWithMCHTrackIds, fBcWindowMCH, mapMchIdBc);

0 commit comments

Comments
 (0)