@@ -644,26 +644,23 @@ struct GammaJetTreeProducer {
644644 // / \param particle The particle to start from
645645 // / \return Vector of daughter particle IDs
646646 template <typename T>
647- std::vector< int > getDaughtersInChain (const T& particle, int depth = 0 )
647+ void getDaughtersInChain (const T& particle, std::vector< int >& daughters , int depth = 0 )
648648 {
649- std::vector<int > daughters;
650649 // Limit recursion depth to avoid infinite loops
651650 if (depth > kMaxRecursionDepth ) { // 100 generations should be more than enough
652- return daughters ;
651+ return ;
653652 }
654- T currentParticle = particle;
655- while (currentParticle.has_daughters ()) {
656- const auto & daughtersIDs = currentParticle.template daughters_as <aod::JMcParticles>();
657- for (const auto & daughter : daughtersIDs) {
658- daughters.push_back (daughter.globalIndex ());
659- }
660- currentParticle = daughtersIDs.iteratorAt (0 );
661- depth++;
662- if (depth > kMaxRecursionDepth ) {
663- break ;
664- }
653+
654+ if (!particle.has_daughters ()) {
655+ return ;
656+ }
657+
658+ const auto & daughterParticles = particle.template daughters_as <aod::JMcParticles>();
659+ for (const auto & daughter : daughterParticles) {
660+ daughters.push_back (daughter.globalIndex ());
661+ getDaughtersInChain (daughter, daughters, depth + 1 );
665662 }
666- return daughters ;
663+ return ;
667664 }
668665 // / \brief Finds the first physical primary particle in the decay chain (upwards)
669666 // / \param particle The particle to start from
@@ -728,8 +725,10 @@ struct GammaJetTreeProducer {
728725 const auto & daughter2 = daughtersMother.iteratorAt (1 );
729726 if (daughter1.pdgCode () == PDG_t::kGamma && daughter2.pdgCode () == PDG_t::kGamma ) {
730727 // get the full stack of particles that these daughters create
731- auto fullDecayChain1 = getDaughtersInChain (daughter1);
732- auto fullDecayChain2 = getDaughtersInChain (daughter2);
728+ std::vector<int > fullDecayChain1;
729+ std::vector<int > fullDecayChain2;
730+ getDaughtersInChain (daughter1, fullDecayChain1);
731+ getDaughtersInChain (daughter2, fullDecayChain2);
733732 bool photon1Found = false ;
734733 bool photon2Found = false ;
735734
0 commit comments