diff --git a/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx b/PWGLF/Tasks/Nuspex/antinucleiInJets.cxx index 4c26eb5e2d8..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; @@ -1616,9 +1619,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 +1646,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 +1659,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 +1769,12 @@ struct AntinucleiInJets { if (isAtLeastOneJetSelected) { registryMC.fill(HIST("genEvents"), 3.5); } + + // Shrink large vectors + if (eventCounter % shrinkInterval == 0) { + fjParticles.shrink_to_fit(); + protonMomentum.shrink_to_fit(); + } } } PROCESS_SWITCH(AntinucleiInJets, processJetsMCgen, "process jets mc gen", false); @@ -1761,9 +1782,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 +1841,6 @@ struct AntinucleiInJets { // Loop over reconstructed tracks int id(-1); - std::vector fjParticles; - std::vector antiprotonTrackIndex; for (auto const& track : mcTracks) { id++; @@ -2028,6 +2061,12 @@ struct AntinucleiInJets { if (isAtLeastOneJetSelected) { registryMC.fill(HIST("recEvents"), 9.5); } + + // Shrink large vectors + if (eventCounter % shrinkInterval == 0) { + fjParticles.shrink_to_fit(); + antiprotonTrackIndex.shrink_to_fit(); + } } } PROCESS_SWITCH(AntinucleiInJets, processJetsMCrec, "process jets MC rec", false);