@@ -1616,9 +1616,23 @@ struct AntinucleiInJets {
16161616 // Generated events
16171617 void processJetsMCgen (GenCollisionsMc const & collisions, aod::McParticles const & mcParticles)
16181618 {
1619+ // Define per-event particle containers
1620+ std::vector<fastjet::PseudoJet> fjParticles;
1621+ std::vector<TVector3> protonMomentum;
1622+
1623+ // Event counter
1624+ int eventCounter = 0 ;
1625+
16191626 // Loop over all simulated collisions
16201627 for (const auto & collision : collisions) {
16211628
1629+ // Increment event counter
1630+ eventCounter++;
1631+
1632+ // Clear containers at the start of the event loop
1633+ fjParticles.clear ();
1634+ protonMomentum.clear ();
1635+
16221636 // Event counter: before event selection
16231637 registryMC.fill (HIST (" genEvents" ), 0.5 );
16241638
@@ -1629,9 +1643,7 @@ struct AntinucleiInJets {
16291643 // Event counter: after event selection
16301644 registryMC.fill (HIST (" genEvents" ), 1.5 );
16311645
1632- // Loop over all MC particles
1633- std::vector<fastjet::PseudoJet> fjParticles;
1634- std::vector<TVector3> protonMomentum;
1646+ // Loop over MC particles
16351647 for (const auto & particle : mcParticles) {
16361648
16371649 // Select physical primaries within acceptance
@@ -1644,7 +1656,7 @@ struct AntinucleiInJets {
16441656 // Store 3-momentum vectors of antiprotons for further analysis
16451657 if (particle.pdgCode () == PDG_t::kProtonBar ) {
16461658 TVector3 pVec (particle.px (), particle.py (), particle.pz ());
1647- protonMomentum.push_back (pVec);
1659+ protonMomentum.emplace_back (pVec);
16481660 }
16491661
16501662 // 4-momentum representation of a particle
@@ -1754,16 +1766,36 @@ struct AntinucleiInJets {
17541766 if (isAtLeastOneJetSelected) {
17551767 registryMC.fill (HIST (" genEvents" ), 3.5 );
17561768 }
1769+
1770+ // Shrink large vectors every 1000 events
1771+ if (eventCounter % 1000 == 0 ) {
1772+ fjParticles.shrink_to_fit ();
1773+ protonMomentum.shrink_to_fit ();
1774+ }
17571775 }
17581776 }
17591777 PROCESS_SWITCH (AntinucleiInJets, processJetsMCgen, " process jets mc gen" , false );
17601778
17611779 // Reconstructed events
17621780 void processJetsMCrec (RecCollisionsMc const & collisions, AntiNucleiTracksMc const & mcTracks, McParticles const &)
17631781 {
1782+ // Define per-event containers
1783+ std::vector<fastjet::PseudoJet> fjParticles;
1784+ std::vector<int > antiprotonTrackIndex;
1785+
1786+ // Event counter
1787+ int eventCounter = 0 ;
1788+
17641789 // Loop over all reconstructed collisions
17651790 for (const auto & collision : collisions) {
17661791
1792+ // Increment event counter
1793+ eventCounter++;
1794+
1795+ // Clear containers at the start of the event loop
1796+ fjParticles.clear ();
1797+ antiprotonTrackIndex.clear ();
1798+
17671799 // Event counter: before event selection
17681800 registryMC.fill (HIST (" recEvents" ), 0.5 );
17691801
@@ -1806,8 +1838,6 @@ struct AntinucleiInJets {
18061838
18071839 // Loop over reconstructed tracks
18081840 int id (-1 );
1809- std::vector<fastjet::PseudoJet> fjParticles;
1810- std::vector<int > antiprotonTrackIndex;
18111841 for (auto const & track : mcTracks) {
18121842 id++;
18131843
@@ -2028,6 +2058,12 @@ struct AntinucleiInJets {
20282058 if (isAtLeastOneJetSelected) {
20292059 registryMC.fill (HIST (" recEvents" ), 9.5 );
20302060 }
2061+
2062+ // Shrink large vectors every 1000 events
2063+ if (eventCounter % 1000 == 0 ) {
2064+ fjParticles.shrink_to_fit ();
2065+ antiprotonTrackIndex.shrink_to_fit ();
2066+ }
20312067 }
20322068 }
20332069 PROCESS_SWITCH (AntinucleiInJets, processJetsMCrec, " process jets MC rec" , false );
0 commit comments