File indexing completed on 2024-11-27 03:18:00
0001 import FWCore.ParameterSet.Config as cms
0002
0003 from PhysicsTools.PatAlgos.tools.ConfigToolBase import *
0004
0005
0006 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0007
0008 def eGammaCorrection(process,
0009 electronCollection,
0010 photonCollection,
0011 corElectronCollection,
0012 corPhotonCollection,
0013 metCollections,
0014 pfCandMatching=False,
0015 pfCandidateCollection="",
0016
0017 corMetName="corEGSlimmedMET",
0018 postfix=""
0019 ):
0020
0021 task = getPatAlgosToolsTask(process)
0022
0023 process.load("PhysicsTools.PatAlgos.cleaningLayer1.photonCleaner_cfi")
0024 task.add(process.cleanPatPhotons)
0025
0026 cleanedPhotonCollection="cleanedPhotons"+postfix
0027 cleanPhotonProducer = getattr(process, "cleanPatPhotons").clone(
0028 src = photonCollection,
0029
0030 )
0031 cleanPhotonProducer.checkOverlaps.electrons.src = electronCollection
0032 cleanPhotonProducer.checkOverlaps.electrons.requireNoOverlaps=cms.bool(True)
0033
0034
0035 cleanedCorPhotonCollection="cleanedCorPhotons"+postfix
0036 cleanCorPhotonProducer = getattr(process, "cleanPatPhotons").clone(
0037 src = corPhotonCollection
0038 )
0039 cleanCorPhotonProducer.checkOverlaps.electrons.src = corElectronCollection
0040 cleanCorPhotonProducer.checkOverlaps.electrons.requireNoOverlaps=cms.bool(True)
0041
0042
0043
0044 matchPhotonCollection="matchedPhotons"+postfix
0045 matchPhotonProducer=cms.EDProducer("PFMatchedCandidateRefExtractor",
0046 col1=cms.InputTag(cleanedPhotonCollection),
0047 col2=cms.InputTag(cleanedCorPhotonCollection),
0048 pfCandCollection=cms.InputTag(pfCandidateCollection),
0049 extractPFCandidates=cms.bool(pfCandMatching) )
0050
0051 matchElectronCollection="matchedElectrons"+postfix
0052 matchElectronProducer=cms.EDProducer("PFMatchedCandidateRefExtractor",
0053 col1=cms.InputTag(electronCollection),
0054 col2=cms.InputTag(corElectronCollection),
0055 pfCandCollection=cms.InputTag(pfCandidateCollection),
0056 extractPFCandidates=cms.bool(pfCandMatching) )
0057
0058
0059
0060 tag1= "pfCandCol1" if pfCandMatching else "col1"
0061 tag2= "pfCandCol2" if pfCandMatching else "col2"
0062 correctionPhoton="corMETPhoton"+postfix
0063 corMETPhoton = cms.EDProducer("ShiftedParticleMETcorrInputProducer",
0064 srcOriginal = cms.InputTag(matchPhotonCollection,tag1),
0065 srcShifted = cms.InputTag(matchPhotonCollection,tag2),
0066 srcWeights = cms.InputTag("")
0067 )
0068 correctionElectron="corMETElectron"+postfix
0069 corMETElectron=cms.EDProducer("ShiftedParticleMETcorrInputProducer",
0070 srcOriginal=cms.InputTag(matchElectronCollection,tag1),
0071 srcShifted=cms.InputTag(matchElectronCollection,tag2),
0072 srcWeights = cms.InputTag("")
0073 )
0074
0075
0076 addToProcessAndTask(cleanedPhotonCollection,cleanPhotonProducer, process, task)
0077 addToProcessAndTask(cleanedCorPhotonCollection,cleanCorPhotonProducer, process, task)
0078 addToProcessAndTask(matchPhotonCollection,matchPhotonProducer, process, task)
0079 addToProcessAndTask(matchElectronCollection,matchElectronProducer, process, task)
0080 addToProcessAndTask(correctionPhoton,corMETPhoton, process, task)
0081 addToProcessAndTask(correctionElectron,corMETElectron, process, task)
0082
0083 sequence=cms.Sequence()
0084 sequence+=getattr(process,cleanedPhotonCollection)
0085 sequence+=getattr(process,cleanedCorPhotonCollection)
0086 sequence+=getattr(process,correctionPhoton)
0087 sequence+=getattr(process,correctionElectron)
0088
0089
0090
0091
0092 for metCollection in metCollections:
0093
0094 if not hasattr(process, metCollection+postfix):
0095
0096
0097 inputMetCollection=metCollection.replace("Raw","",1)
0098 corMETModuleName=corMetName+postfix
0099 corMETModule = cms.EDProducer("CorrectedPATMETProducer",
0100 src = cms.InputTag( inputMetCollection ),
0101
0102 srcCorrections = cms.VInputTag( cms.InputTag(correctionPhoton),
0103 cms.InputTag(correctionElectron),
0104 )
0105 )
0106 addToProcessAndTask(metCollection+postfix, corMETModule, process, task)
0107 sequence+=getattr(process,metCollection+postfix)
0108 else:
0109 print(metCollection)
0110 getattr(process,metCollection).srcCorrections.append(cms.InputTag(correctionPhoton))
0111 getattr(process,metCollection).srcCorrections.append(cms.InputTag(correctionElectron))
0112
0113 return sequence