From 5c8225ab1541db0aa94ea358142c3f81ad926ac6 Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Sat, 11 Oct 2025 12:26:24 +0200 Subject: [PATCH 1/2] [PWGLF] Reduce MC memory usage: reuse vectors per event and shrink every 1000 events --- PWGLF/Tasks/Nuspex/antinucleiInJets.cxx | 48 +++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx index 4c26eb5e2d8..c64d14d02f2 100644 --- a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx +++ b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx @@ -1616,9 +1616,23 @@ struct AntinucleiInJets { // Generated events void processJetsMCgen(GenCollisionsMc const& collisions, aod::McParticles const& mcParticles) { + // Define per-event particle containers + std::vector fjParticles; + std::vector protonMomentum; + + // Event counter + int eventCounter = 0; + // Loop over all simulated collisions for (const auto& collision : collisions) { + // Increment event counter + eventCounter++; + + // Clear containers at the start of the event loop + fjParticles.clear(); + protonMomentum.clear(); + // Event counter: before event selection registryMC.fill(HIST("genEvents"), 0.5); @@ -1629,9 +1643,7 @@ struct AntinucleiInJets { // Event counter: after event selection registryMC.fill(HIST("genEvents"), 1.5); - // Loop over all MC particles - std::vector fjParticles; - std::vector protonMomentum; + // Loop over MC particles for (const auto& particle : mcParticles) { // Select physical primaries within acceptance @@ -1644,7 +1656,7 @@ struct AntinucleiInJets { // Store 3-momentum vectors of antiprotons for further analysis if (particle.pdgCode() == PDG_t::kProtonBar) { TVector3 pVec(particle.px(), particle.py(), particle.pz()); - protonMomentum.push_back(pVec); + protonMomentum.emplace_back(pVec); } // 4-momentum representation of a particle @@ -1754,6 +1766,12 @@ struct AntinucleiInJets { if (isAtLeastOneJetSelected) { registryMC.fill(HIST("genEvents"), 3.5); } + + // Shrink large vectors every 1000 events + if (eventCounter % 1000 == 0) { + fjParticles.shrink_to_fit(); + protonMomentum.shrink_to_fit(); + } } } PROCESS_SWITCH(AntinucleiInJets, processJetsMCgen, "process jets mc gen", false); @@ -1761,9 +1779,23 @@ struct AntinucleiInJets { // Reconstructed events void processJetsMCrec(RecCollisionsMc const& collisions, AntiNucleiTracksMc const& mcTracks, McParticles const&) { + // Define per-event containers + std::vector fjParticles; + std::vector antiprotonTrackIndex; + + // Event counter + int eventCounter = 0; + // Loop over all reconstructed collisions for (const auto& collision : collisions) { + // Increment event counter + eventCounter++; + + // Clear containers at the start of the event loop + fjParticles.clear(); + antiprotonTrackIndex.clear(); + // Event counter: before event selection registryMC.fill(HIST("recEvents"), 0.5); @@ -1806,8 +1838,6 @@ struct AntinucleiInJets { // Loop over reconstructed tracks int id(-1); - std::vector fjParticles; - std::vector antiprotonTrackIndex; for (auto const& track : mcTracks) { id++; @@ -2028,6 +2058,12 @@ struct AntinucleiInJets { if (isAtLeastOneJetSelected) { registryMC.fill(HIST("recEvents"), 9.5); } + + // Shrink large vectors every 1000 events + if (eventCounter % 1000 == 0) { + fjParticles.shrink_to_fit(); + antiprotonTrackIndex.shrink_to_fit(); + } } } PROCESS_SWITCH(AntinucleiInJets, processJetsMCrec, "process jets MC rec", false); From 4319ef999a60f4bbff6b1370d54c22825ed3954e Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Sat, 11 Oct 2025 12:32:02 +0200 Subject: [PATCH 2/2] removed magic number --- PWGLF/Tasks/Nuspex/antinucleiInJets.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx index c64d14d02f2..29473a44283 100644 --- a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx +++ b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx @@ -151,6 +151,9 @@ struct AntinucleiInJets { Configurable weightsXi{"weightsXi", "", "weightsXi"}; Configurable weightsOmega{"weightsOmega", "", "weightsOmega"}; + // Number of events + Configurable shrinkInterval{"shrinkInterval", 1000, "variable that controls how often shrinking happens"}; + // Reweighting histograms TH1F* primaryAntiprotons; TH1F* primaryAntiLambda; @@ -1767,8 +1770,8 @@ struct AntinucleiInJets { registryMC.fill(HIST("genEvents"), 3.5); } - // Shrink large vectors every 1000 events - if (eventCounter % 1000 == 0) { + // Shrink large vectors + if (eventCounter % shrinkInterval == 0) { fjParticles.shrink_to_fit(); protonMomentum.shrink_to_fit(); } @@ -2059,8 +2062,8 @@ struct AntinucleiInJets { registryMC.fill(HIST("recEvents"), 9.5); } - // Shrink large vectors every 1000 events - if (eventCounter % 1000 == 0) { + // Shrink large vectors + if (eventCounter % shrinkInterval == 0) { fjParticles.shrink_to_fit(); antiprotonTrackIndex.shrink_to_fit(); }