Skip to content

Commit

Permalink
updated the Puppi Photon code to not necessarily rely on references a…
Browse files Browse the repository at this point in the history
…nd rather do a delta R matching to the candidates. This allows for use on Reco and and Puppi NoLepton collections without directly relying on the references to fix things. This is a result of studies which show that using the collection puppiMerged or the reco Puppi candidates breaks the use of referene keys to link things making Delta R the only option. The reco code is thus updated with what should be the BEST puppi MET version. However the validated version consists of commenting out the puppiMerged line. This pull request follows the equivalent 81X verision cms-sw#15669
  • Loading branch information
violatingcp committed Sep 8, 2016
1 parent 7c77baa commit 0b8cf50
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
20 changes: 13 additions & 7 deletions CommonTools/PileupAlgos/plugins/PuppiPhoton.cc
Expand Up @@ -74,12 +74,12 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
if(itPho->isPhoton() && usePhotonId_) passObject = (*photonId) [phoCol->ptrAt(iC)];
if(itPho->pt() < pt_) continue;
if(!passObject && usePhotonId_) continue;
if(!usePFRef_ && fabs(itPho->eta()) < eta_) phoCands.push_back(&(*itPho));
if(!usePFRef_) continue;
//if(!usePFRef_ && fabs(itPho->eta()) < eta_) phoCands.push_back(&(*itPho)); ===> should add a flag useAODRef_ in place of usePFRef_
//if(!usePFRef_) continue;
const pat::Photon *pPho = dynamic_cast<const pat::Photon*>(&(*itPho));
if(pPho != 0) {
for( const edm::Ref<pat::PackedCandidateCollection> & ref : pPho->associatedPackedPFCandidates() ) {
if(matchPFCandidate(&(*(pfCol->ptrAt(ref.key()))),&(*itPho)) && fabs(pfCol->ptrAt(ref.key())->eta()) < eta_ ) {
if(fabs(pfCol->ptrAt(ref.key())->eta()) < eta_ ) {
phoIndx.push_back(ref.key());
phoCands.push_back(&(*(pfCol->ptrAt(ref.key()))));
}
Expand All @@ -89,7 +89,7 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
const pat::Electron *pElectron = dynamic_cast<const pat::Electron*>(&(*itPho));
if(pElectron != 0) {
for( const edm::Ref<pat::PackedCandidateCollection> & ref : pElectron->associatedPackedPFCandidates() )
if(matchPFCandidate(&(*(pfCol->ptrAt(ref.key()))),&(*itPho)) && fabs(pfCol->ptrAt(ref.key())->eta()) < eta_ ) {
if(fabs(pfCol->ptrAt(ref.key())->eta()) < eta_ ) {
phoIndx.push_back(ref.key());
phoCands.push_back(&(*(pfCol->ptrAt(ref.key()))));
}
Expand All @@ -114,8 +114,14 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
float pWeight = 1.;
if(useValueMap_) pWeight = (*pupWeights)[pupCol->ptrAt(iPF)];
if(!usePFRef_) {
int iPho = -1;
for(std::vector<const reco::Candidate*>::iterator itPho = phoCands.begin(); itPho!=phoCands.end(); itPho++) {
if(matchPFCandidate(&(*itPF),*itPho)) pWeight = weight_;
iPho++;
if(!matchPFCandidate(&(*itPF),*itPho)) continue;
pWeight = weight_;
if(!useValueMap_ && itPF->pt() != 0) pWeight = pWeight*(phoCands[iPho]->pt()/itPF->pt());
if(!useValueMap_ && itPF->pt() == 0) pVec.SetPxPyPzE(phoCands[iPho]->px()*pWeight,phoCands[iPho]->py()*pWeight,phoCands[iPho]->pz()*pWeight,phoCands[iPho]->energy()*pWeight);
foundPhoIndex.push_back(iPho);
}
} else {
int iPho = -1;
Expand All @@ -125,9 +131,9 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
pWeight = weight_;
if(!useValueMap_ && itPF->pt() != 0) pWeight = pWeight*(phoCands[iPho]->pt()/itPF->pt());
if(!useValueMap_ && itPF->pt() == 0) pVec.SetPxPyPzE(phoCands[iPho]->px()*pWeight,phoCands[iPho]->py()*pWeight,phoCands[iPho]->pz()*pWeight,phoCands[iPho]->energy()*pWeight);
foundPhoIndex.push_back(iPho); }
foundPhoIndex.push_back(iPho);
}
}

if(itPF->pt() != 0) pVec.SetPxPyPzE(itPF->px()*pWeight,itPF->py()*pWeight,itPF->pz()*pWeight,itPF->energy()*pWeight);

lWeights.push_back(pWeight);
Expand Down
9 changes: 8 additions & 1 deletion CommonTools/PileupAlgos/python/PhotonPuppi_cff.py
Expand Up @@ -9,7 +9,7 @@
pt = cms.double(10),
eta = cms.double(2.5),
useRefs = cms.bool(True),
dRMatch = cms.vdouble(10,10,10,10),
dRMatch = cms.vdouble(0.005,0.005,0.005,0.005),
pdgids = cms.vint32 (22,11,211,130),
weight = cms.double(1.),
useValueMap = cms.bool(False),
Expand All @@ -18,6 +18,13 @@


def setupPuppiPhoton(process):
my_id_modules = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_25ns_V1_cff']
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']
switchOnVIDPhotonIdProducer(process, DataFormat.MiniAOD)
for idmod in my_id_modules:
Expand Down
21 changes: 12 additions & 9 deletions PhysicsTools/PatAlgos/python/slimming/puppiForMET_cff.py
@@ -1,12 +1,12 @@
import FWCore.ParameterSet.Config as cms

from CommonTools.PileupAlgos.Puppi_cff import *
from CommonTools.PileupAlgos.PhotonPuppi_cff import setupPuppiPhoton
from CommonTools.PileupAlgos.PhotonPuppi_cff import setupPuppiPhoton,setupPuppiPhotonMiniAOD

def makePuppies( process ):

process.load('CommonTools.PileupAlgos.Puppi_cff')

process.pfNoLepPUPPI = cms.EDFilter("PdgIdCandViewSelector",
src = cms.InputTag("particleFlow"),
pdgId = cms.vint32( 1,2,22,111,130,310,2112,211,-211,321,-321,999211,2212,-2212 )
Expand All @@ -15,14 +15,16 @@ def makePuppies( process ):
src = cms.InputTag("particleFlow"),
pdgId = cms.vint32(-11,11,-13,13),
)

process.puppiNoLep = process.puppi.clone()
process.puppiNoLep.candName = cms.InputTag('pfNoLepPUPPI')

process.puppiMerged = cms.EDProducer("CandViewMerger",src = cms.VInputTag( 'puppiNoLep','pfLeptonsPUPPET'))
process.load('CommonTools.PileupAlgos.PhotonPuppi_cff')
process.puppiForMET = process.puppiPhoton.clone()
#process.puppiForMET.puppiCandName = 'puppiMerged'

#Line below replaces reference linking wiht delta R matching this is because the reference key in packed candidates differs to PF candidates (must be done when reading Reco)
process.puppiForMET.useRefs = False
#Line below points puppi MET to puppi no lepton which increases the response
process.puppiForMET.puppiCandName = 'puppiMerged'


def makePuppiesFromMiniAOD( process ):
Expand All @@ -37,7 +39,8 @@ def makePuppiesFromMiniAOD( process ):
process.puppiMerged = cms.EDProducer("CandViewMerger",src = cms.VInputTag( 'puppiNoLep','pfLeptonsPUPPET'))
process.load('CommonTools.PileupAlgos.PhotonPuppi_cff')
process.puppiForMET = process.puppiPhoton.clone()
setupPuppiPhoton(process)
#Line below doesn't work because of an issue with references in MiniAOD
setupPuppiPhotonMiniAOD(process)
#Line below doesn't work because of an issue with references in MiniAOD without setting useRefs=>False and using delta R
#process.puppiForMET.puppiCandName = 'puppiMerged'

#process.puppiForMET.useRefs = False

0 comments on commit 0b8cf50

Please sign in to comment.