diff --git a/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h b/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h index 6e820c87f8e31..9aecb72f0e746 100644 --- a/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h +++ b/RecoTauTag/RecoTau/interface/PFRecoTauChargedHadronPlugins.h @@ -17,12 +17,11 @@ * */ -#include -#include #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" #include "RecoTauTag/RecoTau/interface/RecoTauPluginsCommon.h" -#include "FWCore/Framework/interface/ConsumesCollector.h" +#include namespace reco { @@ -35,10 +34,8 @@ namespace reco { class PFRecoTauChargedHadronBuilderPlugin : public RecoTauEventHolderPlugin { public: // Return a vector of pointers - typedef boost::ptr_vector ChargedHadronVector; - // Storing the result in an auto ptr on function return allows - // allows us to safely release the ptr_vector in the virtual function - typedef std::unique_ptr return_type; + typedef std::vector> ChargedHadronVector; + typedef ChargedHadronVector return_type; explicit PFRecoTauChargedHadronBuilderPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC) : RecoTauEventHolderPlugin(pset) {} ~PFRecoTauChargedHadronBuilderPlugin() override {} diff --git a/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h b/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h index 150f56aca8232..ef6a66b17e5d5 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h +++ b/RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h @@ -30,8 +30,6 @@ * */ -#include - #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/EDProducer.h" #include "FWCore/Framework/interface/ConsumesCollector.h" @@ -55,15 +53,15 @@ namespace reco { /* Class that constructs PFTau(s) from a Jet and its associated PiZeros */ class RecoTauBuilderPlugin : public RecoTauEventHolderPlugin { public: - typedef boost::ptr_vector output_type; - typedef std::unique_ptr return_type; + typedef std::vector> output_type; + typedef output_type return_type; explicit RecoTauBuilderPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC) : RecoTauEventHolderPlugin(pset), // The vertex association configuration is specified with the quality cuts. vertexAssociator_(pset.getParameter("qualityCuts"), std::move(iC)) { pfCandSrc_ = pset.getParameter("pfCandSrc"); - pfCand_token = iC.consumes >(pfCandSrc_); + pfCand_token = iC.consumes>(pfCandSrc_); }; ~RecoTauBuilderPlugin() override {} @@ -77,7 +75,7 @@ namespace reco { const std::vector&) const = 0; /// Hack to be able to convert Ptrs to Refs - const edm::Handle >& getPFCands() const { return pfCands_; }; + const edm::Handle>& getPFCands() const { return pfCands_; }; /// Get primary vertex associated to this jet reco::VertexRef primaryVertex(const reco::JetBaseRef& jet) const { @@ -95,9 +93,9 @@ namespace reco { private: edm::InputTag pfCandSrc_; // Handle to PFCandidates needed to build Refs - edm::Handle > pfCands_; + edm::Handle> pfCands_; reco::tau::RecoTauVertexAssociator vertexAssociator_; - edm::EDGetTokenT > pfCand_token; + edm::EDGetTokenT> pfCand_token; }; /* Class that updates a PFTau's members (i.e. electron variables) */ diff --git a/RecoTauTag/RecoTau/interface/RecoTauCleaningTools.h b/RecoTauTag/RecoTau/interface/RecoTauCleaningTools.h index b9502807a371d..d2309f8ee0a64 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauCleaningTools.h +++ b/RecoTauTag/RecoTau/interface/RecoTauCleaningTools.h @@ -13,13 +13,11 @@ namespace reco::tau { explicit RecoTauLexicographicalRanking(const RankingList& rankers) : rankers_(rankers) {} // Predicate to compare a and b bool operator()(const Type& a, const Type& b) const { - typename RankingList::const_iterator ranker = rankers_.begin(); - while (ranker != rankers_.end()) { + for (auto const& ranker : rankers_) { double aResult = (*ranker)(a); double bResult = (*ranker)(b); if (aResult != bResult) return (aResult < bResult); - ++ranker; } // If all aare equal return false return false; @@ -31,29 +29,22 @@ namespace reco::tau { template Container cleanOverlaps(const Container& dirty) { - typedef typename Container::const_iterator Iterator; // Output container of clean objects Container clean; OverlapFunction overlapChecker; - for (Iterator candidate = dirty.begin(); candidate != dirty.end(); ++candidate) { + for (auto const& candidate : dirty) { // Check if this overlaps with a pizero already in the clean list bool overlaps = false; - for (Iterator cleaned = clean.begin(); cleaned != clean.end() && !overlaps; ++cleaned) { - overlaps = overlapChecker(*candidate, *cleaned); + for (auto cleaned = clean.begin(); cleaned != clean.end() && !overlaps; ++cleaned) { + overlaps = overlapChecker(candidate, *cleaned); } // If it didn't overlap with anything clean, add it to the clean list if (!overlaps) - clean.insert(clean.end(), *candidate); + clean.insert(clean.end(), candidate); } return clean; } - template - class SortByDescendingPt { - public: - bool operator()(const T& a, const T& b) const { return a.pt() > b.pt(); } - }; - } // namespace reco::tau #endif diff --git a/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h b/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h index ef0978f4d74bb..10a507c63277a 100644 --- a/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h +++ b/RecoTauTag/RecoTau/interface/RecoTauPiZeroPlugins.h @@ -18,7 +18,6 @@ */ #include -#include #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" #include "RecoTauTag/RecoTau/interface/RecoTauPluginsCommon.h" @@ -33,10 +32,8 @@ namespace reco { class RecoTauPiZeroBuilderPlugin : public RecoTauEventHolderPlugin { public: // Return a vector of pointers - typedef boost::ptr_vector PiZeroVector; - // Storing the result in an auto ptr on function return allows - // allows us to safely release the ptr_vector in the virtual function - typedef std::unique_ptr return_type; + typedef std::vector> PiZeroVector; + typedef PiZeroVector return_type; explicit RecoTauPiZeroBuilderPlugin(const edm::ParameterSet& pset, edm::ConsumesCollector&& iC) : RecoTauEventHolderPlugin(pset) {} ~RecoTauPiZeroBuilderPlugin() override {} diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc index 53f921f9cc43a..b6535edd54a4e 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromGenericTrackPlugin.cc @@ -343,7 +343,7 @@ namespace reco { output.push_back(std::move(chargedHadron)); } - return output.release(); + return output; } typedef PFRecoTauChargedHadronFromGenericTrackPlugin PFRecoTauChargedHadronFromTrackPlugin; diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc index cdec62b8e70d9..5cad14272c84d 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronFromPFCandidatePlugin.cc @@ -183,7 +183,7 @@ namespace reco { algo = PFRecoTauChargedHadron::kChargedPFCandidate; else algo = PFRecoTauChargedHadron::kPFNeutralHadron; - std::unique_ptr chargedHadron(new PFRecoTauChargedHadron(**cand, algo)); + auto chargedHadron = std::make_unique(**cand, algo); const reco::PFCandidate* pfCand = dynamic_cast(&**cand); if (pfCand) { @@ -281,7 +281,7 @@ namespace reco { output.push_back(std::move(chargedHadron)); } - return output.release(); + return output; } } // namespace tau diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc index 24b9dda72ea0e..c9e7d35e46a24 100644 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc +++ b/RecoTauTag/RecoTau/plugins/PFRecoTauChargedHadronProducer.cc @@ -41,15 +41,11 @@ #include "CommonTools/Utils/interface/StringCutObjectSelector.h" -#include -#include - -#include - #include #include #include #include +#include #include #include #include @@ -63,17 +59,16 @@ class PFRecoTauChargedHadronProducer : public edm::stream::EDProducer<> { ~PFRecoTauChargedHadronProducer() override {} void produce(edm::Event& evt, const edm::EventSetup& es) override; template - void print(const T& chargedHadrons); + void print(const T& chargedHadron); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - typedef boost::ptr_vector builderList; - typedef boost::ptr_vector rankerList; - typedef boost::ptr_vector ChargedHadronVector; - typedef boost::ptr_list ChargedHadronList; + typedef std::vector> RankerList; + typedef Builder::return_type ChargedHadronVector; + typedef std::list> ChargedHadronList; - typedef reco::tau::RecoTauLexicographicalRanking ChargedHadronPredicate; + typedef reco::tau::RecoTauLexicographicalRanking ChargedHadronPredicate; std::string moduleLabel_; @@ -84,8 +79,8 @@ class PFRecoTauChargedHadronProducer : public edm::stream::EDProducer<> { double maxJetAbsEta_; // plugins for building and ranking ChargedHadron candidates - builderList builders_; - rankerList rankers_; + std::vector> builders_; + RankerList rankers_; std::unique_ptr predicate_; @@ -110,7 +105,7 @@ PFRecoTauChargedHadronProducer::PFRecoTauChargedHadronProducer(const edm::Parame std::string pluginType = pset->getParameter("plugin"); edm::ParameterSet pset_modified = (*pset); pset_modified.addParameter("verbosity", verbosity_); - builders_.push_back( + builders_.emplace_back( PFRecoTauChargedHadronBuilderPluginFactory::get()->create(pluginType, pset_modified, consumesCollector())); } @@ -120,7 +115,7 @@ PFRecoTauChargedHadronProducer::PFRecoTauChargedHadronProducer(const edm::Parame std::string pluginType = pset->getParameter("plugin"); edm::ParameterSet pset_modified = (*pset); pset_modified.addParameter("verbosity", verbosity_); - rankers_.push_back(PFRecoTauChargedHadronQualityPluginFactory::get()->create(pluginType, pset_modified)); + rankers_.emplace_back(PFRecoTauChargedHadronQualityPluginFactory::get()->create(pluginType, pset_modified)); } // build the sorting predicate @@ -143,7 +138,7 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe // give each of our plugins a chance at doing something with the edm::Event for (auto& builder : builders_) { - builder.setup(evt, es); + builder->setup(evt, es); } // get a view of our jets via the base candidates @@ -179,21 +174,23 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe // merge candidates reconstructed by all desired algorithm plugins for (auto const& builder : builders_) { try { - ChargedHadronVector result(builder(*pfJet)); + ChargedHadronVector result((*builder)(*pfJet)); if (verbosity_) { - edm::LogPrint("PFRecoTauChHProducer") << "result of builder = " << builder.name() << ":"; - print(result); + edm::LogPrint("PFRecoTauChHProducer") << "result of builder = " << builder->name() << ":"; + for (auto const& had : result) { + print(*had); + } } - uncleanedChargedHadrons.transfer(uncleanedChargedHadrons.end(), result); + std::move(result.begin(), result.end(), std::back_inserter(uncleanedChargedHadrons)); } catch (cms::Exception& exception) { edm::LogError("BuilderPluginException") - << "Exception caught in builder plugin " << builder.name() << ", rethrowing" << std::endl; + << "Exception caught in builder plugin " << builder->name() << ", rethrowing" << std::endl; throw exception; } } // rank the candidates according to our quality plugins - uncleanedChargedHadrons.sort(*predicate_); + uncleanedChargedHadrons.sort([this](const auto& a, const auto& b) { return (*predicate_)(*a, *b); }); // define collection of cleaned ChargedHadrons; std::vector cleanedChargedHadrons; @@ -205,7 +202,8 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe while (!uncleanedChargedHadrons.empty()) { // get next best ChargedHadron candidate - std::unique_ptr nextChargedHadron(uncleanedChargedHadrons.pop_front().release()); + std::unique_ptr nextChargedHadron = std::move(uncleanedChargedHadrons.front()); + uncleanedChargedHadrons.pop_front(); if (verbosity_) { edm::LogPrint("PFRecoTauChHProducer") << "processing nextChargedHadron:"; edm::LogPrint("PFRecoTauChHProducer") << (*nextChargedHadron); @@ -306,8 +304,10 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe reco::tau::setChargedHadronP4(*nextChargedHadron); // reinsert ChargedHadron candidate into list of uncleaned candidates, // at position according to new rank - ChargedHadronList::iterator insertionPoint = std::lower_bound( - uncleanedChargedHadrons.begin(), uncleanedChargedHadrons.end(), *nextChargedHadron, *predicate_); + auto insertionPoint = std::lower_bound(uncleanedChargedHadrons.begin(), + uncleanedChargedHadrons.end(), + *nextChargedHadron, + [this](const auto& a, const auto& b) { return (*predicate_)(*a, b); }); if (verbosity_) { edm::LogPrint("PFRecoTauChHProducer") << "--> removing non-unique neutral PFCandidates and reinserting " "nextChargedHadron in uncleaned collection."; @@ -317,7 +317,9 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe } if (verbosity_) { - print(cleanedChargedHadrons); + for (auto const& had : cleanedChargedHadrons) { + print(had); + } } // add ChargedHadron-to-jet association @@ -328,17 +330,14 @@ void PFRecoTauChargedHadronProducer::produce(edm::Event& evt, const edm::EventSe } template -void PFRecoTauChargedHadronProducer::print(const T& chargedHadrons) { - for (typename T::const_iterator chargedHadron = chargedHadrons.begin(); chargedHadron != chargedHadrons.end(); - ++chargedHadron) { - edm::LogPrint("PFRecoTauChHProducer") << (*chargedHadron); - edm::LogPrint("PFRecoTauChHProducer") << "Rankers:"; - for (rankerList::const_iterator ranker = rankers_.begin(); ranker != rankers_.end(); ++ranker) { - const unsigned width = 25; - edm::LogPrint("PFRecoTauChHProducer") - << " " << std::setiosflags(std::ios::left) << std::setw(width) << ranker->name() << " " - << std::resetiosflags(std::ios::left) << std::setprecision(3) << (*ranker)(*chargedHadron) << std::endl; - } +void PFRecoTauChargedHadronProducer::print(const T& chargedHadron) { + edm::LogPrint("PFRecoTauChHProducer") << chargedHadron; + edm::LogPrint("PFRecoTauChHProducer") << "Rankers:"; + for (auto const& ranker : rankers_) { + constexpr unsigned width = 25; + edm::LogPrint("PFRecoTauChHProducer") + << " " << std::setiosflags(std::ios::left) << std::setw(width) << ranker->name() << " " + << std::resetiosflags(std::ios::left) << std::setprecision(3) << (*ranker)(chargedHadron) << std::endl; } } diff --git a/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc index 0c87a2bdd2d97..8f46466039760 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauBuilderCombinatoricPlugin.cc @@ -494,7 +494,7 @@ namespace reco { } } - return output.release(); + return output; } } // namespace tau diff --git a/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc index a2cbdcc95483a..eb075a420ca41 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauBuilderConePlugin.cc @@ -245,7 +245,7 @@ namespace reco { } else { // If there is no leading charged candidate at all, return nothing - the // producer class that owns the plugin will build a null tau if desired. - return output.release(); + return output; } // Find the leading neutral candidate @@ -419,7 +419,7 @@ namespace reco { setTauQuantities(*tauPtr, minAbsPhotonSumPt_insideSignalCone_, minRelPhotonSumPt_insideSignalCone_); output.push_back(std::move(tauPtr)); - return output.release(); + return output; } } // namespace tau } // namespace reco diff --git a/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc b/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc index bf8584f5f4fda..766c484351a8e 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauCleaner.cc @@ -14,7 +14,6 @@ * */ -#include #include #include diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc index 2efb91c7f36a1..41dd81a589342 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroCombinatoricPlugin.cc @@ -62,7 +62,7 @@ namespace reco { CandPtrs pfGammaCands = qcuts_.filterCandRefs(pfGammas(jet)); // Check if we have anything to do... if (pfGammaCands.size() < choose_) - return output.release(); + return output; // Define the valid range of gammas to use CandIter start_iter = pfGammaCands.begin(); @@ -81,8 +81,7 @@ namespace reco { std::unique_ptr piZero( new RecoTauPiZero(0, totalP4, Candidate::Point(0, 0, 0), 111, 10001, true, RecoTauPiZero::kCombinatoric)); // Add our daughters from this combination - for (ComboGenerator::combo_iterator candidate = combo->combo_begin(); candidate != combo->combo_end(); - ++candidate) { + for (auto candidate = combo->combo_begin(); candidate != combo->combo_end(); ++candidate) { piZero->addDaughter(*candidate); } p4Builder_.set(*piZero); @@ -91,9 +90,9 @@ namespace reco { piZero->setVertex(piZero->daughterPtr(0)->vertex()); if ((maxMass_ < 0 || piZero->mass() < maxMass_) && piZero->mass() > minMass_) - output.push_back(piZero.get()); + output.emplace_back(piZero.release()); } - return output.release(); + return output; } } // namespace tau diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc index e3da028c506f0..9c943a8edbefb 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroProducer.cc @@ -12,8 +12,6 @@ */ #include -#include -#include #include #include @@ -52,15 +50,14 @@ class RecoTauPiZeroProducer : public edm::stream::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - typedef boost::ptr_vector builderList; - typedef boost::ptr_vector rankerList; - typedef boost::ptr_vector PiZeroVector; - typedef boost::ptr_list PiZeroList; + typedef std::vector> RankerList; + typedef Builder::return_type PiZeroVector; + typedef std::list> PiZeroList; - typedef reco::tau::RecoTauLexicographicalRanking PiZeroPredicate; + typedef reco::tau::RecoTauLexicographicalRanking PiZeroPredicate; - builderList builders_; - rankerList rankers_; + std::vector> builders_; + RankerList rankers_; std::unique_ptr predicate_; double piZeroMass_; @@ -92,7 +89,7 @@ RecoTauPiZeroProducer::RecoTauPiZeroProducer(const edm::ParameterSet& pset) { // Get plugin name const std::string& pluginType = builderPSet->getParameter("plugin"); // Build the plugin - builders_.push_back( + builders_.emplace_back( RecoTauPiZeroBuilderPluginFactory::get()->create(pluginType, *builderPSet, consumesCollector())); } @@ -100,7 +97,7 @@ RecoTauPiZeroProducer::RecoTauPiZeroProducer(const edm::ParameterSet& pset) { const VPSet& rankers = pset.getParameter("ranking"); for (VPSet::const_iterator rankerPSet = rankers.begin(); rankerPSet != rankers.end(); ++rankerPSet) { const std::string& pluginType = rankerPSet->getParameter("plugin"); - rankers_.push_back(RecoTauPiZeroQualityPluginFactory::get()->create(pluginType, *rankerPSet)); + rankers_.emplace_back(RecoTauPiZeroQualityPluginFactory::get()->create(pluginType, *rankerPSet)); } // Build the sorting predicate @@ -124,13 +121,11 @@ void RecoTauPiZeroProducer::produce(edm::Event& evt, const edm::EventSetup& es) // Give each of our plugins a chance at doing something with the edm::Event for (auto& builder : builders_) { - builder.setup(evt, es); + builder->setup(evt, es); } // Make our association - std::unique_ptr association; - - association = std::make_unique(reco::JetRefBaseProd(jetView)); + auto association = std::make_unique(reco::JetRefBaseProd(jetView)); // Loop over our jets size_t nJets = jetView->size(); @@ -147,23 +142,24 @@ void RecoTauPiZeroProducer::produce(edm::Event& evt, const edm::EventSetup& es) // Compute the pi zeros from this jet for all the desired algorithms for (auto const& builder : builders_) { try { - PiZeroVector result(builder(*jet)); - dirtyPiZeros.transfer(dirtyPiZeros.end(), result); + PiZeroVector result((*builder)(*jet)); + std::move(result.begin(), result.end(), std::back_inserter(dirtyPiZeros)); } catch (cms::Exception& exception) { edm::LogError("BuilderPluginException") - << "Exception caught in builder plugin " << builder.name() << ", rethrowing" << std::endl; + << "Exception caught in builder plugin " << builder->name() << ", rethrowing" << std::endl; throw exception; } } // Rank the candidates according to our quality plugins - dirtyPiZeros.sort(*predicate_); + dirtyPiZeros.sort([this](const auto& a, const auto& b) { return (*predicate_)(*a, *b); }); // Keep track of the photons in the clean collection std::vector cleanPiZeros; std::set photonsInCleanCollection; while (!dirtyPiZeros.empty()) { // Pull our candidate pi zero from the front of the list - std::unique_ptr toAdd(dirtyPiZeros.pop_front().release()); + std::unique_ptr toAdd(dirtyPiZeros.front().release()); + dirtyPiZeros.pop_front(); // If this doesn't pass our basic selection, discard it. if (!(*outputSelector_)(*toAdd)) { continue; @@ -196,8 +192,10 @@ void RecoTauPiZeroProducer::produce(edm::Event& evt, const edm::EventSetup& es) AddFourMomenta p4Builder_; p4Builder_.set(*toAdd); // Put this pi zero back into the collection of sorted dirty pizeros - PiZeroList::iterator insertionPoint = - std::lower_bound(dirtyPiZeros.begin(), dirtyPiZeros.end(), *toAdd, *predicate_); + auto insertionPoint = + std::lower_bound(dirtyPiZeros.begin(), dirtyPiZeros.end(), *toAdd, [this](const auto& a, const auto& b) { + return (*predicate_)(*a, b); + }); dirtyPiZeros.insert(insertionPoint, std::move(toAdd)); } } @@ -222,7 +220,7 @@ void RecoTauPiZeroProducer::print(const std::vector& piZero for (auto const& piZero : piZeros) { out << piZero; out << "* Rankers:" << std::endl; - for (rankerList::const_iterator ranker = rankers_.begin(); ranker != rankers_.end(); ++ranker) { + for (auto const& ranker : rankers_) { out << "* " << std::setiosflags(std::ios::left) << std::setw(width) << ranker->name() << " " << std::resetiosflags(std::ios::left) << std::setprecision(3) << (*ranker)(piZero); out << std::endl; diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc index 33f482dc9916d..beb6b25c6da20 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin.cc @@ -94,9 +94,7 @@ namespace reco { //PFCandPtrs candsVector = qcuts_->filterCandRefs(pfGammas(jet)); // Convert to stl::list to allow fast deletions - typedef std::list CandPtrList; - typedef std::list::iterator CandPtrListIter; - CandPtrList cands; + std::list cands; cands.insert(cands.end(), candsVector.begin(), candsVector.end()); while (!cands.empty()) { @@ -105,11 +103,11 @@ namespace reco { cands.pop_front(); // Add a new candidate to our collection using this seed - std::unique_ptr strip(new RecoTauPiZero(*seed, RecoTauPiZero::kStrips)); + auto strip = std::make_unique(*seed, RecoTauPiZero::kStrips); strip->addDaughter(seed); // Find all other objects in the strip - CandPtrListIter stripCand = cands.begin(); + auto stripCand = cands.begin(); while (stripCand != cands.end()) { if (fabs(strip->eta() - (*stripCand)->eta()) < etaAssociationDistance_ && fabs(deltaPhi(*strip, **stripCand)) < phiAssociationDistance_) { @@ -128,20 +126,22 @@ namespace reco { // Update the vertex if (strip->daughterPtr(0).isNonnull()) strip->setVertex(strip->daughterPtr(0)->vertex()); - output.push_back(strip.get()); + output.emplace_back(strip.release()); } // Check if we want to combine our strips if (combineStrips_ && output.size() > 1) { PiZeroVector stripCombinations; // Sort the output by descending pt - output.sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1.pt() > arg2.pt(); }); + std::sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1->pt() > arg2->pt(); }); // Get the end of interesting set of strips to try and combine PiZeroVector::const_iterator end_iter = takeNElements(output.begin(), output.end(), maxStrips_); // Look at all the combinations - for (PiZeroVector::const_iterator first = output.begin(); first != end_iter - 1; ++first) { - for (PiZeroVector::const_iterator second = first + 1; second != end_iter; ++second) { + for (PiZeroVector::const_iterator firstIter = output.begin(); firstIter != end_iter - 1; ++firstIter) { + for (PiZeroVector::const_iterator secondIter = firstIter + 1; secondIter != end_iter; ++secondIter) { + auto const& first = *firstIter; + auto const& second = *secondIter; Candidate::LorentzVector firstP4 = first->p4(); Candidate::LorentzVector secondP4 = second->p4(); // If we assume a certain mass for each strip apply it here. @@ -149,15 +149,15 @@ namespace reco { secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_); Candidate::LorentzVector totalP4 = firstP4 + secondP4; // Make our new combined strip - std::unique_ptr combinedStrips( - new RecoTauPiZero(0, - totalP4, - Candidate::Point(0, 0, 0), - //111, 10001, true, RecoTauPiZero::kCombinatoricStrips)); - 111, - 10001, - true, - RecoTauPiZero::kUndefined)); + auto combinedStrips = + std::make_unique(0, + totalP4, + Candidate::Point(0, 0, 0), + //111, 10001, true, RecoTauPiZero::kCombinatoricStrips)); + 111, + 10001, + true, + RecoTauPiZero::kUndefined); // Now loop over the strip members for (auto const& gamma : first->daughterPtrVector()) { @@ -170,15 +170,14 @@ namespace reco { if (combinedStrips->daughterPtr(0).isNonnull()) combinedStrips->setVertex(combinedStrips->daughterPtr(0)->vertex()); // Add to our collection of combined strips - stripCombinations.push_back(combinedStrips.get()); + stripCombinations.emplace_back(combinedStrips.release()); } } - // When done doing all the combinations, add the combined strips to the - // output. - output.transfer(output.end(), stripCombinations); + // When done doing all the combinations, add the combined strips to the output. + std::move(stripCombinations.begin(), stripCombinations.end(), std::back_inserter(output)); } - return output.release(); + return output; } } // namespace tau } // namespace reco diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc index 1be64b49e9cce..eeb3585aca770 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin2.cc @@ -303,13 +303,15 @@ namespace reco { if (combineStrips_ && output.size() > 1) { PiZeroVector stripCombinations; // Sort the output by descending pt - output.sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1.pt() > arg2.pt(); }); + std::sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1->pt() > arg2->pt(); }); // Get the end of interesting set of strips to try and combine PiZeroVector::const_iterator end_iter = takeNElements(output.begin(), output.end(), maxStrips_); // Look at all the combinations - for (PiZeroVector::const_iterator first = output.begin(); first != end_iter - 1; ++first) { - for (PiZeroVector::const_iterator second = first + 1; second != end_iter; ++second) { + for (PiZeroVector::const_iterator firstIter = output.begin(); firstIter != end_iter - 1; ++firstIter) { + for (PiZeroVector::const_iterator secondIter = firstIter + 1; secondIter != end_iter; ++secondIter) { + auto const& first = *firstIter; + auto const& second = *secondIter; Candidate::LorentzVector firstP4 = first->p4(); Candidate::LorentzVector secondP4 = second->p4(); // If we assume a certain mass for each strip apply it here. @@ -317,15 +319,15 @@ namespace reco { secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_); Candidate::LorentzVector totalP4 = firstP4 + secondP4; // Make our new combined strip - std::unique_ptr combinedStrips( - new RecoTauPiZero(0, - totalP4, - Candidate::Point(0, 0, 0), - //111, 10001, true, RecoTauPiZero::kCombinatoricStrips)); - 111, - 10001, - true, - RecoTauPiZero::kUndefined)); + auto combinedStrips = + std::make_unique(0, + totalP4, + Candidate::Point(0, 0, 0), + //111, 10001, true, RecoTauPiZero::kCombinatoricStrips)); + 111, + 10001, + true, + RecoTauPiZero::kUndefined); // Now loop over the strip members for (auto const& gamma : first->daughterPtrVector()) { @@ -343,10 +345,10 @@ namespace reco { } // When done doing all the combinations, add the combined strips to the // output. - output.transfer(output.end(), stripCombinations); + std::move(stripCombinations.begin(), stripCombinations.end(), std::back_inserter(output)); } - return output.release(); + return output; } } // namespace tau } // namespace reco diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc index 6c1f431686ee7..25f1eec7636e4 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroStripPlugin3.cc @@ -334,13 +334,15 @@ namespace reco { if (combineStrips_ && output.size() > 1) { PiZeroVector stripCombinations; // Sort the output by descending pt - output.sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1.pt() > arg2.pt(); }); + std::sort(output.begin(), output.end(), [&](auto& arg1, auto& arg2) { return arg1->pt() > arg2->pt(); }); // Get the end of interesting set of strips to try and combine PiZeroVector::const_iterator end_iter = takeNElements(output.begin(), output.end(), maxStrips_); // Look at all the combinations - for (PiZeroVector::const_iterator first = output.begin(); first != end_iter - 1; ++first) { - for (PiZeroVector::const_iterator second = first + 1; second != end_iter; ++second) { + for (PiZeroVector::const_iterator firstIter = output.begin(); firstIter != end_iter - 1; ++firstIter) { + for (PiZeroVector::const_iterator secondIter = firstIter + 1; secondIter != end_iter; ++secondIter) { + auto const& first = *firstIter; + auto const& second = *secondIter; Candidate::LorentzVector firstP4 = first->p4(); Candidate::LorentzVector secondP4 = second->p4(); // If we assume a certain mass for each strip apply it here. @@ -348,15 +350,15 @@ namespace reco { secondP4 = applyMassConstraint(secondP4, combinatoricStripMassHypo_); Candidate::LorentzVector totalP4 = firstP4 + secondP4; // Make our new combined strip - std::unique_ptr combinedStrips( - new RecoTauPiZero(0, - totalP4, - Candidate::Point(0, 0, 0), - //111, 10001, true, RecoTauPiZero::kCombinatoricStrips)); - 111, - 10001, - true, - RecoTauPiZero::kUndefined)); + auto combinedStrips = + std::make_unique(0, + totalP4, + Candidate::Point(0, 0, 0), + //111, 10001, true, RecoTauPiZero::kCombinatoricStrips)); + 111, + 10001, + true, + RecoTauPiZero::kUndefined); // Now loop over the strip members for (auto const& gamma : first->daughterPtrVector()) { @@ -376,12 +378,12 @@ namespace reco { } // When done doing all the combinations, add the combined strips to the // output. - output.transfer(output.end(), stripCombinations); + std::move(stripCombinations.begin(), stripCombinations.end(), std::back_inserter(output)); } // Compute correction to account for spread of photon energy in eta and phi // in case charged pions make nuclear interactions or photons convert within the tracking detector - for (PiZeroVector::iterator strip = output.begin(); strip != output.end(); ++strip) { + for (auto const& strip : output) { double bendCorrEta = 0.; double bendCorrPhi = 0.; double energySum = 0.; @@ -399,7 +401,7 @@ namespace reco { strip->setBendCorrPhi(bendCorrPhi); } - return output.release(); + return output; } } // namespace tau } // namespace reco diff --git a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc index 524c94b089bb8..327bd244ee568 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauPiZeroTrivialPlugin.cc @@ -46,7 +46,7 @@ namespace reco::tau { piZero->addDaughter(gamma); output.push_back(std::move(piZero)); } - return output.release(); + return output; } } // namespace reco::tau diff --git a/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc b/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc index a21cef4ec39dc..f78e2f9bb72f7 100644 --- a/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc +++ b/RecoTauTag/RecoTau/plugins/RecoTauProducer.cc @@ -192,22 +192,24 @@ void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) { // Loop over our builders and create the set of taus for this jet unsigned int nTausBuilt = 0; for (const auto& builder : builders_) { - // Get a ptr_vector of taus from the builder + // Get a std::vector of std::unique_ptr to taus from the builder reco::tau::RecoTauBuilderPlugin::output_type taus( (*builder)(jetRef, chargedHadrons, piZeros, uniqueRegionalCands)); // Make sure all taus have their jetref set correctly - std::for_each(taus.begin(), taus.end(), [&](auto& arg) { arg.setjetRef(reco::JetBaseRef(jetRef)); }); + std::for_each(taus.begin(), taus.end(), [&](auto& arg) { arg->setjetRef(reco::JetBaseRef(jetRef)); }); // Copy without selection if (!outputSelector_.get()) { - output->insert(output->end(), taus.begin(), taus.end()); + for (auto& tau : taus) { + output->push_back(*tau); + } nTausBuilt += taus.size(); } else { // Copy only those that pass the selection. for (auto const& tau : taus) { - if ((*outputSelector_)(tau)) { + if ((*outputSelector_)(*tau)) { nTausBuilt++; - output->push_back(tau); + output->push_back(*tau); } } } @@ -223,9 +225,9 @@ void RecoTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) { } // Loop over the taus we have created and apply our modifiers to the taus - for (reco::PFTauCollection::iterator tau = output->begin(); tau != output->end(); ++tau) { + for (auto& tau : *output) { for (const auto& modifier : modifiers_) { - (*modifier)(*tau); + (*modifier)(tau); } }