From 44f51920d5fd334cdb14f9262c64bb52e8987713 Mon Sep 17 00:00:00 2001 From: Florian Jonas Date: Tue, 1 Jul 2025 13:46:20 +0200 Subject: [PATCH] fixed getDaughtersInChain function --- PWGJE/Tasks/gammaJetTreeProducer.cxx | 33 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/PWGJE/Tasks/gammaJetTreeProducer.cxx b/PWGJE/Tasks/gammaJetTreeProducer.cxx index df20989b93a..b233989630c 100644 --- a/PWGJE/Tasks/gammaJetTreeProducer.cxx +++ b/PWGJE/Tasks/gammaJetTreeProducer.cxx @@ -644,26 +644,23 @@ struct GammaJetTreeProducer { /// \param particle The particle to start from /// \return Vector of daughter particle IDs template - std::vector getDaughtersInChain(const T& particle, int depth = 0) + void getDaughtersInChain(const T& particle, std::vector& daughters, int depth = 0) { - std::vector daughters; // Limit recursion depth to avoid infinite loops if (depth > kMaxRecursionDepth) { // 100 generations should be more than enough - return daughters; + return; } - T currentParticle = particle; - while (currentParticle.has_daughters()) { - const auto& daughtersIDs = currentParticle.template daughters_as(); - for (const auto& daughter : daughtersIDs) { - daughters.push_back(daughter.globalIndex()); - } - currentParticle = daughtersIDs.iteratorAt(0); - depth++; - if (depth > kMaxRecursionDepth) { - break; - } + + if (!particle.has_daughters()) { + return; + } + + const auto& daughterParticles = particle.template daughters_as(); + for (const auto& daughter : daughterParticles) { + daughters.push_back(daughter.globalIndex()); + getDaughtersInChain(daughter, daughters, depth + 1); } - return daughters; + return; } /// \brief Finds the first physical primary particle in the decay chain (upwards) /// \param particle The particle to start from @@ -728,8 +725,10 @@ struct GammaJetTreeProducer { const auto& daughter2 = daughtersMother.iteratorAt(1); if (daughter1.pdgCode() == PDG_t::kGamma && daughter2.pdgCode() == PDG_t::kGamma) { // get the full stack of particles that these daughters create - auto fullDecayChain1 = getDaughtersInChain(daughter1); - auto fullDecayChain2 = getDaughtersInChain(daughter2); + std::vector fullDecayChain1; + std::vector fullDecayChain2; + getDaughtersInChain(daughter1, fullDecayChain1); + getDaughtersInChain(daughter2, fullDecayChain2); bool photon1Found = false; bool photon2Found = false;