From 0496b2086ffc1f100f1fda6269ba154d5255a2f1 Mon Sep 17 00:00:00 2001 From: swenzel Date: Mon, 17 Feb 2025 17:58:57 +0100 Subject: [PATCH] Fix mother and daughter indices in generator cocktails Particles in a generated event carry indices to refer to mother and dauther particles. These indices need to be adjusted when we combine multiple events into a cocktail. --- Generators/src/GeneratorHybrid.cxx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Generators/src/GeneratorHybrid.cxx b/Generators/src/GeneratorHybrid.cxx index f968a9c4b3513..729d69527c384 100644 --- a/Generators/src/GeneratorHybrid.cxx +++ b/Generators/src/GeneratorHybrid.cxx @@ -390,6 +390,26 @@ bool GeneratorHybrid::importParticles() for (auto subIndex : subGenIndex) { LOG(info) << "Importing particles for task " << subIndex; auto subParticles = gens[subIndex]->getParticles(); + + // The particles carry mother and daughter indices, which are relative + // to the sub-generator. We need to adjust these indices to reflect that particles + // are now embedded into a cocktail. + auto offset = mParticles.size(); + for (auto& p : subParticles) { + for (int i = 0; i < 2; ++i) { + if (p.GetMother(i) != -1) { + const auto newindex = p.GetMother(i) + offset; + p.SetMother(i, newindex); + } + } + if (p.GetNDaughters() > 0) { + for (int i = 0; i < 2; ++i) { + const auto newindex = p.GetDaughter(i) + offset; + p.SetDaughter(i, newindex); + } + } + } + mParticles.insert(mParticles.end(), subParticles.begin(), subParticles.end()); // fetch the event Header information from the underlying generator gens[subIndex]->updateHeader(&mMCEventHeader);