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 from PhysicsTools.PatAlgos.tools.helpers import listDependencyChain, massSearchReplaceAnyInputTag, cloneProcessingSnippet, addKeepStatement,listModules
0003 
0004 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0005 
0006 def makeRecoJetCollection(process, 
0007                           pfCandCollection,
0008                           coneSize,
0009                           useCHSAlgo,
0010                           postfix):
0011 
0012     task = getPatAlgosToolsTask(process)
0013 
0014     jetColName="ak"+str(int(coneSize*10))+"PFJets"
0015     internalPfCandColl=pfCandCollection
0016     if useCHSAlgo:
0017         addToProcessAndTask("tmpPFCandCollPtr"+postfix, 
0018                             cms.EDProducer("PFCandidateFwdPtrProducer",
0019                                 src = cms.InputTag(pfCandCollection) ),
0020                             process, task )
0021         process.load("CommonTools.ParticleFlow.pfNoPileUpJME_cff")
0022         task.add(process.pfNoPileUpJMETask)
0023         cloneProcessingSnippet(process, getattr(process,"pfNoPileUpJMESequence"), postfix, addToTask = True )
0024         getattr(process, "pfPileUpJME"+postfix).PFCandidates = cms.InputTag("tmpPFCandCollPtr"+postfix)
0025         getattr(process, "pfNoPileUpJME"+postfix).bottomCollection = cms.InputTag("tmpPFCandCollPtr"+postfix) 
0026         
0027         internalPfCandColl = "pfNoPileUpJME"+postfix
0028         jetColName+="CHS"
0029  
0030     addToProcessAndTask(jetColName+postfix,
0031                         getattr(process,jetColName).clone(
0032                             src = cms.InputTag(internalPfCandColl),
0033                             rParam=cms.double(coneSize),
0034                             doAreaFastjet = True),
0035                         process, task )
0036 
0037 def reduceInputJetCollection(process, jetCollection, badMuons):
0038 
0039     task = getPatAlgosToolsTask(process)
0040 
0041     label = jetCollection.label()
0042     addToProcessAndTask(label+"AllEvents",
0043                         jetCollection.clone(),
0044                         process, task )
0045     process.globalReplace(label,
0046             cms.EDProducer("PFJetCollectionReducer",
0047                            writeEmptyCollection = cms.bool(True),
0048                            jetCollection = cms.InputTag(label+"AllEvents"),
0049                            triggeringCollections=badMuons,
0050                            )
0051             )
0052 
0053 def reduceFinalJetCollection(process, jetCollection, badMuons):
0054 
0055     task = getPatAlgosToolsTask(process)
0056 
0057     label = jetCollection.label()
0058     addToProcessAndTask(label+"AllEvents",
0059                         jetCollection.clone(),
0060                         process, task )
0061     process.globalReplace(label,
0062             cms.EDProducer("PATJetCollectionReducer",
0063                            writeEmptyCollection = cms.bool(False),
0064                            jetCollection = cms.InputTag(label+"AllEvents"),
0065                            triggeringCollections=badMuons,
0066                            ) 
0067             )
0068     
0069 
0070 def backupJetsFirstStep(process):
0071 
0072     task = getPatAlgosToolsTask(process)
0073 
0074     """Take snapshots of the sequences before we change the PFCandidates"""
0075     process.originalAK4JetTask, process.originalAK4JetSequence = listDependencyChain(process, getattr(process,"slimmedJets"), ('particleFlow', 'muons'))
0076     backupAK4JetSequence = cloneProcessingSnippet(process, getattr(process,"originalAK4JetSequence"), "Backup", addToTask = True )
0077     process.originalAK4PuppiJetTask, process.originalAK4PuppiJetSequence = listDependencyChain(process,getattr(process,"slimmedJetsPuppi"), ('particleFlow', 'muons'))
0078     backupAK4PuppiJetSequence = cloneProcessingSnippet(process, getattr(process,"originalAK4PuppiJetSequence"), "Backup", addToTask = True )
0079     process.originalAK8JetTask,process.originalAK8JetSequence = listDependencyChain(process, getattr(process,"slimmedJetsAK8"), ('particleFlow', 'muons'))
0080     backupAK8JetSequence = cloneProcessingSnippet(process, getattr(process,"originalAK8JetSequence"), "Backup", addToTask = True )
0081 
0082     task.add(process.originalAK4JetTask)
0083     task.add(process.originalAK4PuppiJetTask)
0084     task.add(process.originalAK8JetTask)
0085 
0086     return { 'AK4':backupAK4JetSequence, 'AK4Puppi':backupAK4PuppiJetSequence, 'AK8':backupAK8JetSequence }
0087 
0088     
0089 def backupJetsSecondStep(process, sequences, badMuons, verbose=False):
0090     """Deploy the snapshots after the change of PFCandidates"""
0091 
0092     task = getPatAlgosToolsTask(process)
0093 
0094     # put back the old input tags and copy in task
0095     for sequence in sequences.values():
0096         massSearchReplaceAnyInputTag(sequence, "pfCandidatesBadMuonsCleaned", "particleFlow")
0097         massSearchReplaceAnyInputTag(sequence, "muonsCleaned", "muons")
0098         for mod in listModules(sequence):
0099             task.add(mod)
0100     # gate the input collections to avoid re-running most of PAT on good events
0101     reduceInputJetCollection(process, process.ak4PFJetsCHSBackup, badMuons)
0102     reduceInputJetCollection(process, process.ak4PFJetsPuppiBackup, badMuons)
0103     # fix names in the valuemaps
0104     process.patJetsBackup.userData.userInts.labelPostfixesToStrip = cms.vstring("Backup",)
0105     process.patJetsBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
0106     process.patJetsAK8Backup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
0107     process.patJetsAK8PuppiBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)    
0108     #
0109     # now deal with daughter links
0110     # for these we can keep the daughters
0111     if hasattr(process,"slimmedJetsBackup"):
0112         process.slimmedJetsBackup.mixedDaughters = True
0113         process.slimmedJetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
0114         process.packedPatJetsAK8Backup.fixDaughters = False
0115        #for this one the link is broken using oldPFCandToPackedOrDiscarded...
0116         #not sure why, but result is the same
0117         process.slimmedJetsAK8Backup.rekeyDaughters = '1'
0118         process.slimmedJetsAK8Backup.mixedDaughters = False
0119         process.slimmedJetsAK8Backup.packedPFCandidates = cms.InputTag("packedPFCandidatesBackup") #oldPFCandToPackedOrDiscarded
0120         reduceFinalJetCollection(process, process.slimmedJetsBackup, badMuons)
0121 
0122     if hasattr(process,"slimmedJetsAK8PFCHSSoftDropSubjetsBackup"):
0123         process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.mixedDaughters = True
0124         process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
0125         reduceFinalJetCollection(process, process.slimmedJetsAK8Backup, badMuons)
0126         #for this one the link is broken using oldPFCandToPackedOrDiscarded...
0127         #not sure why, but result is the same
0128         process.slimmedJetsAK8BackupAllEvents.packedPFCandidates = cms.InpuTag("packedPFCandidatesBackup")
0129 
0130     # for these we can't
0131     if hasattr(process,"slimmedJetsPuppiBackup"):
0132         process.slimmedJetsPuppiBackup.dropDaughters = '1'
0133         process.slimmedJetsAK8PFPuppiSoftDropSubjetsBackup.dropDaughters = '1'
0134         reduceFinalJetCollection(process, process.slimmedJetsPuppiBackup, badMuons)
0135   
0136     #
0137     addKeepStatement(process,
0138                      "keep *_slimmedJets_*_*",
0139                      ["keep *_slimmedJetsBackup_*_*"],
0140                      verbose=verbose)
0141     addKeepStatement(process, "keep *_slimmedJetsPuppi_*_*",
0142                      ["keep *_slimmedJetsPuppiBackup_*_*"],
0143                      verbose=verbose)
0144     addKeepStatement(process,
0145                      "keep *_slimmedJetsAK8_*_*",
0146                      ["keep *_slimmedJetsAK8Backup_*_*"],
0147                      verbose=verbose)
0148     addKeepStatement(process,"keep *_slimmedJetsAK8PFCHSSoftDropPacked_SubJets_*",
0149                      ["keep *_slimmedJetsAK8PFCHSSoftDropPackedBackup_SubJets_*"],
0150                      verbose=verbose)
0151     addKeepStatement(process,"keep *_slimmedJetsAK8PFPuppiSoftDropPacked_SubJets_*",
0152                      ["keep *_slimmedJetsAK8PFPuppiSoftDropPackedBackup_SubJets_*"],
0153                      verbose=verbose)
0154 
0155