From 6f6f63420f937d01af84f260d8577fb49fd76e05 Mon Sep 17 00:00:00 2001 From: Michal Bluj Date: Wed, 28 Feb 2024 13:31:15 +0100 Subject: [PATCH] Reduced complexity of erasing vector elements in PATTauHybridProducer Erase elements of candidate vectors with remove_if instead of looping over the vectors to reduce complexity --- .../PatAlgos/plugins/PATTauHybridProducer.cc | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATTauHybridProducer.cc b/PhysicsTools/PatAlgos/plugins/PATTauHybridProducer.cc index 7e949e3dbe0aa..e3172d01e870d 100644 --- a/PhysicsTools/PatAlgos/plugins/PATTauHybridProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATTauHybridProducer.cc @@ -366,13 +366,10 @@ void PATTauHybridProducer::fillTauFromJet(reco::PFTau& pfTau, const reco::JetBas } } // Clean isolation candidates from low-pt and leptonic ones - for (CandPtrs::iterator it = pfChs.begin(); it != pfChs.end();) { - if ((*it)->pt() < 0.5 || std::abs((*it)->pdgId()) != 211) { - it = pfChs.erase(it); - } else { - ++it; - } - } + pfChs.erase(std::remove_if(pfChs.begin(), + pfChs.end(), + [](auto const& cand) { return cand->pt() < 0.5 || std::abs(cand->pdgId()) != 211; }), + pfChs.end()); // Set charged candidates pfTau.setsignalChargedHadrCands(pfChsSig); pfTau.setisolationChargedHadrCands(pfChs); @@ -388,13 +385,8 @@ void PATTauHybridProducer::fillTauFromJet(reco::PFTau& pfTau, const reco::JetBas pfGammas.erase(pfGammas.begin()); } // Clean gamma candidates from low-pt ones - for (CandPtrs::iterator it = pfGammas.begin(); it != pfGammas.end();) { - if ((*it)->pt() < 0.5) { - it = pfGammas.erase(it); - } else { - ++it; - } - } + pfGammas.erase(std::remove_if(pfGammas.begin(), pfGammas.end(), [](auto const& cand) { return cand->pt() < 0.5; }), + pfGammas.end()); // if decay mode with pi0s is expected look for signal gamma candidates // within eta-phi strips around leading track if (pfTau.decayMode() % 5 != 0 && pfTau.leadChargedHadrCand().isNonnull()) {