Skip to content

Commit cc226e9

Browse files
ktfsawenzel
authored andcommitted
Avoid unneeded lambda
The lambda captures the old2New vector by copy just to dereference it. Use the explicit code for doing so. This appears to be a large fraction of our MC enabled analysis trains when GeneratorPythia8 is used.
1 parent e73e5b9 commit cc226e9

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

Generators/src/GeneratorPythia8.cxx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,12 @@ void GeneratorPythia8::investigateRelatives(Pythia8::Event& event,
292292
const std::string& what,
293293
const std::string& ind)
294294
{
295-
// Utility to find new index, or -1 if not found
296-
auto findNew = [old2New](size_t old) -> int {
297-
return old2New[old];
298-
};
299-
int newIdx = findNew(index);
295+
// New index of this particle, or -1 if not kept. Index old2New directly:
296+
// it is event-sized, and this is a recursive function called once per
297+
// particle, so wrapping it in a by-value-capturing lambda copied the whole
298+
// vector on every call -- O(N^2) in the event multiplicity, which dominated
299+
// high-multiplicity PbPb generation.
300+
int newIdx = old2New[index];
300301
int hepmc = event[index].statusHepMC();
301302

302303
LOG(debug) << ind
@@ -328,7 +329,7 @@ void GeneratorPythia8::investigateRelatives(Pythia8::Event& event,
328329
<< relatives.size();
329330

330331
for (auto relativeIdx : relatives) {
331-
int newRelative = findNew(relativeIdx);
332+
int newRelative = old2New[relativeIdx];
332333
if (newRelative >= 0) {
333334
// If this relative is to be kept, then append to list of new
334335
// relatives.
@@ -418,10 +419,6 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
418419
old2new[i] = newId;
419420
}
420421
}
421-
// Utility to find new index, or -1 if not found
422-
auto findNew = [old2new](size_t old) -> int {
423-
return old2new[old];
424-
};
425422

426423
// First loop, investigate mothers - from the bottom
427424
auto getMothers = [](const Pythia8::Particle& particle) { return particle.motherList(); };
@@ -484,7 +481,7 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
484481
pruned.reset();
485482

486483
for (size_t i = 1; i < event.size(); i++) {
487-
int newIdx = findNew(i);
484+
int newIdx = old2new[i];
488485
if (newIdx < 0) {
489486
continue;
490487
}

0 commit comments

Comments
 (0)