Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:01

0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag,cloneProcessingSnippet,addKeepStatement
0003 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0004 
0005 def addExtraMETCollections(process, unCleanPFCandidateCollection,
0006                            cleanElectronCollection,
0007                            cleanPhotonCollection,
0008                            unCleanElectronCollection,
0009                            unCleanPhotonCollection ):
0010 
0011     task = getPatAlgosToolsTask(process)
0012 
0013     # Muon/EGamma un/corrected pfMET ============
0014     from PhysicsTools.PatUtils.tools.corMETFromMuonAndEG import corMETFromMuonAndEG
0015     from PhysicsTools.PatUtils.tools.runMETCorrectionsAndUncertainties import runMetCorAndUncForMiniAODProduction
0016     
0017     # uncorrected MET
0018     cloneProcessingSnippet(process, getattr(process,"makePatJets"),"BackupAllEvents", addToTask = True )
0019     massSearchReplaceAnyInputTag(getattr(process,"makePatJetsBackupAllEvents"), "ak4PFJetsCHS", "ak4PFJetsCHSBackupAllEvents")
0020     massSearchReplaceAnyInputTag(getattr(process,"makePatJetsBackupAllEvents"), "pfCandidatesBadMuonsCleaned", "particleFlow")
0021     del process.patJetsBackupAllEvents.userData
0022     process.patJetsBackupAllEvents.addAssociatedTracks = cms.bool(False)
0023     process.patJetsBackupAllEvents.addBTagInfo = cms.bool(False)
0024     process.patJetsBackupAllEvents.addDiscriminators = cms.bool(False)
0025     process.patJetsBackupAllEvents.addGenJetMatch = cms.bool(False)
0026     process.patJetsBackupAllEvents.addGenPartonMatch = cms.bool(False)
0027     process.patJetsBackupAllEvents.addJetCharge = cms.bool(False)
0028     process.patJetsBackupAllEvents.addJetCorrFactors = cms.bool(True)
0029     process.patJetsBackupAllEvents.addJetFlavourInfo = cms.bool(False)
0030     process.patJetsBackupAllEvents.addJetID = cms.bool(False)
0031     process.patJetsBackupAllEvents.addPartonJetMatch = cms.bool(False)
0032     process.patJetsBackupAllEvents.addResolutions = cms.bool(False)
0033     process.patJetsBackupAllEvents.addTagInfos = cms.bool(False)
0034     process.patJetsBackupAllEvents.discriminatorSources = cms.VInputTag()
0035     process.patJetsBackupAllEvents.embedGenJetMatch = cms.bool(False)
0036   
0037     runMetCorAndUncForMiniAODProduction(process,
0038                                         metType="PF",
0039                                         pfCandColl=cms.InputTag(unCleanPFCandidateCollection),
0040                                         recoMetFromPFCs=True,
0041                                         jetCollUnskimmed="patJetsBackupAllEvents",
0042                                         postfix="Uncorrected"
0043                                         )
0044 
0045     if not hasattr(process, "slimmedMETs"):
0046         process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0047         
0048     process.slimmedMETsUncorrected = process.slimmedMETs.clone()
0049     task.add(process.slimmedMETs)
0050     process.slimmedMETsUncorrected.src = cms.InputTag("patPFMetT1Uncorrected")
0051     process.slimmedMETsUncorrected.rawVariation =  cms.InputTag("patPFMetUncorrected")
0052     process.slimmedMETsUncorrected.t1Uncertainties = cms.InputTag("patPFMetT1%sUncorrected") 
0053     process.slimmedMETsUncorrected.t01Variation = cms.InputTag("patPFMetT0pcT1Uncorrected")
0054     process.slimmedMETsUncorrected.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sUncorrected")
0055     process.slimmedMETsUncorrected.tXYUncForRaw = cms.InputTag("patPFMetTxyUncorrected")
0056     process.slimmedMETsUncorrected.tXYUncForT1 = cms.InputTag("patPFMetT1TxyUncorrected")
0057     process.slimmedMETsUncorrected.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyUncorrected")
0058     process.slimmedMETsUncorrected.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyUncorrected")
0059     process.slimmedMETsUncorrected.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyUncorrected")
0060     del process.slimmedMETsUncorrected.caloMET
0061     
0062     # EG corrected MET
0063     corMETFromMuonAndEG(process,
0064                         pfCandCollection="", #not needed
0065                         electronCollection=unCleanElectronCollection,
0066                         photonCollection=unCleanPhotonCollection,
0067                         corElectronCollection=cleanElectronCollection,
0068                         corPhotonCollection=cleanPhotonCollection,
0069                         allMETEGCorrected=True,
0070                         muCorrection=False,
0071                         eGCorrection=True,
0072                         runOnMiniAOD=False,
0073                         eGPFix="Uncorrected",
0074                         postfix="EGOnly"
0075                         )
0076     process.slimmedMETsEGClean = process.slimmedMETs.clone()
0077     task.add(process.slimmedMETsEGClean)
0078     process.slimmedMETsEGClean.src = cms.InputTag("patPFMetT1UncorrectedEGOnly")
0079     process.slimmedMETsEGClean.rawVariation =  cms.InputTag("patPFMetRawUncorrectedEGOnly")
0080     process.slimmedMETsEGClean.t1Uncertainties = cms.InputTag("patPFMetT1%sUncorrectedEGOnly") 
0081     process.slimmedMETsEGClean.t01Variation = cms.InputTag("patPFMetT0pcT1UncorrectedEGOnly")
0082     process.slimmedMETsEGClean.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sUncorrectedEGOnly")
0083     process.slimmedMETsEGClean.tXYUncForRaw = cms.InputTag("patPFMetTxyUncorrectedEGOnly")
0084     process.slimmedMETsEGClean.tXYUncForT1 = cms.InputTag("patPFMetT1TxyUncorrectedEGOnly")
0085     process.slimmedMETsEGClean.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyUncorrectedEGOnly")
0086     process.slimmedMETsEGClean.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyUncorrectedEGOnly")
0087     process.slimmedMETsEGClean.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyUncorrectedEGOnly")
0088     del process.slimmedMETsEGClean.caloMET
0089  
0090     # fully corrected MET
0091     corMETFromMuonAndEG(process,
0092                         pfCandCollection="", #not needed
0093                         electronCollection=unCleanElectronCollection,
0094                         photonCollection=unCleanPhotonCollection,
0095                         corElectronCollection=cleanElectronCollection,
0096                         corPhotonCollection=cleanPhotonCollection,
0097                         allMETEGCorrected=True,
0098                         muCorrection=False,
0099                         eGCorrection=True,
0100                         runOnMiniAOD=False,
0101                         postfix="MuEGClean"
0102                         )
0103     process.slimmedMETsMuEGClean = process.slimmedMETs.clone()
0104     task.add(process.slimmedMETsMuEGClean)
0105     process.slimmedMETsMuEGClean.src = cms.InputTag("patPFMetT1MuEGClean")
0106     process.slimmedMETsMuEGClean.rawVariation =  cms.InputTag("patPFMetRawMuEGClean")
0107     process.slimmedMETsMuEGClean.t1Uncertainties = cms.InputTag("patPFMetT1%sMuEGClean") 
0108     process.slimmedMETsMuEGClean.t01Variation = cms.InputTag("patPFMetT0pcT1MuEGClean")
0109     process.slimmedMETsMuEGClean.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sMuEGClean")
0110     process.slimmedMETsMuEGClean.tXYUncForRaw = cms.InputTag("patPFMetTxyMuEGClean")
0111     process.slimmedMETsMuEGClean.tXYUncForT1 = cms.InputTag("patPFMetT1TxyMuEGClean")
0112     process.slimmedMETsMuEGClean.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyMuEGClean")
0113     process.slimmedMETsMuEGClean.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyMuEGClean")
0114     process.slimmedMETsMuEGClean.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyMuEGClean")
0115     del process.slimmedMETsMuEGClean.caloMET
0116 
0117     addKeepStatement(process, "keep *_slimmedMETs_*_*",
0118                     ["keep *_slimmedMETsUncorrected_*_*", "keep *_slimmedMETsEGClean_*_*", "keep *_slimmedMETsMuEGClean_*_*"])
0119 
0120     
0121 
0122 def addExtraPuppiMETCorrections(process,
0123                                 cleanPFCandidateCollection,
0124                                 unCleanPFCandidateCollection,
0125                                 cleanElectronCollection,
0126                                 cleanPhotonCollection,
0127                                 unCleanElectronCollection,
0128                                 unCleanPhotonCollection
0129                                 ):
0130 
0131     task = getPatAlgosToolsTask(process)
0132 
0133     from PhysicsTools.PatUtils.tools.corMETFromMuonAndEG import corMETFromMuonAndEG
0134     #EG correction for puppi, muon correction done right above
0135     corMETFromMuonAndEG(process,
0136                         metType="Puppi",
0137                         electronCollection=unCleanElectronCollection,
0138                         photonCollection=unCleanPhotonCollection,
0139                         corElectronCollection=cleanElectronCollection,
0140                         corPhotonCollection=cleanPhotonCollection,
0141                         allMETEGCorrected=True,
0142                         muCorrection=False,
0143                         eGCorrection=True,
0144                         runOnMiniAOD=False,
0145                         eGPfCandMatching=True,
0146                         eGPFix="Puppi",
0147                         postfix="PuppiClean"
0148                         )
0149 
0150     if not hasattr(process, "slimmedMETs"):
0151         process.load('PhysicsTools.PatAlgos.slimming.slimmedMETs_cfi')
0152         task.add(process.slimmedMETs)
0153 
0154     process.slimmedMETsPuppi.src = cms.InputTag("patPFMetT1PuppiPuppiClean")
0155     process.slimmedMETsPuppi.rawVariation =  cms.InputTag("patPFMetRawPuppiPuppiClean")
0156     process.slimmedMETsPuppi.t1Uncertainties = cms.InputTag("patPFMetT1%sPuppiPuppiClean")
0157     process.slimmedMETsPuppi.t01Variation = cms.InputTag("patPFMetT0pcT1PuppiPuppiClean")
0158     process.slimmedMETsPuppi.t1SmearedVarsAndUncs = cms.InputTag("patPFMetT1Smear%sPuppiPuppiClean")
0159     process.slimmedMETsPuppi.tXYUncForRaw = cms.InputTag("patPFMetTxyPuppiPuppiClean")
0160     process.slimmedMETsPuppi.tXYUncForT1 = cms.InputTag("patPFMetT1TxyPuppiPuppiClean")
0161     process.slimmedMETsPuppi.tXYUncForT01 = cms.InputTag("patPFMetT0pcT1TxyPuppiPuppiClean")
0162     process.slimmedMETsPuppi.tXYUncForT1Smear = cms.InputTag("patPFMetT1SmearTxyPuppiPuppiClean")
0163     process.slimmedMETsPuppi.tXYUncForT01Smear = cms.InputTag("patPFMetT0pcT1SmearTxyPuppiPuppiClean")
0164     #del process.slimmedMETsPuppi.caloMET    
0165 
0166     #EGamma correction
0167     process.puppiMETEGCor = cms.EDProducer("CorrMETDataExtractor",
0168                     corrections = cms.VInputTag(
0169                         cms.InputTag("corMETPhotonPuppiClean"),
0170                         cms.InputTag("corMETElectronPuppiClean") )
0171                                            )
0172     task.add(process.puppiMETEGCor)
0173 
0174     #Muon correction, restarting from PF candidates to take the weights
0175     process.puppiMuonCorrection = cms.EDProducer("ShiftedParticleMETcorrInputProducer",
0176                         srcOriginal = cms.InputTag(unCleanPFCandidateCollection),
0177                         srcShifted = cms.InputTag(cleanPFCandidateCollection),
0178                         srcWeights = cms.InputTag("")
0179                                   )
0180 
0181     task.add(process.puppiMuonCorrection)
0182 
0183     process.puppiMETMuCor = cms.EDProducer("CorrMETDataExtractor",
0184                     corrections = cms.VInputTag(
0185                         cms.InputTag("puppiMuonCorrection") )
0186                                            )
0187     task.add(process.puppiMETMuCor)
0188     addKeepStatement(process, "keep *_slimmedMETsPuppi_*_*",
0189                     ["keep *_puppiMETEGCor_*_*", "keep *_puppiMETMuCor_*_*"])