From b3ffb19185dba7b3016505f6367136b983d83743 Mon Sep 17 00:00:00 2001 From: Alberto Caliva Date: Tue, 14 Oct 2025 18:00:11 +0200 Subject: [PATCH] [PWGLF]Optimize memory usage: move jet/area definitions outside event loop and use swap() to release vectors --- PWGLF/Tasks/Nuspex/antinucleiInJets.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx index 29473a44283..f964137285b 100644 --- a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx +++ b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx @@ -1626,6 +1626,10 @@ struct AntinucleiInJets { // Event counter int eventCounter = 0; + // Jet and area definitions + fastjet::JetDefinition jetDef(fastjet::antikt_algorithm, rJet); + fastjet::AreaDefinition areaDef(fastjet::active_area, fastjet::GhostedAreaSpec(1.0)); + // Loop over all simulated collisions for (const auto& collision : collisions) { @@ -1675,8 +1679,6 @@ struct AntinucleiInJets { registryMC.fill(HIST("genEvents"), 2.5); // Cluster MC particles into jets using anti-kt algorithm - fastjet::JetDefinition jetDef(fastjet::antikt_algorithm, rJet); - fastjet::AreaDefinition areaDef(fastjet::active_area, fastjet::GhostedAreaSpec(1.0)); fastjet::ClusterSequenceArea cs(fjParticles, jetDef, areaDef); std::vector jets = fastjet::sorted_by_pt(cs.inclusive_jets()); auto [rhoPerp, rhoMPerp] = backgroundSub.estimateRhoPerpCone(fjParticles, jets); @@ -1772,8 +1774,8 @@ struct AntinucleiInJets { // Shrink large vectors if (eventCounter % shrinkInterval == 0) { - fjParticles.shrink_to_fit(); - protonMomentum.shrink_to_fit(); + std::vector().swap(fjParticles); + std::vector().swap(protonMomentum); } } } @@ -1786,6 +1788,10 @@ struct AntinucleiInJets { std::vector fjParticles; std::vector antiprotonTrackIndex; + // Jet and area definitions + fastjet::JetDefinition jetDef(fastjet::antikt_algorithm, rJet); + fastjet::AreaDefinition areaDef(fastjet::active_area, fastjet::GhostedAreaSpec(1.0)); + // Event counter int eventCounter = 0; @@ -1870,8 +1876,6 @@ struct AntinucleiInJets { registryMC.fill(HIST("recEvents"), 8.5); // Cluster particles using the anti-kt algorithm - fastjet::JetDefinition jetDef(fastjet::antikt_algorithm, rJet); - fastjet::AreaDefinition areaDef(fastjet::active_area, fastjet::GhostedAreaSpec(1.0)); fastjet::ClusterSequenceArea cs(fjParticles, jetDef, areaDef); std::vector jets = fastjet::sorted_by_pt(cs.inclusive_jets()); auto [rhoPerp, rhoMPerp] = backgroundSub.estimateRhoPerpCone(fjParticles, jets); @@ -2064,8 +2068,8 @@ struct AntinucleiInJets { // Shrink large vectors if (eventCounter % shrinkInterval == 0) { - fjParticles.shrink_to_fit(); - antiprotonTrackIndex.shrink_to_fit(); + std::vector().swap(fjParticles); + std::vector().swap(antiprotonTrackIndex); } } }