From 9916e65f003d72be67e59d33dbb1df3ed91c3577 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 29 Nov 2022 15:36:51 +0100 Subject: [PATCH] Remove deprecated NoPileUpPFMEtDataProducer --- .../plugins/NoPileUpPFMEtDataProducer.cc | 293 ------------------ .../plugins/NoPileUpPFMEtDataProducer.h | 73 ----- .../python/mitigatedMETSequence_cff.py | 17 - .../METPUSubtraction/python/pfNoPUMET_cff.py | 18 -- 4 files changed, 401 deletions(-) delete mode 100644 RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.cc delete mode 100644 RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.h diff --git a/RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.cc b/RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.cc deleted file mode 100644 index c3e87281e17d2..0000000000000 --- a/RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.cc +++ /dev/null @@ -1,293 +0,0 @@ -#include "RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.h" - -#include "FWCore/Utilities/interface/Exception.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include -#include - -const int flag_isWithinFakeJet = 1; -const int flag_isWithinSelectedJet = 2; -const int flag_isWithinJetForMEtCov = 4; - -const double dR2Min = 0.001 * 0.001; - -NoPileUpPFMEtDataProducer::NoPileUpPFMEtDataProducer(const edm::ParameterSet& cfg) - : moduleLabel_(cfg.getParameter("@module_label")), - looseJetIdAlgo_(nullptr), - pfMEtSignInterface_(nullptr) { - srcJets_ = consumes(cfg.getParameter("srcJets")); - srcJetIds_ = consumes >(cfg.getParameter("srcJetIds")); - minJetPt_ = cfg.getParameter("minJetPt"); - std::string jetIdSelection_string = cfg.getParameter("jetIdSelection"); - if (jetIdSelection_string == "loose") - jetIdSelection_ = PileupJetIdentifier::kLoose; - else if (jetIdSelection_string == "medium") - jetIdSelection_ = PileupJetIdentifier::kMedium; - else if (jetIdSelection_string == "tight") - jetIdSelection_ = PileupJetIdentifier::kTight; - else - throw cms::Exception("NoPileUpPFMEtDataProducer") - << "Invalid Configuration Parameter 'jetIdSelection' = " << jetIdSelection_string << " !!\n"; - jetEnOffsetCorrLabel_ = cfg.getParameter("jetEnOffsetCorrLabel"); - - srcPFCandidates_ = consumes(cfg.getParameter("srcPFCandidates")); - srcPFCandidatesView_ = consumes >(cfg.getParameter("srcPFCandidates")); - srcPFCandToVertexAssociations_ = - consumes(cfg.getParameter("srcPFCandToVertexAssociations")); - srcJetsForMEtCov_ = mayConsume(cfg.getParameter("srcJetsForMEtCov")); - minJetPtForMEtCov_ = cfg.getParameter("minJetPtForMEtCov"); - srcHardScatterVertex_ = consumes(cfg.getParameter("srcHardScatterVertex")); - dZcut_ = cfg.getParameter("dZcut"); - - edm::ParameterSet cfgPFJetIdAlgo; - cfgPFJetIdAlgo.addParameter("version", "FIRSTDATA"); - cfgPFJetIdAlgo.addParameter("quality", "LOOSE"); - looseJetIdAlgo_ = new PFJetIDSelectionFunctor(cfgPFJetIdAlgo); - - pfMEtSignInterface_ = new PFMEtSignInterfaceBase(cfg.getParameter("resolution")); - - maxWarnings_ = (cfg.exists("maxWarnings")) ? cfg.getParameter("maxWarnings") : 1; - numWarnings_ = 0; - - verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter("verbosity") : 0; - - produces("jetInfos"); - produces("pfCandInfos"); -} - -NoPileUpPFMEtDataProducer::~NoPileUpPFMEtDataProducer() { - delete looseJetIdAlgo_; - delete pfMEtSignInterface_; -} - -namespace { - void setPFCandidateFlag(const reco::PFJet& pfJet, - const edm::View& pfCandidateCollection, - std::vector& flags, - int value, - int& numWarnings, - int maxWarnings, - std::vector* pfCandidateToJetAssociations = nullptr) { - edm::ProductID viewProductID; - if (!pfCandidateCollection.empty()) { - viewProductID = pfCandidateCollection.ptrAt(0).id(); - } - - std::vector pfConsts = pfJet.getPFConstituents(); - for (std::vector::const_iterator pfJetConstituent = pfConsts.begin(); - pfJetConstituent != pfConsts.end(); - ++pfJetConstituent) { - std::vector idxs; - if (!pfCandidateCollection.empty() && pfJetConstituent->id() == viewProductID) { - idxs.push_back(pfJetConstituent->key()); - } else { - bool isMatched_fast = false; - if (pfJetConstituent->key() < pfCandidateCollection.size()) { - edm::Ptr pfCandidatePtr = pfCandidateCollection.ptrAt(pfJetConstituent->key()); - double dR2 = deltaR2((*pfJetConstituent)->p4(), pfCandidatePtr->p4()); - if (dR2 < dR2Min) { - idxs.push_back(pfCandidatePtr.key()); - isMatched_fast = true; - } - } - - if (!isMatched_fast) { - size_t numPFCandidates = pfCandidateCollection.size(); - for (size_t iPFCandidate = 0; iPFCandidate < numPFCandidates; ++iPFCandidate) { - edm::Ptr pfCandidatePtr = pfCandidateCollection.ptrAt(iPFCandidate); - double dR2 = deltaR2((*pfJetConstituent)->p4(), pfCandidatePtr->p4()); - if (dR2 < dR2Min) { - idxs.push_back(pfCandidatePtr.key()); - } - } - if (numWarnings < maxWarnings) { - edm::LogWarning("setPFCandidateFlag") - << " The productIDs of PFJetConstituent and PFCandidateCollection passed as function arguments don't " - "match.\n" - << "NOTE: The return value will be unaffected, but the code will run MUCH slower !!"; - ++numWarnings; - } - } - } - if (!idxs.empty()) { - for (std::vector::const_iterator idx = idxs.begin(); idx != idxs.end(); ++idx) { - if ((*idx) >= (int)flags.size()) - flags.resize(2 * flags.size()); - flags[*idx] |= value; - if (pfCandidateToJetAssociations != nullptr) - (*pfCandidateToJetAssociations)[*idx] = &pfJet; - } - } else { - edm::LogError("setPFCandidateFlag") - << " Failed to associated PFJetConstituent with index = " << pfJetConstituent->key() - << " to any PFCandidate !!"; - } - } - } -} // namespace - -void NoPileUpPFMEtDataProducer::produce(edm::Event& evt, const edm::EventSetup& es) { - LogDebug("produce") << ":\n" - << " moduleLabel = " << moduleLabel_ << std::endl; - - // get jets - edm::Handle jets; - evt.getByToken(srcJets_, jets); - - typedef edm::ValueMap jetIdMap; - edm::Handle jetIds; - evt.getByToken(srcJetIds_, jetIds); - - // get jets for computing contributions to PFMEt significance matrix - edm::Handle jetsForMEtCov; - if (!srcJetsForMEtCov_.isUninitialized()) - evt.getByToken(srcJetsForMEtCov_, jetsForMEtCov); - - // get PFCandidates - edm::Handle > pfCandidates; - evt.getByToken(srcPFCandidatesView_, pfCandidates); - - std::vector pfCandidateFlags(pfCandidates->size()); - std::vector pfCandidateToJetAssociations(pfCandidates->size()); - - edm::Handle pfCandidateHandle; - evt.getByToken(srcPFCandidates_, pfCandidateHandle); - - // get PFCandidate-to-vertex associations and "the" hard-scatter vertex - edm::Handle pfCandToVertexAssociations; - evt.getByToken(srcPFCandToVertexAssociations_, pfCandToVertexAssociations); - - noPuUtils::reversedPFCandToVertexAssMap pfCandToVertexAssociations_reversed = - noPuUtils::reversePFCandToVertexAssociation(*pfCandToVertexAssociations); - - edm::Handle hardScatterVertex; - evt.getByToken(srcHardScatterVertex_, hardScatterVertex); - - auto jetInfos = std::make_unique(); - auto pfCandInfos = std::make_unique(); - - // const JetCorrector* jetEnOffsetCorrector = nullptr; - if (!jetEnOffsetCorrLabel_.empty()) { - throw cms::Exception("NoPileUpPFMEtDataProducer::produce") - << "Failed to access Jet corrections for = " << jetEnOffsetCorrLabel_ << " !!\n" - << "During the migration from the deprecated ::JetCorrector to the\n" - << "new reco::JetCorrector class, this module was never completely migrated.\n" - << "The usage of the deprecated class was removed and replaced by this exception.\n" - << "To use the new reco::JetCorrector class, someone must do the work\n" - << "to implement and test usage of reco::JetCollector in this class.\n"; - } - - size_t numJets = jets->size(); - for (size_t iJet = 0; iJet < numJets; ++iJet) { - reco::PFJetRef jet(jets, iJet); - if (!(jet->pt() > minJetPt_)) - continue; - - bool passesLooseJetId = (*looseJetIdAlgo_)(*jet); - if (!passesLooseJetId) { - setPFCandidateFlag(*jet, *pfCandidates, pfCandidateFlags, flag_isWithinFakeJet, numWarnings_, maxWarnings_); - } - setPFCandidateFlag(*jet, *pfCandidates, pfCandidateFlags, flag_isWithinSelectedJet, numWarnings_, maxWarnings_); - - reco::PUSubMETCandInfo jetInfo; - jetInfo.setP4(jet->p4()); - int jetId = (*jetIds)[jet]; - bool jetIdSelection_passed = PileupJetIdentifier::passJetId(jetId, jetIdSelection_); - jetInfo.setType((jetIdSelection_passed) ? reco::PUSubMETCandInfo::kHS : reco::PUSubMETCandInfo::kPU); - jetInfo.setPassesLooseJetId(passesLooseJetId); - double jetEnergy_uncorrected = jet->chargedHadronEnergy() + jet->neutralHadronEnergy() + jet->photonEnergy() + - jet->electronEnergy() + jet->muonEnergy() + jet->HFHadronEnergy() + - jet->HFEMEnergy(); - double jetPx_uncorrected = cos(jet->phi()) * sin(jet->theta()) * jetEnergy_uncorrected; - double jetPy_uncorrected = sin(jet->phi()) * sin(jet->theta()) * jetEnergy_uncorrected; - double jetPz_uncorrected = cos(jet->theta()) * jetEnergy_uncorrected; - reco::Candidate::LorentzVector rawJetP4( - jetPx_uncorrected, jetPy_uncorrected, jetPz_uncorrected, jetEnergy_uncorrected); - reco::PFJet rawJet(*jet); - rawJet.setP4(rawJetP4); - double jetNeutralEnFrac = (jetEnergy_uncorrected > 0.) - ? (jet->neutralEmEnergy() + jet->neutralHadronEnergy()) / jetEnergy_uncorrected - : -1.; - jetInfo.setChargedEnFrac((1 - jetNeutralEnFrac)); - // jetInfo.setOffsetEnCorr( - // (jetEnOffsetCorrector) ? rawJet.energy() * (1. - jetEnOffsetCorrector->correction(rawJet, evt, es)) : 0.); - jetInfo.setOffsetEnCorr(0.); - - jetInfo.setMEtSignObj(pfMEtSignInterface_->compResolution(&(*jet))); - - jetInfos->push_back(jetInfo); - } - LogDebug("produce") << "#jetInfos = " << jetInfos->size() << std::endl; - - for (reco::PFJetCollection::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) { - if (jet->pt() > minJetPtForMEtCov_) { - setPFCandidateFlag(*jet, - *pfCandidates, - pfCandidateFlags, - flag_isWithinJetForMEtCov, - numWarnings_, - maxWarnings_, - &pfCandidateToJetAssociations); - } - } - - size_t numPFCandidates = pfCandidates->size(); - for (size_t iPFCandidate = 0; iPFCandidate < numPFCandidates; ++iPFCandidate) { - reco::PFCandidatePtr pfCandidatePtr = pfCandidates->ptrAt(iPFCandidate); - - int idx = pfCandidatePtr.key(); - reco::PUSubMETCandInfo pfCandInfo; - pfCandInfo.setP4(pfCandidatePtr->p4()); - pfCandInfo.setCharge(pfCandidatePtr->charge()); - pfCandInfo.setType(-1); - // CV: need to call isVertexAssociated_fast instead of isVertexAssociated function - // (makes run-time of MVAPFMEtDataProducer::produce decrease from ~1s per event to ~0.35s per event) - //int vtxAssociationType = isVertexAssociated(*pfCandidatePtr, *pfCandToVertexAssociations, *hardScatterVertex, dZcut_); - reco::PFCandidateRef pfCandidateRef(pfCandidateHandle, iPFCandidate); - int vtxAssociationType = noPuUtils::isVertexAssociated_fast( - pfCandidateRef, pfCandToVertexAssociations_reversed, *hardScatterVertex, dZcut_, numWarnings_, maxWarnings_); - bool isHardScatterVertex_associated = (vtxAssociationType == noPuUtils::kChHSAssoc); - if (pfCandidatePtr->charge() == 0) - pfCandInfo.setType(reco::PUSubMETCandInfo::kNeutral); - else if (isHardScatterVertex_associated) - pfCandInfo.setType(reco::PUSubMETCandInfo::kChHS); - else - pfCandInfo.setType(reco::PUSubMETCandInfo::kChPU); - pfCandInfo.setIsWithinJet((pfCandidateFlags[idx] & flag_isWithinSelectedJet)); - if (pfCandInfo.isWithinJet()) - pfCandInfo.setPassesLooseJetId((pfCandidateFlags[idx] & flag_isWithinFakeJet)); - else - pfCandInfo.setPassesLooseJetId(true); - - // CV: for PFCandidates that are within PFJets (of Pt between 'minJetPtForMEtCov' and 'minJetPt'), - // take contribution to PFMEt significance matrix from associated PFJet. - // (energy uncertainty scaled by ratio of PFCandidate/PFJet energy) - const reco::PFJet* jet_matched = pfCandidateToJetAssociations[idx]; - if (jet_matched) { - metsig::SigInputObj pfCandResolution = pfMEtSignInterface_->compResolution(pfCandidatePtr.get()); - metsig::SigInputObj jetResolution = pfMEtSignInterface_->compResolution(jet_matched); - - metsig::SigInputObj metSign; - metSign.set(pfCandResolution.get_type(), - pfCandResolution.get_energy(), - pfCandResolution.get_phi(), - jetResolution.get_sigma_e() * (pfCandidatePtr->energy() / jet_matched->energy()), - jetResolution.get_sigma_tan()); - pfCandInfo.setMEtSignObj(metSign); - } else { - pfCandInfo.setMEtSignObj(pfMEtSignInterface_->compResolution(pfCandidatePtr.get())); - } - - pfCandInfos->push_back(pfCandInfo); - } - - LogDebug("produce") << "#pfCandInfos = " << pfCandInfos->size() << std::endl; - - evt.put(std::move(jetInfos), "jetInfos"); - evt.put(std::move(pfCandInfos), "pfCandInfos"); -} - -#include "FWCore/Framework/interface/MakerMacros.h" - -DEFINE_FWK_MODULE(NoPileUpPFMEtDataProducer); diff --git a/RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.h b/RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.h deleted file mode 100644 index 7d549955d7e6a..0000000000000 --- a/RecoMET/METPUSubtraction/plugins/NoPileUpPFMEtDataProducer.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef RecoMET_METPUSubtraction_NoPileUpPFMEtDataProducer_h -#define RecoMET_METPUSubtraction_NoPileUpPFMEtDataProducer_h - -/** \class NoPileUpPFMEtDataProducer - * - * Produce input objects used to compute MVA/No-PU MET - * - * \authors Phil Harris, CERN - * Christian Veelken, LLR - * - */ - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "PhysicsTools/SelectorUtils/interface/PFJetIDSelectionFunctor.h" -#include "DataFormats/JetReco/interface/PileupJetIdentifier.h" - -#include "RecoMET/METPUSubtraction/interface/PFMEtSignInterfaceBase.h" -#include "RecoMET/METPUSubtraction/interface/NoPileUpMEtAuxFunctions.h" - -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/Candidate/interface/CandidateFwd.h" -#include "DataFormats/JetReco/interface/PFJet.h" -#include "DataFormats/JetReco/interface/PFJetCollection.h" -#include "DataFormats/Common/interface/ValueMap.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" -#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" -#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/Common/interface/Handle.h" -#include "DataFormats/Math/interface/deltaR.h" -#include "DataFormats/METReco/interface/PUSubMETData.h" -#include "DataFormats/METReco/interface/PUSubMETDataFwd.h" -#include "DataFormats/METReco/interface/SigInputObj.h" //PH: preserve 5_3_x dependence - -class NoPileUpPFMEtDataProducer : public edm::stream::EDProducer<> { -public: - NoPileUpPFMEtDataProducer(const edm::ParameterSet&); - ~NoPileUpPFMEtDataProducer() override; - -private: - void produce(edm::Event&, const edm::EventSetup&) override; - - std::string moduleLabel_; - - edm::EDGetTokenT srcJets_; - edm::EDGetTokenT > srcJetIds_; - double minJetPt_; - PileupJetIdentifier::Id jetIdSelection_; - std::string jetEnOffsetCorrLabel_; - - edm::EDGetTokenT srcPFCandidates_; - edm::EDGetTokenT > srcPFCandidatesView_; - edm::EDGetTokenT srcPFCandToVertexAssociations_; - edm::EDGetTokenT srcJetsForMEtCov_; - double minJetPtForMEtCov_; - edm::EDGetTokenT srcHardScatterVertex_; - double dZcut_; - - PFJetIDSelectionFunctor* looseJetIdAlgo_; - - PFMEtSignInterfaceBase* pfMEtSignInterface_; - - int maxWarnings_; - int numWarnings_; - - int verbosity_; -}; - -#endif diff --git a/RecoMET/METPUSubtraction/python/mitigatedMETSequence_cff.py b/RecoMET/METPUSubtraction/python/mitigatedMETSequence_cff.py index d4a894a42bfa6..b66ccd10682a5 100644 --- a/RecoMET/METPUSubtraction/python/mitigatedMETSequence_cff.py +++ b/RecoMET/METPUSubtraction/python/mitigatedMETSequence_cff.py @@ -135,23 +135,6 @@ pfNoPUMEtTask.add(jvfJetIdForPFNoPUMEt) import RecoMET.METProducers.METSigParams_cfi as met_config -pfNoPUMEtData = cms.EDProducer("NoPileUpPFMEtDataProducer", - srcJets = cms.InputTag('calibratedAK4PFJetsForPFNoPUMEt'), - srcJetIds = cms.InputTag('puJetIdForPFNoPUMEt', 'full53xId'), - - minJetPt = cms.double(30.0), - jetIdSelection = cms.string('loose'), - jetEnOffsetCorrLabel = cms.string("ak4PFL1Fastjet"), - srcPFCandidates = cms.InputTag('particleFlow'), - srcPFCandToVertexAssociations = cms.InputTag('pfCandidateToVertexAssociationForPFNoPUMEt'), - srcJetsForMEtCov = cms.InputTag('ak4PFJets'), - minJetPtForMEtCov = cms.double(10.), - srcHardScatterVertex = cms.InputTag('selectedPrimaryVertexHighestPtTrackSumForPFMEtCorrType0'), - dZcut = cms.double(0.2), # cm - resolution = met_config.METSignificance_params, - verbosity = cms.int32(0) -) -pfNoPUMEtTask.add(pfNoPUMEtData) pfNoPUMEt = cms.EDProducer("NoPileUpPFMEtProducer", srcMEt = cms.InputTag('pfMet'), diff --git a/RecoMET/METPUSubtraction/python/pfNoPUMET_cff.py b/RecoMET/METPUSubtraction/python/pfNoPUMET_cff.py index 47226d2360257..ce33be9c55bb6 100644 --- a/RecoMET/METPUSubtraction/python/pfNoPUMET_cff.py +++ b/RecoMET/METPUSubtraction/python/pfNoPUMET_cff.py @@ -53,24 +53,6 @@ pfNoPUMEtTask.add(jvfJetIdForPFNoPUMEt) import RecoMET.METProducers.METSigParams_cfi as met_config -pfNoPUMEtData = cms.EDProducer("NoPileUpPFMEtDataProducer", - srcJets = cms.InputTag('calibratedAK4PFJetsForPFNoPUMEt'), - srcJetIds = cms.InputTag('puJetIdForPFNoPUMEt', 'full53xId'), - #srcJetIds = cms.InputTag('jvcJetIdForPFNoPUMEt', 'Id'), - minJetPt = cms.double(30.0), - jetIdSelection = cms.string('loose'), - jetEnOffsetCorrLabel = cms.string("ak4PFL1Fastjet"), - srcPFCandidates = cms.InputTag('particleFlow'), - srcPFCandToVertexAssociations = cms.InputTag('pfCandidateToVertexAssociationForPFNoPUMEt'), - srcJetsForMEtCov = cms.InputTag('ak4PFJets'), - minJetPtForMEtCov = cms.double(10.), - # minJetPtForMEtCov = cms.double(8.), # FOR TESTING ONLY !! - srcHardScatterVertex = cms.InputTag('selectedPrimaryVertexHighestPtTrackSumForPFMEtCorrType0'), - dZcut = cms.double(0.2), # cm - resolution = met_config.METSignificance_params, - verbosity = cms.int32(0) -) -pfNoPUMEtTask.add(pfNoPUMEtData) pfNoPUMEt = cms.EDProducer("NoPileUpPFMEtProducer", srcMEt = cms.InputTag('pfMet'),