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