@@ -289,11 +289,12 @@ void GeneratorPythia8::investigateRelatives(Pythia8::Event& event,
289289 const std::string& what,
290290 const std::string& ind)
291291{
292- // Utility to find new index, or -1 if not found
293- auto findNew = [old2New](size_t old) -> int {
294- return old2New[old];
295- };
296- int newIdx = findNew (index);
292+ // New index of this particle, or -1 if not kept. Index old2New directly:
293+ // it is event-sized, and this is a recursive function called once per
294+ // particle, so wrapping it in a by-value-capturing lambda copied the whole
295+ // vector on every call -- O(N^2) in the event multiplicity, which dominated
296+ // high-multiplicity PbPb generation.
297+ int newIdx = old2New[index];
297298 int hepmc = event[index].statusHepMC ();
298299
299300 LOG (debug) << ind
@@ -325,7 +326,7 @@ void GeneratorPythia8::investigateRelatives(Pythia8::Event& event,
325326 << relatives.size ();
326327
327328 for (auto relativeIdx : relatives) {
328- int newRelative = findNew ( relativeIdx) ;
329+ int newRelative = old2New[ relativeIdx] ;
329330 if (newRelative >= 0 ) {
330331 // If this relative is to be kept, then append to list of new
331332 // relatives.
@@ -415,10 +416,6 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
415416 old2new[i] = newId;
416417 }
417418 }
418- // Utility to find new index, or -1 if not found
419- auto findNew = [old2new](size_t old) -> int {
420- return old2new[old];
421- };
422419
423420 // First loop, investigate mothers - from the bottom
424421 auto getMothers = [](const Pythia8::Particle& particle) { return particle.motherList (); };
@@ -481,7 +478,7 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
481478 pruned.reset ();
482479
483480 for (size_t i = 1 ; i < event.size (); i++) {
484- int newIdx = findNew (i) ;
481+ int newIdx = old2new[i] ;
485482 if (newIdx < 0 ) {
486483 continue ;
487484 }
0 commit comments