diff --git a/CommonTools/PileupAlgos/interface/PuppiContainer.h b/CommonTools/PileupAlgos/interface/PuppiContainer.h index 644343d5ba7f9..0c5df114bffa6 100644 --- a/CommonTools/PileupAlgos/interface/PuppiContainer.h +++ b/CommonTools/PileupAlgos/interface/PuppiContainer.h @@ -76,6 +76,7 @@ class PuppiContainer{ double fNeutralMinPt; double fNeutralSlope; double fPuppiWeightCut; + double fPtMax; int fNAlgos; int fNPV; double fPVFrac; diff --git a/CommonTools/PileupAlgos/plugins/PuppiPhoton.cc b/CommonTools/PileupAlgos/plugins/PuppiPhoton.cc index ba6587e61aea5..e341f5d36c0a7 100644 --- a/CommonTools/PileupAlgos/plugins/PuppiPhoton.cc +++ b/CommonTools/PileupAlgos/plugins/PuppiPhoton.cc @@ -30,9 +30,19 @@ PuppiPhoton::PuppiPhoton(const edm::ParameterSet& iConfig) { tokenPFCandidates_ = consumes(iConfig.getParameter("candName")); tokenPuppiCandidates_ = consumes(iConfig.getParameter("puppiCandName")); - tokenPhotonCandidates_ = consumes(iConfig.getParameter("photonName")); - reco2pf_ = mayConsume > >(iConfig.getParameter("recoToPFMap")); - tokenPhotonId_ = mayConsume >(iConfig.getParameter("photonId")); + usePFphotons_ = iConfig.getParameter("usePFphotons"); + if(!usePFphotons_) + tokenPhotonCandidates_ = consumes(iConfig.getParameter("photonName")); + usePhotonId_ = (iConfig.getParameter("photonId")).label().size() != 0; + if(usePhotonId_) + tokenPhotonId_ = consumes >(iConfig.getParameter("photonId")); + runOnMiniAOD_ = iConfig.getParameter("runOnMiniAOD"); + if(!runOnMiniAOD_) + reco2pf_ = consumes > >(iConfig.getParameter("recoToPFMap")); + useValueMap_ = iConfig.getParameter("useValueMap"); + if(useValueMap_) + tokenWeights_ = consumes >(iConfig.getParameter("weightsName")); + pt_ = iConfig.getParameter("pt"); eta_ = iConfig.getParameter("eta"); dRMatch_ = iConfig.getParameter > ("dRMatch"); @@ -51,13 +61,6 @@ PuppiPhoton::PuppiPhoton(const edm::ParameterSet& iConfig) { PuppiPhoton::~PuppiPhoton(){} // ------------------------------------------------------------------------------------------ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - - edm::Handle hPhoProduct; - iEvent.getByToken(tokenPhotonCandidates_,hPhoProduct); - const CandidateView *phoCol = hPhoProduct.product(); - - edm::Handle > photonId; - if(usePhotonId_) iEvent.getByToken(tokenPhotonId_,photonId); int iC = -1; std::vector phoCands; std::vector phoIndx; @@ -73,7 +76,25 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { edm::Handle hPuppiProduct; iEvent.getByToken(tokenPuppiCandidates_,hPuppiProduct); const CandidateView *pupCol = hPuppiProduct.product(); - for(CandidateView::const_iterator itPho = phoCol->begin(); itPho!=phoCol->end(); itPho++) { + if(usePFphotons_) { + for(const auto & pho : *pfCol) { + iC++; + if(pho.pt() < pt_) continue; + if(std::abs(pho.pdgId())!=22) continue; + if(fabs(pho.eta()) < eta_ ) { + phoIndx.push_back(iC); + phoCands.push_back(&pho); + } + } + } else { + edm::Handle hPhoProduct; + iEvent.getByToken(tokenPhotonCandidates_,hPhoProduct); + const CandidateView *phoCol = hPhoProduct.product(); + + edm::Handle > photonId; + if(usePhotonId_) iEvent.getByToken(tokenPhotonId_,photonId); + + for(CandidateView::const_iterator itPho = phoCol->begin(); itPho!=phoCol->end(); itPho++) { iC++; bool passObject = false; if(itPho->isPhoton() && usePhotonId_) passObject = (*photonId) [phoCol->ptrAt(iC)]; @@ -106,6 +127,7 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { } } } + } } //Get Weights edm::Handle > pupWeights; @@ -182,6 +204,7 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { } // ------------------------------------------------------------------------------------------ bool PuppiPhoton::matchPFCandidate(const reco::Candidate *iPF,const reco::Candidate *iPho) { + if(iPF->pdgId() != iPho->pdgId()) return false; double lDR = deltaR(iPF->eta(),iPF->phi(),iPho->eta(),iPho->phi()); for(unsigned int i0 = 0; i0 < pdgIds_.size(); i0++) { if(std::abs(iPF->pdgId()) == pdgIds_[i0] && lDR < dRMatch_[i0]) return true; diff --git a/CommonTools/PileupAlgos/plugins/PuppiPhoton.h b/CommonTools/PileupAlgos/plugins/PuppiPhoton.h index 9a65d3a352234..a8b8852433048 100644 --- a/CommonTools/PileupAlgos/plugins/PuppiPhoton.h +++ b/CommonTools/PileupAlgos/plugins/PuppiPhoton.h @@ -40,6 +40,7 @@ class PuppiPhoton : public edm::stream::EDProducer<> { double pt_; double eta_; bool usePFRef_; + bool usePFphotons_; bool runOnMiniAOD_; bool usePhotonId_; std::vector dRMatch_; diff --git a/CommonTools/PileupAlgos/plugins/PuppiProducer.cc b/CommonTools/PileupAlgos/plugins/PuppiProducer.cc index 3376ba914cd6c..60326842cb8d0 100644 --- a/CommonTools/PileupAlgos/plugins/PuppiProducer.cc +++ b/CommonTools/PileupAlgos/plugins/PuppiProducer.cc @@ -33,6 +33,7 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) { fPuppiForLeptons = iConfig.getParameter("puppiForLeptons"); fUseDZ = iConfig.getParameter("UseDeltaZCut"); fDZCut = iConfig.getParameter("DeltaZCut"); + fPtMax = iConfig.getParameter("PtMaxNeutrals"); fUseExistingWeights = iConfig.getParameter("useExistingWeights"); fUseWeightsNoLep = iConfig.getParameter("useWeightsNoLep"); fClonePackedCands = iConfig.getParameter("clonePackedCands"); diff --git a/CommonTools/PileupAlgos/plugins/PuppiProducer.h b/CommonTools/PileupAlgos/plugins/PuppiProducer.h index 84aecffbe1003..575d49bf3116f 100644 --- a/CommonTools/PileupAlgos/plugins/PuppiProducer.h +++ b/CommonTools/PileupAlgos/plugins/PuppiProducer.h @@ -51,6 +51,7 @@ class PuppiProducer : public edm::stream::EDProducer<> { bool fPuppiForLeptons; bool fUseDZ; float fDZCut; + float fPtMax; bool fUseExistingWeights; bool fUseWeightsNoLep; bool fClonePackedCands; diff --git a/CommonTools/PileupAlgos/python/PhotonPuppi_cff.py b/CommonTools/PileupAlgos/python/PhotonPuppi_cff.py index 1631e61bed4bf..589d719e95d8b 100644 --- a/CommonTools/PileupAlgos/python/PhotonPuppi_cff.py +++ b/CommonTools/PileupAlgos/python/PhotonPuppi_cff.py @@ -4,12 +4,13 @@ puppiPhoton = cms.EDProducer("PuppiPhoton", candName = cms.InputTag('particleFlow'), puppiCandName = cms.InputTag('puppi'), + usePFphotons = cms.bool(True), # Use PF photons and not GED photons photonName = cms.InputTag('reducedEgamma','reducedGedPhotons'), - recoToPFMap = cms.InputTag("reducedEgamma","reducedPhotonPfCandMap"), - photonId = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring15-25ns-V1-standalone-loose"), - pt = cms.double(10), + recoToPFMap = cms.InputTag("reducedEgamma","reducedPhotonPfCandMap"), + photonId = cms.InputTag(""), + pt = cms.double(20), eta = cms.double(2.5), - runOnMiniAOD = cms.bool(False), + runOnMiniAOD = cms.bool(False), # If set to true photon ID is taken from pat::Photon, otherwise from the value map at RECO/AOD level useRefs = cms.bool(True), dRMatch = cms.vdouble(0.005,0.005,0.005,0.005), pdgids = cms.vint32 (22,11,211,130), @@ -20,14 +21,14 @@ def setupPuppiPhoton(process): - my_id_modules = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_25ns_V1_cff'] + my_id_modules = [] # Add photon ID used by puppiPhoton producer here switchOnVIDPhotonIdProducer(process, DataFormat.AOD) for idmod in my_id_modules: setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection) def setupPuppiPhotonMiniAOD(process): - my_id_modules = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_25ns_V1_cff'] + my_id_modules = [] # Add photon ID used by puppiPhoton producer here switchOnVIDPhotonIdProducer(process, DataFormat.MiniAOD) for idmod in my_id_modules: setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection) diff --git a/CommonTools/PileupAlgos/python/Puppi_cff.py b/CommonTools/PileupAlgos/python/Puppi_cff.py index 2ea8db93760f5..2c944000ec733 100644 --- a/CommonTools/PileupAlgos/python/Puppi_cff.py +++ b/CommonTools/PileupAlgos/python/Puppi_cff.py @@ -29,6 +29,7 @@ puppiForLeptons = cms.bool(False), UseDeltaZCut = cms.bool(True), DeltaZCut = cms.double(0.3), + PtMaxNeutrals = cms.double(200.), candName = cms.InputTag('particleFlow'), vertexName = cms.InputTag('offlinePrimaryVertices'), #candName = cms.string('packedPFCandidates'), diff --git a/CommonTools/PileupAlgos/src/PuppiContainer.cc b/CommonTools/PileupAlgos/src/PuppiContainer.cc index 70ce26fb1d383..ccf1e101fbaef 100644 --- a/CommonTools/PileupAlgos/src/PuppiContainer.cc +++ b/CommonTools/PileupAlgos/src/PuppiContainer.cc @@ -18,6 +18,7 @@ PuppiContainer::PuppiContainer(const edm::ParameterSet &iConfig) { fInvert = iConfig.getParameter("invertPuppi"); fUseExp = iConfig.getParameter("useExp"); fPuppiWeightCut = iConfig.getParameter("MinPuppiWeight"); + fPtMax = iConfig.getParameter("PtMaxNeutrals"); std::vector lAlgos = iConfig.getParameter >("algos"); fNAlgos = lAlgos.size(); for(unsigned int i0 = 0; i0 < lAlgos.size(); i0++) { @@ -262,6 +263,7 @@ std::vector const & PuppiContainer::puppiWeights() { if(pWeight*fPFParticles[i0].pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && fRecoParticles[i0].id == 0 ) pWeight = 0; //threshold cut on the neutral Pt if(fInvert) pWeight = 1.-pWeight; //std::cout << "fRecoParticles[i0].pt = " << fRecoParticles[i0].pt << ", fRecoParticles[i0].charge = " << fRecoParticles[i0].charge << ", fRecoParticles[i0].id = " << fRecoParticles[i0].id << ", weight = " << pWeight << std::endl; + if((fPtMax>0) && (fRecoParticles[i0].id == 0)) pWeight=min(max(pWeight,fPFParticles[i0].pt()/fPtMax),1.); fWeights .push_back(pWeight); fAlphaMed.push_back(fPuppiAlgo[pPupId].median());