diff --git a/PhysicsTools/HepMCCandAlgos/plugins/GenParticlePruner.cc b/PhysicsTools/HepMCCandAlgos/plugins/GenParticlePruner.cc index 6c661d9b862ee..413785e68fadb 100644 --- a/PhysicsTools/HepMCCandAlgos/plugins/GenParticlePruner.cc +++ b/PhysicsTools/HepMCCandAlgos/plugins/GenParticlePruner.cc @@ -36,8 +36,8 @@ class GenParticlePruner : public edm::EDProducer { void flagMothers(const reco::GenParticle &, int); void recursiveFlagDaughters(size_t, const reco::GenParticleCollection &, int, std::vector &); void recursiveFlagMothers(size_t, const reco::GenParticleCollection &, int, std::vector &); - void getDaughterKeys(std::vector &, const reco::GenParticleRefVector&) const; - void getMotherKeys(std::vector &, const reco::GenParticleRefVector&) const; + void getDaughterKeys(std::vector &, std::vector &, const reco::GenParticleRefVector&) const; + void getMotherKeys(std::vector &, std::vector &, const reco::GenParticleRefVector&) const; }; using namespace edm; @@ -247,16 +247,17 @@ void GenParticlePruner::produce(Event& evt, const EventSetup& es) { // parentage/descendency. In some cases, a circular referencing is encountered, // which would result in an infinite loop. The list is checked to // avoid this. - vector daIndxs; - getDaughterKeys(daIndxs, gen.daughterRefVector()); - std::sort(daIndxs.begin(),daIndxs.end()); - for(size_t i=0; i moIndxs; - getMotherKeys(moIndxs, gen.motherRefVector()); - std::sort(moIndxs.begin(),moIndxs.end()); - for(size_t i=0; i daIndxs, daNewIndxs; + getDaughterKeys(daIndxs, daNewIndxs, gen.daughterRefVector()); + std::sort(daNewIndxs.begin(),daNewIndxs.end()); + for(size_t i=0; i moIndxs, moNewIndxs; + getMotherKeys(moIndxs, moNewIndxs, gen.motherRefVector()); + std::sort(moNewIndxs.begin(),moNewIndxs.end()); + for(size_t i=0; i & daIndxs, +void GenParticlePruner::getDaughterKeys(vector & daIndxs, vector & daNewIndxs, const GenParticleRefVector& daughters) const { for(GenParticleRefVector::const_iterator j = daughters.begin(); j != daughters.end(); ++j) { GenParticleRef dau = *j; - int idx = flags_[dau.key()]; - if (find(daIndxs.begin(), daIndxs.end(), idx) != daIndxs.end()) continue; - if (idx > 0 ) { - daIndxs.push_back( idx ); - } else { - const GenParticleRefVector & daus = dau->daughterRefVector(); - if(daus.size()>0) - getDaughterKeys(daIndxs, daus); + if (find(daIndxs.begin(), daIndxs.end(), dau.key()) == daIndxs.end()) { + daIndxs.push_back( dau.key() ); + int idx = flags_[dau.key()]; + if (idx > 0 ) { + daNewIndxs.push_back( idx ); + } else { + const GenParticleRefVector & daus = dau->daughterRefVector(); + if(daus.size()>0) + getDaughterKeys(daIndxs, daNewIndxs, daus); + } } } } -void GenParticlePruner::getMotherKeys(vector & moIndxs, +void GenParticlePruner::getMotherKeys(vector & moIndxs, vector & moNewIndxs, const GenParticleRefVector& mothers) const { for(GenParticleRefVector::const_iterator j = mothers.begin(); j != mothers.end(); ++j) { GenParticleRef mom = *j; - int idx = flags_[mom.key()]; - if (find(moIndxs.begin(), moIndxs.end(), idx) != moIndxs.end()) continue; - if (idx >= 0 ) { - moIndxs.push_back( idx ); - } else { - const GenParticleRefVector & moms = mom->motherRefVector(); - if(moms.size()>0) - getMotherKeys(moIndxs, moms); + if (find(moIndxs.begin(), moIndxs.end(), mom.key()) == moIndxs.end()) { + moIndxs.push_back( mom.key() ); + int idx = flags_[mom.key()]; + if (idx >= 0 ) { + moNewIndxs.push_back( idx ); + } else { + const GenParticleRefVector & moms = mom->motherRefVector(); + if(moms.size()>0) + getMotherKeys(moIndxs, moNewIndxs, moms); + } } } }