CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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
3 
4 def makeRecoJetCollection(process,
5  pfCandCollection,
6  coneSize,
7  useCHSAlgo,
8  postfix):
9 
10  jetColName="ak"+str(int(coneSize*10))+"PFJets"
11  internalPfCandColl=pfCandCollection
12  if useCHSAlgo:
13  setattr( process, "tmpPFCandCollPtr"+postfix,
14  cms.EDProducer("PFCandidateFwdPtrProducer",
15  src = cms.InputTag(pfCandCollection) )
16  )
17  process.load("CommonTools.ParticleFlow.pfNoPileUpJME_cff")
18  cloneProcessingSnippet(process, getattr(process,"pfNoPileUpJMESequence"), postfix )
19  getattr(process, "pfPileUpJME"+postfix).PFCandidates = cms.InputTag("tmpPFCandCollPtr"+postfix)
20  getattr(process, "pfNoPileUpJME"+postfix).bottomCollection = cms.InputTag("tmpPFCandCollPtr"+postfix)
21 
22  internalPfCandColl = "pfNoPileUpJME"+postfix
23  jetColName+="CHS"
24 
25  setattr(process, jetColName+postfix, getattr(process,"ak4PFJets").clone(
26  src = cms.InputTag(internalPfCandColl),
27  rParam=cms.double(coneSize),
28  doAreaFastjet = True)
29  )
30 
31 
32 
33 def reduceInputJetCollection(process, jetCollection, badMuons):
34  label = jetCollection.label()
35  setattr(process, label+"AllEvents", jetCollection.clone())
36  process.globalReplace(label,
37  cms.EDProducer("PFJetCollectionReducer",
38  writeEmptyCollection = cms.bool(True),
39  jetCollection = cms.InputTag(label+"AllEvents"),
40  triggeringCollections=badMuons,
41  )
42  )
43 
44 def reduceFinalJetCollection(process, jetCollection, badMuons):
45  label = jetCollection.label()
46  setattr(process, label+"AllEvents", jetCollection.clone())
47  process.globalReplace(label,
48  cms.EDProducer("PATJetCollectionReducer",
49  writeEmptyCollection = cms.bool(False),
50  jetCollection = cms.InputTag(label+"AllEvents"),
51  triggeringCollections=badMuons,
52  )
53  )
54 
55 
56 def backupJetsFirstStep(process):
57  """Take snapshots of the sequences before we change the PFCandidates"""
58  process.originalAK4JetSequence = listDependencyChain(process, process.slimmedJets, ('particleFlow', 'muons'))
59  backupAK4JetSequence = cloneProcessingSnippet(process, process.originalAK4JetSequence, "Backup")
60  process.originalAK4PuppiJetSequence = listDependencyChain(process, process.slimmedJetsPuppi, ('particleFlow', 'muons'))
61  backupAK4PuppiJetSequence = cloneProcessingSnippet(process, process.originalAK4PuppiJetSequence, "Backup")
62  process.originalAK8JetSequence = listDependencyChain(process, process.slimmedJetsAK8, ('particleFlow', 'muons'))
63  backupAK8JetSequence = cloneProcessingSnippet(process, process.originalAK8JetSequence, "Backup")
64  return { 'AK4':backupAK4JetSequence, 'AK4Puppi':backupAK4PuppiJetSequence, 'AK8':backupAK8JetSequence }
65 
66 
67 def backupJetsSecondStep(process, sequences, badMuons, verbose=False):
68  """Deploy the snapshots after the change of PFCandidates"""
69  # put back the old input tags
70  for sequence in sequences.itervalues():
71  massSearchReplaceAnyInputTag(sequence, "pfCandidatesBadMuonsCleaned", "particleFlow")
72  massSearchReplaceAnyInputTag(sequence, "muonsCleaned", "muons")
73  # gate the input collections to avoid re-running most of PAT on good events
74  reduceInputJetCollection(process, process.ak4PFJetsCHSBackup, badMuons)
75  reduceInputJetCollection(process, process.ak4PFJetsPuppiBackup, badMuons)
76  # fix names in the valuemaps
77  process.patJetsBackup.userData.userInts.labelPostfixesToStrip = cms.vstring("Backup",)
78  process.patJetsBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
79  process.patJetsAK8Backup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
80  process.patJetsAK8PuppiBackup.userData.userFloats.labelPostfixesToStrip = cms.vstring("Backup",)
81  #
82  # now deal with daughter links
83  # for these we can keep the daughters
84  process.slimmedJetsBackup.mixedDaughters = True
85  process.slimmedJetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
86  process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.mixedDaughters = True
87  process.slimmedJetsAK8PFCHSSoftDropSubjetsBackup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
88  # for these we can't
89  process.slimmedJetsPuppiBackup.dropDaughters = '1'
90  process.slimmedJetsAK8PFPuppiSoftDropSubjetsBackup.dropDaughters = '1'
91  # for these we do even if we wouldn't have done in the standard case, since we couldn't for the subjets
92  process.packedPatJetsAK8Backup.fixDaughters = False
93  process.slimmedJetsAK8Backup.rekeyDaughters = '1'
94  process.slimmedJetsAK8Backup.mixedDaughters = True
95  process.slimmedJetsAK8Backup.packedPFCandidates = cms.InputTag("oldPFCandToPackedOrDiscarded")
96  #
97  reduceFinalJetCollection(process, process.slimmedJetsBackup, badMuons)
98  reduceFinalJetCollection(process, process.slimmedJetsPuppiBackup, badMuons)
99  reduceFinalJetCollection(process, process.slimmedJetsAK8Backup, badMuons)
100  #
101  addKeepStatement(process,
102  "keep *_slimmedJets_*_*",
103  ["keep *_slimmedJetsBackup_*_*"],
104  verbose=verbose)
105  addKeepStatement(process, "keep *_slimmedJetsPuppi_*_*",
106  ["keep *_slimmedJetsPuppiBackup_*_*"],
107  verbose=verbose)
108  addKeepStatement(process,
109  "keep *_slimmedJetsAK8_*_*",
110  ["keep *_slimmedJetsAK8Backup_*_*"],
111  verbose=verbose)
112  addKeepStatement(process,"keep *_slimmedJetsAK8PFCHSSoftDropPacked_SubJets_*",
113  ["keep *_slimmedJetsAK8PFCHSSoftDropPackedBackup_SubJets_*"],
114  verbose=verbose)
115  addKeepStatement(process,"keep *_slimmedJetsAK8PFPuppiSoftDropPacked_SubJets_*",
116  ["keep *_slimmedJetsAK8PFPuppiSoftDropPackedBackup_SubJets_*"],
117  verbose=verbose)
118 
119 
def listDependencyChain
Definition: helpers.py:330
def cloneProcessingSnippet
Definition: helpers.py:315
def massSearchReplaceAnyInputTag
Definition: helpers.py:271
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
def addKeepStatement
Definition: helpers.py:427