CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
extraJets_MuEGFixMoriond2017.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 from PhysicsTools.PatAlgos.tools.helpers import listDependencyChain, massSearchReplaceAnyInputTag, cloneProcessingSnippet, addKeepStatement,listModules
3 
4 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
5 
6 def makeRecoJetCollection(process,
7  pfCandCollection,
8  coneSize,
9  useCHSAlgo,
10  postfix):
11 
12  task = getPatAlgosToolsTask(process)
13 
14  jetColName="ak"+str(int(coneSize*10))+"PFJets"
15  internalPfCandColl=pfCandCollection
16  if useCHSAlgo:
17  addToProcessAndTask("tmpPFCandCollPtr"+postfix,
18  cms.EDProducer("PFCandidateFwdPtrProducer",
19  src = cms.InputTag(pfCandCollection) ),
20  process, task )
21  process.load("CommonTools.ParticleFlow.pfNoPileUpJME_cff")
22  task.add(process.pfNoPileUpJMETask)
23  cloneProcessingSnippet(process, getattr(process,"pfNoPileUpJMESequence"), postfix, addToTask = True )
24  getattr(process, "pfPileUpJME"+postfix).PFCandidates = cms.InputTag("tmpPFCandCollPtr"+postfix)
25  getattr(process, "pfNoPileUpJME"+postfix).bottomCollection = cms.InputTag("tmpPFCandCollPtr"+postfix)
26 
27  internalPfCandColl = "pfNoPileUpJME"+postfix
28  jetColName+="CHS"
29 
30  addToProcessAndTask(jetColName+postfix,
31  getattr(process,jetColName).clone(
32  src = cms.InputTag(internalPfCandColl),
33  rParam=cms.double(coneSize),
34  doAreaFastjet = True),
35  process, task )
36 
37 def reduceInputJetCollection(process, jetCollection, badMuons):
38 
39  task = getPatAlgosToolsTask(process)
40 
41  label = jetCollection.label()
42  addToProcessAndTask(label+"AllEvents",
43  jetCollection.clone(),
44  process, task )
45  process.globalReplace(label,
46  cms.EDProducer("PFJetCollectionReducer",
47  writeEmptyCollection = cms.bool(True),
48  jetCollection = cms.InputTag(label+"AllEvents"),
49  triggeringCollections=badMuons,
50  )
51  )
52 
53 def reduceFinalJetCollection(process, jetCollection, badMuons):
54 
55  task = getPatAlgosToolsTask(process)
56 
57  label = jetCollection.label()
58  addToProcessAndTask(label+"AllEvents",
59  jetCollection.clone(),
60  process, task )
61  process.globalReplace(label,
62  cms.EDProducer("PATJetCollectionReducer",
63  writeEmptyCollection = cms.bool(False),
64  jetCollection = cms.InputTag(label+"AllEvents"),
65  triggeringCollections=badMuons,
66  )
67  )
68 
69 
70 def backupJetsFirstStep(process):
71 
72  task = getPatAlgosToolsTask(process)
73 
74  """Take snapshots of the sequences before we change the PFCandidates"""
75  process.originalAK4JetTask, process.originalAK4JetSequence = listDependencyChain(process, getattr(process,"slimmedJets"), ('particleFlow', 'muons'))
76  backupAK4JetSequence = cloneProcessingSnippet(process, getattr(process,"originalAK4JetSequence"), "Backup", addToTask = True )
77  process.originalAK4PuppiJetTask, process.originalAK4PuppiJetSequence = listDependencyChain(process,getattr(process,"slimmedJetsPuppi"), ('particleFlow', 'muons'))
78  backupAK4PuppiJetSequence = cloneProcessingSnippet(process, getattr(process,"originalAK4PuppiJetSequence"), "Backup", addToTask = True )
79  process.originalAK8JetTask,process.originalAK8JetSequence = listDependencyChain(process, getattr(process,"slimmedJetsAK8"), ('particleFlow', 'muons'))
80  backupAK8JetSequence = cloneProcessingSnippet(process, getattr(process,"originalAK8JetSequence"), "Backup", addToTask = True )
81 
82  task.add(process.originalAK4JetTask)
83  task.add(process.originalAK4PuppiJetTask)
84  task.add(process.originalAK8JetTask)
85 
86  return { 'AK4':backupAK4JetSequence, 'AK4Puppi':backupAK4PuppiJetSequence, 'AK8':backupAK8JetSequence }
87 
88 
89 def backupJetsSecondStep(process, sequences, badMuons, verbose=False):
90  """Deploy the snapshots after the change of PFCandidates"""
91 
92  task = getPatAlgosToolsTask(process)
93 
94  # put back the old input tags and copy in task
95  for sequence in sequences.values():
96  massSearchReplaceAnyInputTag(sequence, "pfCandidatesBadMuonsCleaned", "particleFlow")
97  massSearchReplaceAnyInputTag(sequence, "muonsCleaned", "muons")
98  for mod in listModules(sequence):
99  task.add(mod)
100  # gate the input collections to avoid re-running most of PAT on good events
101  reduceInputJetCollection(process, process.ak4PFJetsCHSBackup, badMuons)
102  reduceInputJetCollection(process, process.ak4PFJetsPuppiBackup, badMuons)
103  # fix names in the valuemaps
104  process.patJetsBackup.userData.userInts.labelPostfixesToStrip = cms.vstring("Backup",)
105  process.patJetsBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
106  process.patJetsAK8Backup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
107  process.patJetsAK8PuppiBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
108  #
109  # now deal with daughter links
110  # for these we can keep the daughters
111  if hasattr(process,"slimmedJetsBackup"):
112  process.slimmedJetsBackup.mixedDaughters = True
113  process.slimmedJetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
114  process.packedPatJetsAK8Backup.fixDaughters = False
115  #for this one the link is broken using oldPFCandToPackedOrDiscarded...
116  #not sure why, but result is the same
117  process.slimmedJetsAK8Backup.rekeyDaughters = '1'
118  process.slimmedJetsAK8Backup.mixedDaughters = False
119  process.slimmedJetsAK8Backup.packedPFCandidates = cms.InputTag("packedPFCandidatesBackup") #oldPFCandToPackedOrDiscarded
120  reduceFinalJetCollection(process, process.slimmedJetsBackup, badMuons)
121 
122  if hasattr(process,"slimmedJetsAK8PFCHSSoftDropSubjetsBackup"):
123  process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.mixedDaughters = True
124  process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
125  reduceFinalJetCollection(process, process.slimmedJetsAK8Backup, badMuons)
126  #for this one the link is broken using oldPFCandToPackedOrDiscarded...
127  #not sure why, but result is the same
128  process.slimmedJetsAK8BackupAllEvents.packedPFCandidates = cms.InpuTag("packedPFCandidatesBackup")
129 
130  # for these we can't
131  if hasattr(process,"slimmedJetsPuppiBackup"):
132  process.slimmedJetsPuppiBackup.dropDaughters = '1'
133  process.slimmedJetsAK8PFPuppiSoftDropSubjetsBackup.dropDaughters = '1'
134  reduceFinalJetCollection(process, process.slimmedJetsPuppiBackup, badMuons)
135 
136  #
137  addKeepStatement(process,
138  "keep *_slimmedJets_*_*",
139  ["keep *_slimmedJetsBackup_*_*"],
140  verbose=verbose)
141  addKeepStatement(process, "keep *_slimmedJetsPuppi_*_*",
142  ["keep *_slimmedJetsPuppiBackup_*_*"],
143  verbose=verbose)
144  addKeepStatement(process,
145  "keep *_slimmedJetsAK8_*_*",
146  ["keep *_slimmedJetsAK8Backup_*_*"],
147  verbose=verbose)
148  addKeepStatement(process,"keep *_slimmedJetsAK8PFCHSSoftDropPacked_SubJets_*",
149  ["keep *_slimmedJetsAK8PFCHSSoftDropPackedBackup_SubJets_*"],
150  verbose=verbose)
151  addKeepStatement(process,"keep *_slimmedJetsAK8PFPuppiSoftDropPacked_SubJets_*",
152  ["keep *_slimmedJetsAK8PFPuppiSoftDropPackedBackup_SubJets_*"],
153  verbose=verbose)
154 
155 
def listModules
Definition: helpers.py:207
def listDependencyChain
Definition: helpers.py:272
def cloneProcessingSnippet
Definition: helpers.py:257
def getPatAlgosToolsTask
Definition: helpers.py:13
def massSearchReplaceAnyInputTag
Definition: MassReplace.py:79
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addKeepStatement
Definition: helpers.py:354
#define str(s)
def addToProcessAndTask
Definition: helpers.py:28