def cleanPfCandidates(process, verbose=False): task = getPatAlgosToolsTask(process) #add producer at the beginning of the schedule process.load("CommonTools.ParticleFlow.pfCandidateRecalibrator_cfi") task.add(process.pfCandidateRecalibrator) replacePFCandidates = MassSearchReplaceAnyInputTagVisitor( "particleFlow", "pfCandidateRecalibrator", verbose=verbose) replacePFTmpPtrs = MassSearchReplaceAnyInputTagVisitor( "particleFlowTmpPtrs", "particleFlowPtrs", verbose=verbose) for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]: for name, obj in six.iteritems(everywhere): if obj != process.pfCandidateRecalibrator: replacePFCandidates.doIt(obj, name) replacePFTmpPtrs.doIt(obj, name) process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi") task.add(process.pfEGammaToCandidateRemapper) process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag( "pfCandidateRecalibrator") process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag( "pfEGammaToCandidateRemapper", "electrons") process.reducedEgamma.photonsPFValMap = cms.InputTag( "pfEGammaToCandidateRemapper", "photons")
def cleanPFCandidates(process, badMuons, verbose=False): process.load("CommonTools.ParticleFlow.muonsCleaned_cfi") process.patMuons.userData.userInts.src = [ cms.InputTag("muonsCleaned:oldPF") ] process.load("CommonTools.ParticleFlow.pfCandidatesBadMuonsCleaned_cfi") process.muonsCleaned.badmuons = badMuons replaceMuons = MassSearchReplaceAnyInputTagVisitor("muons", "muonsCleaned", verbose=verbose) needOriginalMuons = [ process.muonsCleaned ] + [ getattr(process,l.moduleLabel) for l in badMuons ] replacePFCandidates = MassSearchReplaceAnyInputTagVisitor("particleFlow", "pfCandidatesBadMuonsCleaned", verbose=verbose) for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]: for name,obj in everywhere.iteritems(): if obj not in needOriginalMuons: replaceMuons.doIt(obj, name) if obj != process.pfCandidatesBadMuonsCleaned: replacePFCandidates.doIt(obj, name) process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi") process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag("pfCandidatesBadMuonsCleaned") process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","electrons") process.reducedEgamma.photonsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","photons") if hasattr(process,"gedGsfElectronsGSFixed"): # also reconfigure pfEGammaToCandidateRemapper because of GS Fix # first the old one process.pfEGammaToCandidateRemapperBeforeGSFix = process.pfEGammaToCandidateRemapper.clone() process.reducedEgammaBeforeGSFix.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapperBeforeGSFix","electrons") process.reducedEgammaBeforeGSFix.photonsPFValMap = cms.InputTag("pfEGammaToCandidateRemapperBeforeGSFix","photons") # then the new one process.pfEGammaToCandidateRemapper.electrons = cms.InputTag("gedGsfElectronsGSFixed") process.pfEGammaToCandidateRemapper.photons = cms.InputTag("gedPhotonsGSFixed") process.pfEGammaToCandidateRemapper.electron2pf = cms.InputTag("particleBasedIsolationGSFixed","gedGsfElectrons") process.pfEGammaToCandidateRemapper.photon2pf = cms.InputTag("particleBasedIsolationGSFixed","gedPhotons")
def cleanPFCandidates(process, badMuons, verbose=False): process.load("CommonTools.ParticleFlow.muonsCleaned_cfi") process.patMuons.userData.userInts.src = [ cms.InputTag("muonsCleaned:oldPF") ] process.load("CommonTools.ParticleFlow.pfCandidatesBadMuonsCleaned_cfi") process.muonsCleaned.badmuons = badMuons replaceMuons = MassSearchReplaceAnyInputTagVisitor("muons", "muonsCleaned", verbose=verbose) needOriginalMuons = [process.muonsCleaned] + [ getattr(process, l.moduleLabel) for l in badMuons ] replacePFCandidates = MassSearchReplaceAnyInputTagVisitor( "particleFlow", "pfCandidatesBadMuonsCleaned", verbose=verbose) for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]: for name, obj in everywhere.iteritems(): if obj not in needOriginalMuons: replaceMuons.doIt(obj, name) if obj != process.pfCandidatesBadMuonsCleaned: replacePFCandidates.doIt(obj, name) process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi") process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag( "pfCandidatesBadMuonsCleaned") process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag( "pfEGammaToCandidateRemapper", "electrons") process.reducedEgamma.photonsPFValMap = cms.InputTag( "pfEGammaToCandidateRemapper", "photons") if hasattr(process, "gedGsfElectronsGSFixed"): # also reconfigure pfEGammaToCandidateRemapper because of GS Fix # first the old one process.pfEGammaToCandidateRemapperBeforeGSFix = process.pfEGammaToCandidateRemapper.clone( ) process.reducedEgammaBeforeGSFix.gsfElectronsPFValMap = cms.InputTag( "pfEGammaToCandidateRemapperBeforeGSFix", "electrons") process.reducedEgammaBeforeGSFix.photonsPFValMap = cms.InputTag( "pfEGammaToCandidateRemapperBeforeGSFix", "photons") # then the new one process.pfEGammaToCandidateRemapper.electrons = cms.InputTag( "gedGsfElectronsGSFixed") process.pfEGammaToCandidateRemapper.photons = cms.InputTag( "gedPhotonsGSFixed") process.pfEGammaToCandidateRemapper.electron2pf = cms.InputTag( "particleBasedIsolationGSFixed", "gedGsfElectrons") process.pfEGammaToCandidateRemapper.photon2pf = cms.InputTag( "particleBasedIsolationGSFixed", "gedPhotons")
def cleanPfCandidates(process, verbose=False): task = getPatAlgosToolsTask(process) #add producer at the beginning of the schedule process.load("CommonTools.ParticleFlow.pfCandidateRecalibrator_cfi") task.add(process.pfCandidateRecalibrator) replacePFCandidates = MassSearchReplaceAnyInputTagVisitor("particleFlow", "pfCandidateRecalibrator", verbose=verbose) replacePFTmpPtrs = MassSearchReplaceAnyInputTagVisitor("particleFlowTmpPtrs", "particleFlowPtrs", verbose=verbose) for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]: for name,obj in everywhere.iteritems(): if obj != process.pfCandidateRecalibrator: replacePFCandidates.doIt(obj, name) replacePFTmpPtrs.doIt(obj, name) process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi") task.add(process.pfEGammaToCandidateRemapper) process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag("pfCandidateRecalibrator") process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","electrons") process.reducedEgamma.photonsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","photons")
def cleanPFCandidates(process, badMuons, verbose=False): task = getPatAlgosToolsTask(process) process.load("CommonTools.ParticleFlow.muonsCleaned_cfi") task.add(process.muonsCleaned) process.patMuons.userData.userInts.src = [ cms.InputTag("muonsCleaned:oldPF") ] process.load("CommonTools.ParticleFlow.pfCandidatesBadMuonsCleaned_cfi") task.add(process.pfCandidatesBadMuonsCleaned) process.muonsCleaned.badmuons = badMuons replaceMuons = MassSearchReplaceAnyInputTagVisitor("muons", "muonsCleaned", verbose=verbose) needOriginalMuons = [ process.muonsCleaned ] + [ getattr(process,l.moduleLabel) for l in badMuons ] replacePFCandidates = MassSearchReplaceAnyInputTagVisitor("particleFlow", "pfCandidatesBadMuonsCleaned", verbose=verbose) for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]: for name,obj in six.iteritems(everywhere): if obj not in needOriginalMuons: replaceMuons.doIt(obj, name) if obj != process.pfCandidatesBadMuonsCleaned: replacePFCandidates.doIt(obj, name) process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi") task.add(process.pfEGammaToCandidateRemapper) process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag("pfCandidatesBadMuonsCleaned") process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","electrons") process.reducedEgamma.photonsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","photons") if hasattr(process,"gedGsfElectronsFixed"): # also reconfigure pfEGammaToCandidateRemapper because of GS Fix # first the old one process.pfEGammaToCandidateRemapperBeforeGSFix = process.pfEGammaToCandidateRemapper.clone() task.add(process.pfEGammaToCandidateRemapperBeforeGSFix) process.reducedEgammaBeforeGSFix.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapperBeforeGSFix","electrons") process.reducedEgammaBeforeGSFix.photonsPFValMap = cms.InputTag("pfEGammaToCandidateRemapperBeforeGSFix","photons") # then the new one process.pfEGammaToCandidateRemapper.electrons = cms.InputTag("gedGsfElectronsFixed") process.pfEGammaToCandidateRemapper.photons = cms.InputTag("gedPhotonsFixed") process.pfEGammaToCandidateRemapper.electron2pf = cms.InputTag("particleBasedIsolationGSFixed","gedGsfElectrons") process.pfEGammaToCandidateRemapper.photon2pf = cms.InputTag("particleBasedIsolationGSFixed","gedPhotons") else: sys.stderr.write("WARNING : attempt to use gain switch corrected electron/photon collection gedGsfElectronsFixed, but the current process does not contain such collection")
else: ### PF CLEANING (BAD MUON REMOVAL) # Replace all references made so far to packedPFCandidates with cleanMuonsPFCandidates from PhysicsTools.PatAlgos.tools.helpers import MassSearchReplaceAnyInputTagVisitor replacePFCandidates = MassSearchReplaceAnyInputTagVisitor( 'packedPFCandidates', 'cleanMuonsPFCandidates', verbose=False) for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]: for name, obj in everywhere.iteritems(): replacePFCandidates.doIt(obj, name) from PhysicsTools.PatUtils.tools.muonRecoMitigation import muonRecoMitigation # Adds badGlobalMuonTaggerMAOD, cloneGlobalMuonTaggerMAOD, badMuons, and cleanMuonsPFCandidates muonRecoMitigation(process, pfCandCollection='packedPFCandidates', runOnMiniAOD=True) # And of course this is against the convention (MET filters are true if event is *good*) but that's what the REMINIAOD developers chose. process.Flag_badMuons = cms.Path(process.badGlobalMuonTaggerMAOD) process.Flag_duplicateMuons = cms.Path(process.cloneGlobalMuonTaggerMAOD) process.schedule += [process.Flag_badMuons, process.Flag_duplicateMuons] pfCleaningSequence = cms.Sequence(process.badMuons + process.cleanMuonsPFCandidates)