Skip to content

Commit 2406170

Browse files
sawenzelclaude
andcommitted
Read the MC kinematics one event at a time in MatchITSTPCQC
This reduces the memory of the MC mode of the ITS-TPC matching QC from the size of all kinematics of the TF to that of the largest event. - The physical-primary flag of all needed labels is now resolved event by event. - Each event is released after use, whereas before every touched event stayed cached. - The histograms are unchanged (92 compared bin by bin, same entries). Peak memory of the `o2-qc` task on one PbPb timeframe of 8 orbits (28 signal events, 75.6M MC tracks): | | before | after | |---|---:|---:| | `o2-qc` device (PSS) | 5.6 GB | 1.45 GB | | task total (PSS) | 7.1 GB | 2.9 GB | | wall time | 35 s | 41 s | Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 987de04 commit 2406170

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

‎Detectors/GLOQC/src/MatchITSTPCQC.cxx‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include <algorithm>
13+
#include <map>
14+
#include <unordered_map>
1315

1416
#include "GLOQC/MatchITSTPCQC.h"
1517
#include "ReconstructionDataFormats/TrackTPCITS.h"
@@ -563,6 +565,27 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx)
563565
}
564566
}
565567

568+
// physical-primary flag of all labelled tracks, per (source, event); the kinematics are read and released one event at a time
569+
std::map<std::pair<int, int>, std::unordered_map<int, bool>> physPrimary;
570+
auto isPhysPrimary = [&physPrimary](const o2::MCCompLabel& lbl) { return physPrimary.at({lbl.getSourceID(), lbl.getEventID()}).at(lbl.getTrackID()); };
571+
if (mUseMC) {
572+
for (auto const& labels : {mRecoCont.getTPCITSTracksMCLabels(), mRecoCont.getTPCTracksMCLabels(), mRecoCont.getITSTracksMCLabels()}) {
573+
for (auto const& lbl : labels) {
574+
if (lbl.isValid()) {
575+
physPrimary[{lbl.getSourceID(), lbl.getEventID()}][lbl.getTrackID()] = false;
576+
}
577+
}
578+
}
579+
for (auto& [sourceAndEvent, flags] : physPrimary) {
580+
const auto [source, event] = sourceAndEvent;
581+
const std::vector<o2::MCTrack>& pcontainer = mcReader.getTracks(source, event);
582+
for (auto& [trackID, flag] : flags) {
583+
flag = static_cast<size_t>(trackID) < pcontainer.size() && MCTrackNavigator::isPhysicalPrimary(pcontainer[trackID], pcontainer);
584+
}
585+
mcReader.releaseTracksForSourceAndEvent(source, event);
586+
}
587+
}
588+
566589
// numerator + eta, chi2...
567590
if (mUseMC) {
568591
for (int i = 0; i < matchType::SIZE; ++i) {
@@ -580,11 +603,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx)
580603
continue;
581604
}
582605
if (mMapLabels[matchType::TPC].find(lbl) == mMapLabels[matchType::TPC].end()) {
583-
int source = lbl.getSourceID();
584-
int event = lbl.getEventID();
585-
const std::vector<o2::MCTrack>& pcontainer = mcReader.getTracks(source, event);
586-
const o2::MCTrack& p = pcontainer[lbl.getTrackID()];
587-
if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) {
606+
if (isPhysPrimary(lbl)) {
588607
mMapLabels[matchType::TPC].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = true}});
589608
} else {
590609
mMapLabels[matchType::TPC].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = false}});
@@ -603,11 +622,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx)
603622
continue;
604623
}
605624
if (mMapLabels[matchType::ITS].find(lbl) == mMapLabels[matchType::ITS].end()) {
606-
int source = lbl.getSourceID();
607-
int event = lbl.getEventID();
608-
const std::vector<o2::MCTrack>& pcontainer = mcReader.getTracks(source, event);
609-
const o2::MCTrack& p = pcontainer[lbl.getTrackID()];
610-
if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) {
625+
if (isPhysPrimary(lbl)) {
611626
mMapLabels[matchType::ITS].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = true}});
612627
} else {
613628
mMapLabels[matchType::ITS].insert({lbl, {.mIdx = itrk, .mIsPhysicalPrimary = false}});
@@ -828,11 +843,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx)
828843
continue;
829844
}
830845
if (mMapRefLabels[matchType::TPC].find(lbl) == mMapRefLabels[matchType::TPC].end()) {
831-
int source = lbl.getSourceID();
832-
int event = lbl.getEventID();
833-
const std::vector<o2::MCTrack>& pcontainer = mcReader.getTracks(source, event);
834-
const o2::MCTrack& p = pcontainer[lbl.getTrackID()];
835-
if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) {
846+
if (isPhysPrimary(lbl)) {
836847
mMapRefLabels[matchType::TPC].insert({lbl, {itrk, true}});
837848
} else {
838849
mMapRefLabels[matchType::TPC].insert({lbl, {itrk, false}});
@@ -860,11 +871,7 @@ void MatchITSTPCQC::run(o2::framework::ProcessingContext& ctx)
860871
continue;
861872
}
862873
if (mMapRefLabels[matchType::ITS].find(lbl) == mMapRefLabels[matchType::ITS].end()) {
863-
int source = lbl.getSourceID();
864-
int event = lbl.getEventID();
865-
const std::vector<o2::MCTrack>& pcontainer = mcReader.getTracks(source, event);
866-
const o2::MCTrack& p = pcontainer[lbl.getTrackID()];
867-
if (MCTrackNavigator::isPhysicalPrimary(p, pcontainer)) {
874+
if (isPhysPrimary(lbl)) {
868875
mMapRefLabels[matchType::ITS].insert({lbl, {itrk, true}});
869876
} else {
870877
mMapRefLabels[matchType::ITS].insert({lbl, {itrk, false}});

0 commit comments

Comments
 (0)