Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:54

0001 import FWCore.ParameterSet.Config as cms
0002 
0003 from PhysicsTools.PatAlgos.tools.helpers import MassSearchReplaceAnyInputTagVisitor, cloneProcessingSnippet, addKeepStatement
0004 from PhysicsTools.PatAlgos.slimming.extraJets_MuEGFixMoriond2017 import backupJetsFirstStep, backupJetsSecondStep
0005 #from RecoEgamma.EgammaTools.egammaGainSwitchFixToolsForPAT_cff import customizeGSFixForPAT
0006 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0007 import sys
0008 
0009 def addBadMuonFilters(process):
0010 
0011     task = getPatAlgosToolsTask(process)
0012 
0013     process.load("RecoMET.METFilters.badGlobalMuonTaggersAOD_cff")
0014     task.add(process.badGlobalMuonTagger)
0015     task.add(process.cloneGlobalMuonTagger)
0016     process.Flag_noBadMuons = cms.Path(process.noBadGlobalMuons)
0017     process.Flag_badMuons = cms.Path(process.badGlobalMuonTagger)
0018     process.Flag_duplicateMuons = cms.Path(process.cloneGlobalMuonTagger)
0019     for P in process.Flag_noBadMuons, process.Flag_badMuons, process.Flag_duplicateMuons:
0020         process.schedule.insert(0, P)
0021 
0022 def cleanPFCandidates(process, badMuons, verbose=False):
0023 
0024     task = getPatAlgosToolsTask(process)
0025 
0026     process.load("CommonTools.ParticleFlow.muonsCleaned_cfi")
0027     task.add(process.muonsCleaned)
0028     process.patMuons.userData.userInts.src = [ cms.InputTag("muonsCleaned:oldPF") ]
0029 
0030     process.load("CommonTools.ParticleFlow.pfCandidatesBadMuonsCleaned_cfi")
0031     task.add(process.pfCandidatesBadMuonsCleaned)
0032     process.muonsCleaned.badmuons = badMuons
0033     replaceMuons = MassSearchReplaceAnyInputTagVisitor("muons", "muonsCleaned", verbose=verbose)
0034     needOriginalMuons = [ process.muonsCleaned ] + [ getattr(process,l.moduleLabel) for l in badMuons ]
0035     replacePFCandidates = MassSearchReplaceAnyInputTagVisitor("particleFlow", "pfCandidatesBadMuonsCleaned", verbose=verbose)
0036     for everywhere in [ process.producers, process.filters, process.analyzers, process.psets, process.vpsets ]:
0037         for name,obj in everywhere.items():
0038             if obj not in needOriginalMuons:
0039                 replaceMuons.doIt(obj, name)
0040             if obj != process.pfCandidatesBadMuonsCleaned: 
0041                 replacePFCandidates.doIt(obj, name)
0042             
0043     process.load("CommonTools.ParticleFlow.pfEGammaToCandidateRemapper_cfi")
0044     task.add(process.pfEGammaToCandidateRemapper)
0045     process.pfEGammaToCandidateRemapper.pf2pf = cms.InputTag("pfCandidatesBadMuonsCleaned")
0046     process.reducedEgamma.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapper","electrons")
0047     process.reducedEgamma.photonsPFValMap      = cms.InputTag("pfEGammaToCandidateRemapper","photons")
0048     if hasattr(process,"gedGsfElectronsFixed"):
0049         # also reconfigure pfEGammaToCandidateRemapper because of GS Fix
0050         # first the old one
0051         process.pfEGammaToCandidateRemapperBeforeGSFix = process.pfEGammaToCandidateRemapper.clone()
0052         task.add(process.pfEGammaToCandidateRemapperBeforeGSFix)
0053         process.reducedEgammaBeforeGSFix.gsfElectronsPFValMap = cms.InputTag("pfEGammaToCandidateRemapperBeforeGSFix","electrons")
0054         process.reducedEgammaBeforeGSFix.photonsPFValMap      = cms.InputTag("pfEGammaToCandidateRemapperBeforeGSFix","photons")
0055         # then the new one
0056         process.pfEGammaToCandidateRemapper.electrons = cms.InputTag("gedGsfElectronsFixed")
0057         process.pfEGammaToCandidateRemapper.photons   = cms.InputTag("gedPhotonsFixed")
0058         process.pfEGammaToCandidateRemapper.electron2pf = cms.InputTag("particleBasedIsolationGSFixed","gedGsfElectrons")
0059         process.pfEGammaToCandidateRemapper.photon2pf   = cms.InputTag("particleBasedIsolationGSFixed","gedPhotons")
0060     else:
0061         sys.stderr.write("WARNING : attempt to use gain switch corrected electron/photon collection gedGsfElectronsFixed, but the current process does not contain such collection")
0062 
0063 def addDiscardedPFCandidates(process, inputCollection, verbose=False):
0064 
0065     task = getPatAlgosToolsTask(process)
0066 
0067     process.primaryVertexAssociationDiscardedCandidates = process.primaryVertexAssociation.clone(
0068         particles = inputCollection,
0069         )
0070     task.add(process.primaryVertexAssociationDiscardedCandidates)
0071     process.packedPFCandidatesDiscarded = process.packedPFCandidates.clone(
0072         inputCollection = inputCollection,
0073         PuppiNoLepSrc = cms.InputTag(""),
0074         PuppiSrc = cms.InputTag(""),
0075         secondaryVerticesForWhiteList = cms.VInputTag(),
0076         vertexAssociator = cms.InputTag("primaryVertexAssociationDiscardedCandidates","original")
0077         )
0078     task.add(process.packedPFCandidatesDiscarded)
0079     addKeepStatement(process, "keep patPackedCandidates_packedPFCandidates_*_*",
0080                              ["keep patPackedCandidates_packedPFCandidatesDiscarded_*_*"],
0081                               verbose=verbose)
0082     # Now make the mixed map for rekeying
0083     from PhysicsTools.PatAlgos.slimming.packedPFCandidateRefMixer_cfi import packedPFCandidateRefMixer
0084     process.oldPFCandToPackedOrDiscarded = packedPFCandidateRefMixer.clone(
0085         pf2pf = cms.InputTag(inputCollection.moduleLabel),
0086         pf2packed = cms.VInputTag(cms.InputTag("packedPFCandidates"), cms.InputTag("packedPFCandidatesDiscarded"))
0087     )
0088     task.add(process.oldPFCandToPackedOrDiscarded)
0089     # Fix slimmed muon keying
0090     process.slimmedMuons.pfCandidates = cms.VInputTag(cms.InputTag(inputCollection.moduleLabel), inputCollection)
0091     process.slimmedMuons.packedPFCandidates = cms.VInputTag(cms.InputTag("packedPFCandidates"), cms.InputTag("packedPFCandidatesDiscarded"))
0092   
0093     #MM point to uncleaned collection for hadronic taus, to avoid remaking them
0094     #no impact expected, as no muons are included here
0095     process.slimmedTaus.packedPFCandidates=cms.InputTag("packedPFCandidatesBackup")
0096 
0097 def loadJetMETBTag(process):
0098 
0099     task = getPatAlgosToolsTask(process)
0100 
0101     import RecoJets.Configuration.RecoPFJets_cff
0102     process.ak4PFJetsCHS = RecoJets.Configuration.RecoPFJets_cff.ak4PFJetsCHS.clone()
0103     task.add(process.ak4PFJetsCHS)
0104     process.ak8PFJetsCHS = RecoJets.Configuration.RecoPFJets_cff.ak8PFJetsCHS.clone()
0105     task.add(process.ak8PFJetsCHS)
0106     process.load("RecoMET.METProducers.pfMet_cfi")
0107     task.add(process.pfMet)
0108     process.load("RecoBTag.ImpactParameter.impactParameter_cff")
0109     task.add(process.impactParameterTask)
0110     process.load("RecoBTag.SecondaryVertex.secondaryVertex_cff")
0111     task.add(process.secondaryVertexTask)
0112     process.load("RecoBTag.SoftLepton.softLepton_cff")
0113     task.add(process.softLeptonTask)
0114     process.load("RecoBTag.Combined.combinedMVA_cff")
0115     task.add(process.combinedMVATask)
0116     process.load("RecoBTag.CTagging.cTagging_cff")
0117     task.add(process.cTaggingTask)
0118     process.load("RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff")
0119     task.add(process.inclusiveVertexingTask)
0120     task.add(process.inclusiveCandidateVertexingTask)
0121     task.add(process.inclusiveCandidateVertexingCvsLTask)
0122 
0123 def customizeAll(process, verbose=False):
0124     
0125     #disabled for now, backup in case 90X needs similar fix
0126     #process = customizeGSFixForPAT(process)
0127 
0128     loadJetMETBTag(process)
0129     backupJetSequences = backupJetsFirstStep(process)
0130 
0131     addBadMuonFilters(process)    
0132     badMuons = cms.VInputTag( cms.InputTag("badGlobalMuonTagger","bad"), cms.InputTag("cloneGlobalMuonTagger","bad") )
0133     # clean the muons and PF candidates, and make *everything* point to the new candidates
0134     cleanPFCandidates(process, badMuons, verbose=verbose) 
0135 
0136     addDiscardedPFCandidates(process, cms.InputTag("pfCandidatesBadMuonsCleaned","discarded"), verbose=verbose)
0137 
0138     # now make the backup sequences point to the right place
0139     backupJetsSecondStep(process, backupJetSequences, badMuons, verbose=verbose)
0140 
0141     
0142     process.patMuons.embedCaloMETMuonCorrs = False # FIXME
0143     ##extra METs and MET corrections ===============================================================
0144     from PhysicsTools.PatAlgos.slimming.extraSlimmedMETs_MuEGFixMoriond2017 import addExtraMETCollections,addExtraPuppiMETCorrections
0145     
0146     ### Gain switch collections not existing in 90X+ 
0147     ### -> corrections are set up to give no change on the MET computation
0148     addExtraMETCollections(process,
0149                            unCleanPFCandidateCollection="particleFlow",
0150                            cleanElectronCollection="slimmedElectrons",
0151                            cleanPhotonCollection="slimmedPhotons",
0152                            unCleanElectronCollection="slimmedElectrons",
0153                            unCleanPhotonCollection="slimmedPhotons")
0154     
0155     addExtraPuppiMETCorrections(process,
0156                                 cleanPFCandidateCollection="particleFlow",
0157                                 unCleanPFCandidateCollection="pfCandidatesBadMuonsCleaned",
0158                                 cleanElectronCollection="slimmedElectrons",
0159                                 cleanPhotonCollection="slimmedPhotons",
0160                                 unCleanElectronCollection="slimmedElectrons",
0161                                 unCleanPhotonCollection="slimmedPhotons")
0162 
0163     addKeepStatement(process,
0164                      "keep *_slimmedMETs_*_*",
0165                      ["keep *_slimmedMETsUncorrected_*_*",
0166                       "keep *_slimmedMETsEGClean_*_*",
0167                       "keep *_slimmedMETsMuEGClean_*_*"],
0168                      verbose=verbose)
0169     addKeepStatement(process,
0170                      "keep *_slimmedMETsPuppi_*_*",
0171                      ["keep *_puppiMETEGCor_*_*",
0172                       "keep *_puppiMETMuCor_*_*"],
0173                      verbose=verbose)
0174 
0175 
0176 
0177     #redo the miniAOD data customization for new JEC modules created during the backup process
0178     from PhysicsTools.PatAlgos.slimming.miniAOD_tools import miniAOD_customizeData
0179     miniAOD_customizeData(process)
0180 
0181     return process