ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/additionalFiles/jetTools.py
Revision: 1.3
Committed: Wed May 9 19:53:55 2012 UTC (12 years, 11 months ago) by arizzi
Content type: text/x-python
Branch: MAIN
CVS Tags: EDMV42_Step2_V6, EDMV42_Step2_V5a, EDMV42_Step2_V5, tauCandV42, hbbsubstructDev_11, hbbsubstructDev_10, hbbsubstructDev_9, hbbsubstructDev_8, hbbsubstructDev_7, hbbsubstructDev_6, hbbsubstructDev_5, hbbsubstructDev_4, hbbsubstructDev_3, hbbsubstructDev_2, hbbsubstructDev_1, hbbsubstructDev, EDMV42_Step2_V4a, EDMV42_Step2_V4, EDMV42_Step2_V3, EDMV42_Step2_V2, EDMV42_Step2_V1, EdmV42, EdmV41alpha1, EdmV40alpha1, EdmV40alpha, EdmV33Jun12v2_consistent, Step2ForV33_v2, Step2ForV33_v1, EdmV33Jun12v2, EdmV33Jun12v1, EdmV33Jun12v0, Step2ForV32_v0, Step2ForV31_v0, EdmV32May24v0, EdmV31May21v1, EdmV31May17v0, May14thStep2, EdmV30Apr10, EdmV21Apr10v2, HEAD
Branch point for: V42TauCandidate, hbbsubstructDevPostHCP
Changes since 1.2: +489 -152 lines
Log Message:
add new taggers also to switch jet collection

File Contents

# Content
1 from FWCore.GuiBrowsers.ConfigToolBase import *
2
3 from PhysicsTools.PatAlgos.tools.helpers import *
4
5
6 class RunBTagging(ConfigToolBase):
7
8 """ Define sequence to run b tagging on AOD input for a given jet
9 collection including a JetTracksAssociatorAtVertex module with
10 name 'jetTracksAssociatorAtVertex' + 'label'
11
12 Return value is a pair of (sequence, labels) where 'sequence' is
13 the cms.Sequence, and 'labels' is a vector with the following
14 entries:
15 * labels['jta'] = the name of the JetTrackAssociator module
16 * labels['tagInfos'] = a list of names of the TagInfo modules
17 * labels['jetTags '] = a list of names of the JetTag modules
18 """
19 _label='runBTagging'
20 _defaultParameters=dicttypes.SortedKeysDict()
21 def __init__(self):
22 ConfigToolBase.__init__(self)
23 self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue, 'input jet collection',Type=cms.InputTag)
24 self.addParameter(self._defaultParameters,'label',self._defaultValue, 'postfix label to identify new sequence/modules', Type=str)
25 self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence (do not confuse with 'label')")
26 self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list)
27 self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags', 'trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags', 'simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list)
28 self._parameters=copy.deepcopy(self._defaultParameters)
29 self._comment = ""
30
31 def getDefaultParameters(self):
32 return self._defaultParameters
33
34
35 def __call__(self,process,
36 jetCollection = None,
37 label = None,
38 postfix = None,
39 btagInfo = None,
40 btagdiscriminators = None) :
41
42
43
44 if jetCollection is None:
45 jetCollection=self._defaultParameters['jetCollection'].value
46 if label is None:
47 label=self._defaultParameters['label'].value
48 if postfix is None:
49 postfix=self._defaultParameters['postfix'].value
50 if btagInfo is None:
51 btagInfo=self._defaultParameters['btagInfo'].value
52 if btagdiscriminators is None:
53 btagdiscriminators=self._defaultParameters['btagdiscriminators'].value
54
55
56
57 self.setParameter('jetCollection',jetCollection)
58 self.setParameter('label',label)
59 self.setParameter('postfix',postfix)
60 self.setParameter('btagInfo',btagInfo)
61 self.setParameter('btagdiscriminators',btagdiscriminators)
62
63
64 return self.apply(process)
65
66 def apply(self, process):
67 jetCollection=self._parameters['jetCollection'].value
68 label=self._parameters['label'].value
69 postfix=self._parameters['postfix'].value
70 btagInfo=self._parameters['btagInfo'].value
71 btagdiscriminators=self._parameters['btagdiscriminators'].value
72
73
74 if hasattr(process, "addAction"):
75 process.disableRecording()
76
77 try:
78 comment=inspect.stack(2)[2][4][0].rstrip("\n")
79 if comment.startswith("#"):
80 self.setComment(comment.lstrip("#"))
81 except:
82 pass
83
84 #############################
85 ### TOOL CODE STARTS HERE ###
86 #############################
87 if (label == ''):
88 ## label is not allowed to be empty
89 raise ValueError, "label for re-running b tagging is not allowed to be empty"
90
91 ## import track associator & b tag configuration
92 process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
93 from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
94 process.load("RecoBTag.Configuration.RecoBTag_cff")
95 import RecoBTag.Configuration.RecoBTag_cff as btag
96
97 # add negative tag infos
98 import PhysicsTools.PatAlgos.recoLayer0.bTagging_cff as nbtag
99
100 ## define jetTracksAssociator; for switchJetCollection
101 ## the label is 'AOD' as empty labels will lead to crashes
102 ## of crab. In this case the postfix label is skiped,
103 ## otherwise a postfix label is added as for the other
104 ## labels
105 jtaLabel = 'jetTracksAssociatorAtVertex'+postfix
106
107 if (not label == 'AOD'):
108 jtaLabel += label
109 ## define tag info labels (compare with jetProducer_cfi.py)
110 ipTILabel = 'impactParameterTagInfos' + label + postfix
111 svTILabel = 'secondaryVertexTagInfos' + label + postfix
112 ivfTILabel = 'inclusiveSecondaryVertexFinderTagInfos' + label + postfix
113 nvTILabel = 'secondaryVertexNegativeTagInfos' + label + postfix
114 seTILabel = 'softElectronTagInfos' + label + postfix
115 smTILabel = 'softMuonTagInfos' + label + postfix
116
117
118
119 #setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
120 #setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
121 #setattr( process, nvTILabel, nbtag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
122 #setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = jetCollection) )
123 #setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )
124
125 ## make VInputTag from strings
126 def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
127
128 ## produce btags
129 print
130 print "The btaginfo below will be written to the jet collection in the PATtuple (default is all, see PatAlgos/PhysicsTools/python/tools/jetTools.py)"
131 print
132 for TagInfo in btagInfo:
133 print TagInfo
134
135 if TagInfo=='impactParameterTagInfos':
136 setattr( process, ipTILabel, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(jtaLabel)) )
137 if TagInfo=='secondaryVertexTagInfos':
138 setattr( process, svTILabel, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
139 if TagInfo=='softMuonTagInfos':
140 setattr( process, smTILabel, btag.softMuonTagInfos.clone(jets = jetCollection) )
141 if TagInfo=='softElectronTagInfos':
142 setattr( process, seTILabel, btag.softElectronTagInfos.clone(jets = jetCollection) )
143 if TagInfo=='secondaryVertexNegativeTagInfos':
144 setattr( process, nvTILabel, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
145 if TagInfo=='inclusiveSecondaryVertexFinderTagInfos':
146 setattr( process, ivfTILabel, btag.inclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag(ipTILabel)) )
147
148 print
149 print "The bdiscriminators below will be written to the jet collection in the PATtuple (default is all, see PatAlgos/PhysicsTools/python/tools/jetTools.py)"
150 for tag in btagdiscriminators:
151 print tag
152 if tag == 'jetBProbabilityBJetTags' or tag == 'jetProbabilityBJetTags' or tag == 'trackCountingHighPurBJetTags' or tag == 'trackCountingHighEffBJetTags' or tag == 'negativeTrackCountingHighEffJetTags' or tag =='negativeTrackCountingHighPurJetTags' :
153 tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel))
154 setattr(process, tag+label+postfix, tagInfo)
155
156 if tag == 'simpleSecondaryVertexHighEffBJetTags' or tag == 'simpleSecondaryVertexHighPurBJetTags':
157 # tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel,svTILabel))
158 tagInfo=getattr(btag,tag).clone(tagInfos = vit(svTILabel))
159 setattr(process, tag+label+postfix, tagInfo)
160
161 if tag == 'combinedSecondaryVertexBJetTags' or tag == 'combinedSecondaryVertexMVABJetTags':
162 tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel,svTILabel))
163 setattr(process, tag+label+postfix, tagInfo)
164
165 if tag == 'softMuonBJetTags' or tag == 'softMuonByPtBJetTags' or tag == 'softMuonByIP3dBJetTags' :
166 tagInfo=getattr(btag,tag).clone(tagInfos = vit(smTILabel))
167 setattr(process, tag+label+postfix, tagInfo)
168
169 if tag == 'simpleSecondaryVertexNegativeHighEffBJetTags' or tag == 'simpleSecondaryVertexNegativeHighPurBJetTags':
170 tagInfo=getattr(btag,tag).clone(tagInfos = vit(nvTILabel))
171 setattr(process, tag+label+postfix, tagInfo)
172
173
174 if tag == 'combinedInclusiveSecondaryVertexBJetTags' :
175 tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel,ivfTILabel))
176 setattr(process, tag+label+postfix, tagInfo)
177
178 if tag == 'combinedMVABJetTags' :
179 tagInfo=getattr(btag,tag).clone(tagInfos = vit(ipTILabel, ivfTILabel,smTILabel,seTILabel))
180 setattr(process, tag+label+postfix, tagInfo)
181
182
183
184 ## define vector of (output) labels
185 labels = { 'jta' : jtaLabel,
186 #'tagInfos' : (ipTILabel,svTILabel,seTILabel,smTILabel),
187 #'tagInfos' : (ipTILabel,svTILabel,smTILabel),
188 #'tagInfos' : [ for y in btagInfo],
189 'tagInfos' : [(y + label + postfix) for y in btagInfo],
190 #'tagInfos' : (ipTILabel,svTILabel,smTILabel),
191 'jetTags' : [ (x + label+postfix) for x in btagdiscriminators]
192
193 }
194
195
196
197
198 ## extend an existing sequence by otherLabels
199 def mkseq(process, firstlabel, *otherlabels):
200 seq = getattr(process, firstlabel)
201 for x in otherlabels: seq += getattr(process, x)
202 return cms.Sequence(seq)
203
204 ## add tag infos to the process
205 setattr( process, 'btaggingTagInfos'+label+postfix, mkseq(process, *(labels['tagInfos']) ) )
206 ## add b tags to the process
207 setattr( process, 'btaggingJetTags'+label+postfix, mkseq(process, *(labels['jetTags']) ) )
208 ## add a combined sequence to the process
209 seq = mkseq(process, 'btaggingTagInfos'+label+postfix, 'btaggingJetTags' + label + postfix)
210 setattr( process, 'btagging'+label+postfix, seq )
211 ## return the combined sequence and the labels defined above
212
213 if hasattr(process, "addAction"):
214 process.enableRecording()
215 action=self.__copy__()
216 process.addAction(action)
217 return (seq, labels)
218
219 runBTagging=RunBTagging()
220
221
222 class AddJetCollection(ConfigToolBase):
223
224 """ Add a new collection of jets. Takes the configuration from the
225 already configured standard jet collection as starting point;
226 replaces before calling addJetCollection will also affect the
227 new jet collections
228 """
229 _label='addJetCollection'
230 _defaultParameters=dicttypes.SortedKeysDict()
231
232 def __init__(self):
233 ConfigToolBase.__init__(self)
234 self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
235 self.addParameter(self._defaultParameters,'algoLabel',self._defaultValue, "label to indicate the jet algorithm (e.g.'AK5')",str)
236 self.addParameter(self._defaultParameters,'typeLabel',self._defaultValue, "label to indicate the type of constituents (e.g. 'Calo', 'Pflow', 'Jpt', ...)",str)
237 self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list)
238 # self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos'],Type=list)
239 # self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags'],Type=list)
240 self.addParameter(self._defaultParameters,'btagdiscriminators',['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags', 'trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags', 'simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list)
241 self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
242 self.addParameter(self._defaultParameters,'doBTagging',True, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)')
243 self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True )
244 self.addParameter(self._defaultParameters,'doType1MET',True, "if jetCorrLabel is not 'None', set this to 'True' to redo the Type1 MET correction for the new jet colllection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ")
245 self.addParameter(self._defaultParameters,'doL1Cleaning',True, "copy also the producer modules for cleanLayer1 will be set to 'True' automatically when doL1Counters is 'True'")
246 self.addParameter(self._defaultParameters,'doL1Counters',False, "copy also the filter modules that accept/reject the event looking at the number of jets")
247 self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to")
248 self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection?")
249 self.addParameter(self._defaultParameters,'jetIdLabel',"ak5", " specify the label prefix of the xxxJetID object; in general it is the jet collection tag like ak5, kt4 sc5, aso. For more information have a look to SWGuidePATTools#add_JetCollection")
250 self.addParameter(self._defaultParameters,'standardAlgo',"AK5", "standard algorithm label of the collection from which the clones for the new jet collection will be taken from (note that this jet collection has to be available in the event before hand)")
251 self.addParameter(self._defaultParameters,'standardType',"Calo", "standard constituent type label of the collection from which the clones for the new jet collection will be taken from (note that this jet collection has to be available in the event before hand)")
252 self.addParameter(self._defaultParameters, 'outputModules', ['out'], "output module labels, empty list of label indicates no output, default: ['out']")
253
254 self._parameters=copy.deepcopy(self._defaultParameters)
255 self._comment = ""
256
257 def getDefaultParameters(self):
258 return self._defaultParameters
259
260 def __call__(self,process,
261
262 jetCollection = None,
263 algoLabel = None,
264 typeLabel = None,
265 doJTA = None,
266 doBTagging = None,
267 jetCorrLabel = None,
268 doType1MET = None,
269 doL1Cleaning = None,
270 doL1Counters = None,
271 genJetCollection = None,
272 doJetID = None,
273 jetIdLabel = None,
274 outputModule = None,
275 outputModules = None,
276 btagInfo = None,
277 btagdiscriminators = None
278 ):
279
280 ## stop processing if 'outputModule' exists and show the new alternative
281 if not outputModule is None:
282 depricatedOptionOutputModule(self)
283 if jetCollection is None:
284 jetCollection=self._defaultParameters['jetCollection'].value
285 if algoLabel is None:
286 algoLabel=self._defaultParameters['algoLabel'].value
287 if typeLabel is None:
288 typeLabel=self._defaultParameters['typeLabel'].value
289 if doJTA is None:
290 doJTA=self._defaultParameters['doJTA'].value
291 if doBTagging is None:
292 doBTagging=self._defaultParameters['doBTagging'].value
293 if jetCorrLabel is None:
294 jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
295 if doType1MET is None:
296 doType1MET=self._defaultParameters['doType1MET'].value
297 if doL1Cleaning is None:
298 doL1Cleaning=self._defaultParameters['doL1Cleaning'].value
299 if doL1Counters is None:
300 doL1Counters=self._defaultParameters['doL1Counters'].value
301 if genJetCollection is None:
302 genJetCollection=self._defaultParameters['genJetCollection'].value
303 if doJetID is None:
304 doJetID=self._defaultParameters['doJetID'].value
305 if jetIdLabel is None:
306 jetIdLabel=self._defaultParameters['jetIdLabel'].value
307 if outputModules is None:
308 outputModules=self._defaultParameters['outputModules'].value
309 if btagInfo is None:
310 btagInfo=self._defaultParameters['btagInfo'].value
311 if btagdiscriminators is None:
312 btagdiscriminators=self._defaultParameters['btagdiscriminators'].value
313
314 self.setParameter('jetCollection',jetCollection)
315 self.setParameter('algoLabel',algoLabel)
316 self.setParameter('typeLabel',typeLabel)
317 self.setParameter('doJTA',doJTA)
318 self.setParameter('doBTagging',doBTagging)
319 self.setParameter('jetCorrLabel',jetCorrLabel)
320 self.setParameter('doType1MET',doType1MET)
321 self.setParameter('doL1Cleaning',doL1Cleaning)
322 self.setParameter('doL1Counters',doL1Counters)
323 self.setParameter('genJetCollection',genJetCollection)
324 self.setParameter('doJetID',doJetID)
325 self.setParameter('jetIdLabel',jetIdLabel)
326 self.setParameter('outputModules',outputModules)
327 self.setParameter('btagInfo',btagInfo)
328 self.setParameter('btagdiscriminators',btagdiscriminators)
329
330 self.apply(process)
331
332 def toolCode(self, process):
333
334 jetCollection=self._parameters['jetCollection'].value
335 algoLabel=self._parameters['algoLabel'].value
336 typeLabel=self._parameters['typeLabel'].value
337 doJTA=self._parameters['doJTA'].value
338 doBTagging=self._parameters['doBTagging'].value
339 jetCorrLabel=self._parameters['jetCorrLabel'].value
340 doType1MET =self._parameters['doType1MET'].value
341 doL1Cleaning=self._parameters['doL1Cleaning'].value
342 doL1Counters=self._parameters['doL1Counters'].value
343 genJetCollection=self._parameters['genJetCollection'].value
344 doJetID=self._parameters['doJetID'].value
345 jetIdLabel=self._parameters['jetIdLabel'].value
346 outputModules=self._parameters['outputModules'].value
347 btagInfo=self._parameters['btagInfo'].value
348 btagdiscriminators=self._parameters['btagdiscriminators'].value
349
350
351 ## create old module label from standardAlgo
352 ## and standardType and return
353 def oldLabel(prefix=''):
354 return jetCollectionString(prefix, '', '')
355
356 ## create new module label from old module
357 ## label and return
358 def newLabel(oldLabel):
359 newLabel=oldLabel
360 oldLabel=oldLabel+algoLabel+typeLabel
361 return oldLabel
362
363 ## clone module and add it to the patDefaultSequence
364 def addClone(hook, **replaceStatements):
365 ## create a clone of the hook with corresponding
366 ## parameter replacements
367 newModule = getattr(process, hook).clone(**replaceStatements)
368 ## add the module to the sequence
369 addModuleToSequence(hook, newModule)
370
371 ## add module to the patDefaultSequence
372 def addModuleToSequence(hook, newModule):
373 hookModule = getattr(process, hook)
374 ## add the new module with standardAlgo &
375 ## standardType replaced in module label
376 setattr( process, newLabel(hook), newModule)
377 ## add new module to default sequence
378 ## just behind the hookModule
379 process.patDefaultSequence.replace( hookModule, hookModule*newModule )
380
381 ## add a clone of patJets
382 addClone(oldLabel(), jetSource = jetCollection)
383 ## add a clone of selectedPatJets
384 addClone(oldLabel('selected'), src=cms.InputTag(newLabel(oldLabel())))
385 ## add a clone of cleanPatJets
386 if( doL1Cleaning ):
387 addClone(oldLabel('clean'), src=cms.InputTag(newLabel(oldLabel('selected'))))
388 ## add a clone of countPatJets
389 if( doL1Counters ):
390 if( doL1Cleaning ):
391 addClone(oldLabel('count'), src=cms.InputTag(newLabel(oldLabel('clean'))))
392 else:
393 addClone(oldLabel('count'), src=cms.InputTag(newLabel(oldLabel('selected'))))
394
395 ## get attributes of new module
396 l1Jets = getattr(process, newLabel(oldLabel()))
397
398 ## add a clone of gen jet matching
399 addClone('patJetPartonMatch', src = jetCollection)
400 addClone('patJetGenJetMatch', src = jetCollection, matched = genJetCollection)
401
402 ## add a clone of parton and flavour associations
403 addClone('patJetPartonAssociation', jets = jetCollection)
404 addClone('patJetFlavourAssociation', srcByReference = cms.InputTag(newLabel('patJetPartonAssociation')))
405
406 ## fix label for input tag
407 def fixInputTag(x): x.setModuleLabel(newLabel(x.moduleLabel))
408 ## fix label for vector of input tags
409 def fixVInputTag(x): x[0].setModuleLabel(newLabel(x[0].moduleLabel))
410
411 ## provide allLayer1Jet inputs with individual labels
412 fixInputTag(l1Jets.genJetMatch)
413 fixInputTag(l1Jets.genPartonMatch)
414 fixInputTag(l1Jets.JetPartonMapSource)
415
416 ## make VInputTag from strings
417 def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
418
419 if (doJTA or doBTagging):
420 ## add clone of jet track association
421 process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
422 from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
423 ## add jet track association module to processes
424 jtaLabel = 'jetTracksAssociatorAtVertex'+algoLabel+typeLabel
425 setattr( process, jtaLabel, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection) )
426 process.patDefaultSequence.replace(process.patJetCharge, getattr(process,jtaLabel)+process.patJetCharge)
427 l1Jets.trackAssociationSource = cms.InputTag(jtaLabel)
428 addClone('patJetCharge', src=cms.InputTag(jtaLabel)),
429 fixInputTag(l1Jets.jetChargeSource)
430 else:
431 ## switch embedding of track association and jet
432 ## charge estimate to 'False'
433 l1Jets.addAssociatedTracks = False
434 l1Jets.addJetCharge = False
435
436 if (doBTagging):
437 ## define postfixLabel
438 postfixLabel=algoLabel+typeLabel
439 ## add b tagging sequence
440 (btagSeq, btagLabels) = runBTagging(process, jetCollection, postfixLabel,"", btagInfo,btagdiscriminators)
441 ## add b tagging sequence before running the allLayer1Jets modules
442 process.patDefaultSequence.replace(getattr(process,jtaLabel), getattr(process,jtaLabel)+btagSeq)
443 ## replace corresponding tags for pat jet production
444 l1Jets.trackAssociationSource = cms.InputTag(btagLabels['jta'])
445 l1Jets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
446 l1Jets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags'] ] )
447 else:
448 ## switch general b tagging info switch off
449 l1Jets.addBTagInfo = False
450 ## adjust output
451 if len(outputModules) > 0:
452 for outMod in outputModules:
453 if hasattr(process,outMod):
454 getattr(process,outMod).outputCommands.append("drop *_"+newLabel(oldLabel('selected'))+"_tagInfos_*")
455 else:
456 raise KeyError, "process has no OutModule named", outMod
457
458 if (doJetID):
459 l1Jets.addJetID = cms.bool(True)
460 jetIdLabelNew = jetIdLabel + 'JetID'
461 l1Jets.jetIDMap = cms.InputTag( jetIdLabelNew )
462 else :
463 l1Jets.addJetID = cms.bool(False)
464
465 if (jetCorrLabel != None):
466 ## add clone of jet energy corrections;
467 ## catch a couple of exceptions first
468 if (jetCorrLabel == False ):
469 raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
470 if (jetCorrLabel == "None"):
471 raise ValueError, "In addJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
472 ## check for the correct format
473 if type(jetCorrLabel) != type(('AK5Calo',['L2Relative'])):
474 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('payload',['correction1', 'correction2'])"
475
476 ## add clone of jetCorrFactors
477 addClone('patJetCorrFactors', src = jetCollection)
478 switchJetCorrLevels(process, jetCorrLabel = jetCorrLabel, postfix=algoLabel+typeLabel)
479 getattr(process, newLabel('patJets')).jetCorrFactorsSource = cms.VInputTag( cms.InputTag(newLabel('patJetCorrFactors')) )
480
481 ## find out type of jet collection, switch type1MET corrections off for JPTJets
482 jetCollType = ''
483 if ( 'CaloJets' in jetCollection.getModuleLabel() ):
484 jetCollType = 'Calo'
485 elif ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith('pfNo') or jetCollection.getModuleLabel() == 'particleFlow'):
486 jetCollType = 'PF'
487 else:
488 print '============================================='
489 print 'Type1MET corrections are switched off for '
490 print 'JPT Jets. Users are recommened to use tcMET '
491 print 'together with JPT jets. '
492 print '============================================='
493 doType1MET=False
494
495 ## add a clone of the type1MET correction for the new jet collection
496 if (doType1MET):
497 ## create jet correctors for MET corrections
498 from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet, ak5PFL1Offset, ak5PFL2Relative, ak5PFL3Absolute, ak5PFResidual
499 setattr(process, jetCorrLabel[0]+'L1FastJet' , ak5PFL1Fastjet.clone ( algorithm=jetCorrLabel[0]
500 , srcRho=cms.InputTag(newLabel('kt6'+jetCollType+'Jets'),'rho') ) )
501 setattr(process, jetCorrLabel[0]+'L1Offset' , ak5PFL1Offset.clone ( algorithm=jetCorrLabel[0] ) )
502 setattr(process, jetCorrLabel[0]+'L2Relative' , ak5PFL2Relative.clone( algorithm=jetCorrLabel[0] ) )
503 setattr(process, jetCorrLabel[0]+'L3Absolute' , ak5PFL3Absolute.clone( algorithm=jetCorrLabel[0] ) )
504 setattr(process, jetCorrLabel[0]+'L2L3Residual', ak5PFResidual.clone ( algorithm=jetCorrLabel[0] ) )
505 ## combinded corrections
506 setattr(process, jetCorrLabel[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain'
507 , correctors = cms.vstring() ) )
508
509 for corrLbl in jetCorrLabel[1]:
510 if corrLbl != 'L1FastJet' and corrLbl != 'L1Offset' and corrLbl != 'L2Relative' and corrLbl != 'L3Absolute' and corrLbl != 'L2L3Residual':
511 print '========================================='
512 print ' Type1MET corrections are currently only '
513 print ' supported for the following corrections: '
514 print ' - L1FastJet'
515 print ' - L1Offset'
516 print ' - L2Relative'
517 print ' - L3Absolute'
518 print ' - L2L3Residual'
519 print ' But given was:'
520 print ' -', corrLbl
521 print '============================================='
522 raise ValueError, 'unsupported JEC for TypeI MET correction: '+corrLbl
523 else:
524 getattr(process, jetCorrLabel[0]+'CombinedCorrector').correctors.append(jetCorrLabel[0]+corrLbl)
525
526 ## configuration of MET corrections
527 if jetCollType == 'Calo':
528 from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloJetMETcorr,caloType1CorrectedMet,caloType1p2CorrectedMet,produceCaloMETCorrections
529
530 setattr(process,jetCorrLabel[0]+'JetMETcorr', caloJetMETcorr.clone(srcMET = "corMetGlobalMuons"))
531 setattr(process,jetCorrLabel[0]+'Type1CorMet', caloType1CorrectedMet.clone(src = "corMetGlobalMuons"))
532 setattr(process,jetCorrLabel[0]+'Type1p2CorMet',caloType1p2CorrectedMet.clone(src = "corMetGlobalMuons"))
533
534 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).src = cms.InputTag(jetCollection.getModuleLabel())
535 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
536 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
537 elif ('L1Offset' in jetCorrLabel[1]):
538 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
539 else:
540 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).offsetCorrLabel = cms.string('')
541 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector')
542
543 getattr(process,jetCorrLabel[0]+'Type1CorMet' ).srcType1Corrections = cms.VInputTag(
544 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
545 )
546
547 getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcType1Corrections = cms.VInputTag(
548 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
549 )
550 getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcUnclEnergySums = cms.VInputTag(
551 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type2'),
552 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'offset'),
553 cms.InputTag('muonCaloMETcorr')
554 )
555
556 ## add MET corrections to sequence
557 addClone('patMETs', metSource = cms.InputTag(jetCorrLabel[0]+'Type1CorMet'))
558
559 setattr(process,'produce'+jetCorrLabel[0]+'METCorrections',produceCaloMETCorrections.copy())
560 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'caloJetMETcorr'), getattr(process,jetCorrLabel[0]+'JetMETcorr'))
561 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'caloType1CorrectedMet'), getattr(process,jetCorrLabel[0]+'Type1CorMet'))
562 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'caloType1p2CorrectedMet'),getattr(process,jetCorrLabel[0]+'Type1p2CorMet'))
563 process.patDefaultSequence.replace( getattr(process,newLabel('patMETs')),
564 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections')
565 *getattr(process,newLabel('patMETs')) )
566 elif jetCollType == 'PF':
567 from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandsNotInJet,pfJetMETcorr,pfCandMETcorr,pfType1CorrectedMet,pfType1p2CorrectedMet,producePFMETCorrections
568 setattr(process,jetCorrLabel[0]+'CandsNotInJet',pfCandsNotInJet.clone(topCollection = jetCollection))
569 setattr(process,jetCorrLabel[0]+'JetMETcorr', pfJetMETcorr.clone(src = jetCollection))
570 setattr(process,jetCorrLabel[0]+'CandMETcorr', pfCandMETcorr.clone(src = cms.InputTag(jetCorrLabel[0]+'CandsNotInJet')))
571 setattr(process,jetCorrLabel[0]+'Type1CorMet', pfType1CorrectedMet.clone())
572 setattr(process,jetCorrLabel[0]+'Type1p2CorMet',pfType1p2CorrectedMet.clone())
573
574 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
575 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
576 elif ('L1Offset' in jetCorrLabel[1]):
577 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
578 else:
579 getattr(process,jetCorrLabel[0]+'JetMETcorr' ).offsetCorrLabel = cms.string('')
580 getattr(process,jetCorrLabel[0]+'JetMETcorr').jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector')
581
582 getattr(process,jetCorrLabel[0]+'Type1CorMet').srcType1Corrections = cms.VInputTag(
583 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
584 )
585 getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcType1Corrections = cms.VInputTag(
586 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type1')
587 )
588 getattr(process,jetCorrLabel[0]+'Type1p2CorMet').srcUnclEnergySums = cms.VInputTag(
589 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'type2'),
590 cms.InputTag(jetCorrLabel[0]+'JetMETcorr', 'offset'),
591 cms.InputTag(jetCorrLabel[0]+'CandMETcorr')
592 )
593
594 ## add MET corrections to sequence
595 addClone('patMETs', metSource = cms.InputTag(jetCorrLabel[0]+'Type1CorMet'), addMuonCorrections = False)
596 setattr(process,'produce'+jetCorrLabel[0]+'METCorrections',producePFMETCorrections.copy())
597 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfCandsNotInJet'), getattr(process,jetCorrLabel[0]+'CandsNotInJet'))
598 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfJetMETcorr'), getattr(process,jetCorrLabel[0]+'JetMETcorr'))
599 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfCandMETcorr'), getattr(process,jetCorrLabel[0]+'CandMETcorr'))
600 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfType1CorrectedMet'), getattr(process,jetCorrLabel[0]+'Type1CorMet'))
601 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections').replace(getattr(process,'pfType1p2CorrectedMet'),getattr(process,jetCorrLabel[0]+'Type1p2CorMet'))
602 process.patDefaultSequence.replace( getattr(process,newLabel('patMETs')),
603 getattr(process,'produce'+jetCorrLabel[0]+'METCorrections')
604 *getattr(process,newLabel('patMETs')) )
605 else:
606 ## switch jetCorrFactors off
607 l1Jets.addJetCorrFactors = False
608
609 addJetCollection=AddJetCollection()
610
611
612 class SwitchJetCollection(ConfigToolBase):
613
614 """ Switch the collection of jets in PAT from the default value to a
615 new jet collection
616 """
617 _label='switchJetCollection'
618 _defaultParameters=dicttypes.SortedKeysDict()
619 def __init__(self):
620 ConfigToolBase.__init__(self)
621 self.addParameter(self._defaultParameters,'jetCollection',self._defaultValue,'Input jet collection', cms.InputTag)
622 self.addParameter(self._defaultParameters,'btagInfo',['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],"input btag info",allowedValues=['impactParameterTagInfos','secondaryVertexTagInfos','softMuonTagInfos','secondaryVertexNegativeTagInfos','inclusiveSecondaryVertexFinderTagInfos','softElectronTagInfos'],Type=list)
623 self.addParameter(self._defaultParameters, 'btagdiscriminators',['jetBProbabilityBJetTags','jetProbabilityBJetTags','trackCountingHighPurBJetTags','trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],"input btag discriminators", allowedValues=['jetBProbabilityBJetTags', 'jetProbabilityBJetTags','trackCountingHighPurBJetTags', 'trackCountingHighEffBJetTags','simpleSecondaryVertexHighEffBJetTags','simpleSecondaryVertexHighPurBJetTags','combinedSecondaryVertexBJetTags','combinedSecondaryVertexMVABJetTags','softMuonBJetTags','softMuonByPtBJetTags','softMuonByIP3dBJetTags','simpleSecondaryVertexNegativeHighEffBJetTags','simpleSecondaryVertexNegativeHighPurBJetTags','negativeTrackCountingHighEffJetTags','negativeTrackCountingHighPurJetTags','combinedInclusiveSecondaryVertexBJetTags','combinedMVABJetTags'],Type=list)
624 self.addParameter(self._defaultParameters,'doJTA',True, "run b tagging sequence for new jet collection and add it to the new pat jet collection")
625 self.addParameter(self._defaultParameters,'doBTagging',True, 'run JetTracksAssociation and JetCharge and add it to the new pat jet collection (will autom. be true if doBTagging is set to true)')
626 self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True )
627 self.addParameter(self._defaultParameters,'doType1MET',True, "if jetCorrLabel is not 'None', set this to 'True' to redo the Type1 MET correction for the new jet colleection; at the moment it must be 'False' for non CaloJets otherwise the JetMET POG module crashes. ")
628 self.addParameter(self._defaultParameters,'genJetCollection',cms.InputTag("ak5GenJets"), "GenJet collection to match to")
629 self.addParameter(self._defaultParameters,'doJetID',True, "add jetId variables to the added jet collection")
630 self.addParameter(self._defaultParameters,'jetIdLabel',"ak5", " specify the label prefix of the xxxJetID object; in general it is the jet collection tag like ak5, kt4 sc5, aso. For more information have a look to SWGuidePATTools#add_JetCollection")
631 self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence")
632 self.addParameter(self._defaultParameters, 'outputModules', ['out'], "Output module labels, empty list of label indicates no output, default: ['out']")
633
634 self._parameters=copy.deepcopy(self._defaultParameters)
635 self._comment = ""
636
637 def getDefaultParameters(self):
638 return self._defaultParameters
639
640 def __call__(self,process,
641 jetCollection = None,
642 doJTA = None,
643 doBTagging = None,
644 jetCorrLabel = None,
645 doType1MET = None,
646 genJetCollection = None,
647 doJetID = None,
648 jetIdLabel = None,
649 postfix = None,
650 outputModule = None,
651 outputModules = None,
652 btagInfo = None,
653 btagdiscriminators = None
654 ):
655
656
657
658
659 ## stop processing if 'outputModule' exists and show the new alternative
660 if not outputModule is None:
661 depricatedOptionOutputModule(self)
662 if jetCollection is None:
663 jetCollection=self._defaultParameters['jetCollection'].value
664 if doJTA is None:
665 doJTA=self._defaultParameters['doJTA'].value
666 if doBTagging is None:
667 doBTagging=self._defaultParameters['doBTagging'].value
668 if jetCorrLabel is None:
669 jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
670 if doType1MET is None:
671 doType1MET=self._defaultParameters['doType1MET'].value
672 if genJetCollection is None:
673 genJetCollection=self._defaultParameters['genJetCollection'].value
674 if doJetID is None:
675 doJetID=self._defaultParameters['doJetID'].value
676 if jetIdLabel is None:
677 jetIdLabel=self._defaultParameters['jetIdLabel'].value
678 if outputModules is None:
679 outputModules=self._defaultParameters['outputModules'].value
680 if postfix is None:
681 postfix=self._defaultParameters['postfix'].value
682 if btagInfo is None:
683 btagInfo=self._defaultParameters['btagInfo'].value
684 if btagdiscriminators is None:
685 btagdiscriminators=self._defaultParameters['btagdiscriminators'].value
686
687
688
689
690 self.setParameter('jetCollection',jetCollection)
691 self.setParameter('doJTA',doJTA)
692 self.setParameter('doBTagging',doBTagging)
693 self.setParameter('jetCorrLabel',jetCorrLabel)
694 self.setParameter('doType1MET',doType1MET)
695 self.setParameter('genJetCollection',genJetCollection)
696 self.setParameter('doJetID',doJetID)
697 self.setParameter('jetIdLabel',jetIdLabel)
698 self.setParameter('outputModules',outputModules)
699 self.setParameter('postfix',postfix)
700 self.setParameter('btagInfo',btagInfo)
701 self.setParameter('btagdiscriminators',btagdiscriminators)
702
703 self.apply(process)
704
705 def toolCode(self, process):
706 jetCollection=self._parameters['jetCollection'].value
707 doJTA=self._parameters['doJTA'].value
708 doBTagging=self._parameters['doBTagging'].value
709 jetCorrLabel=self._parameters['jetCorrLabel'].value
710 doType1MET =self._parameters['doType1MET'].value
711 genJetCollection=self._parameters['genJetCollection'].value
712 doJetID=self._parameters['doJetID'].value
713 jetIdLabel=self._parameters['jetIdLabel'].value
714 outputModules=self._parameters['outputModules'].value
715 postfix=self._parameters['postfix'].value
716 btagInfo=self._parameters['btagInfo'].value
717 btagdiscriminators=self._parameters['btagdiscriminators'].value
718
719 ## save label of old input jet collection
720 oldLabel = applyPostfix(process, "patJets", postfix).jetSource;
721
722 ## replace input jet collection for generator matches if the
723 ## genJetCollection is no empty
724 if (process.patJets.addGenPartonMatch):
725 applyPostfix(process, "patJetPartonMatch", postfix).src = jetCollection
726 if (process.patJets.addGenJetMatch):
727 applyPostfix(process, "patJetGenJetMatch", postfix).src = jetCollection
728 applyPostfix(process, "patJetGenJetMatch", postfix).matched = genJetCollection
729 if (process.patJets.getJetMCFlavour):
730 applyPostfix(process, "patJetPartonAssociation", postfix).jets = jetCollection
731
732 ## replace input jet collection for pat jet production
733 applyPostfix(process, "patJets", postfix).jetSource = jetCollection
734
735 ## make VInputTag from strings
736 def vit(*args) : return cms.VInputTag( *[ cms.InputTag(x) for x in args ] )
737
738 if (doJTA or doBTagging):
739 ## replace jet track association
740 process.load("RecoJets.JetAssociationProducers.ak5JTA_cff")
741 from RecoJets.JetAssociationProducers.ak5JTA_cff import ak5JetTracksAssociatorAtVertex
742 setattr(process, "jetTracksAssociatorAtVertex"+postfix, ak5JetTracksAssociatorAtVertex.clone(jets = jetCollection))
743 getattr(process, "patDefaultSequence"+postfix).replace(
744 applyPostfix(process, "patJetCharge", postfix),
745 getattr(process, "jetTracksAssociatorAtVertex" + postfix) #module with postfix that is not n patDefaultSequence
746 + applyPostfix(process, "patJetCharge", postfix)
747 )
748
749 applyPostfix(process, "patJetCharge", postfix).src = 'jetTracksAssociatorAtVertex'+postfix
750 applyPostfix(process, "patJets", postfix).trackAssociationSource = 'jetTracksAssociatorAtVertex'+postfix
751 else:
752 ## remove the jet track association from the std
753 ## sequence
754 removeIfInSequence(process, "patJetCharge", "patDefaultSequence", postfix)
755 ## switch embedding of track association and jet
756 ## charge estimate to 'False'
757 applyPostfix(process, "patJets", postfix).addAssociatedTracks = False
758 applyPostfix(process, "patJets", postfix).addJetCharge = False
759
760 if (doBTagging):
761 ## replace b tagging sequence; add postfix label 'AOD' as crab will
762 ## crash when confronted with empy labels
763 ##(btagSeq, btagLabels) = runBTagging(process, jetCollection, 'AOD',postfix)
764 (btagSeq, btagLabels) = runBTagging(process, jetCollection,"AOD",postfix,btagInfo,btagdiscriminators)
765 ## add b tagging sequence before running the allLayer1Jets modules
766 getattr(process, "patDefaultSequence"+postfix).replace(
767 getattr( process,"jetTracksAssociatorAtVertex"+postfix),
768 getattr( process,"jetTracksAssociatorAtVertex"+postfix) + btagSeq
769 )
770
771 ## replace corresponding tags for pat jet production
772 applyPostfix(process, "patJets", postfix).trackAssociationSource = btagLabels['jta']
773 applyPostfix(process, "patJets", postfix).tagInfoSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['tagInfos'] ] )
774 applyPostfix(process, "patJets", postfix).discriminatorSources = cms.VInputTag( *[ cms.InputTag(x) for x in btagLabels['jetTags'] ] )
775 else:
776 ## remove b tagging from the std sequence
777 removeIfInSequence(process, "secondaryVertexNegativeTagInfos", "patDefaultSequence", postfix)
778 removeIfInSequence(process, "simpleSecondaryVertexNegativeBJetTags", "patDefaultSequence", postfix)
779 ## switch embedding of b tagging for pat
780 ## jet production to 'False'
781 applyPostfix(process, "patJets", postfix).addBTagInfo = False
782 ## adjust output
783 if len(outputModules) > 0:
784 for outMod in outputModules:
785 if hasattr(process,outMod):
786 getattr(process,outMod).outputCommands.append("drop *_selectedPatJets_tagInfos_*")
787 else:
788 raise KeyError, "process has no OutModule named", outMod
789
790 if (doJetID):
791 jetIdLabelNew = jetIdLabel + 'JetID'
792 applyPostfix(process, "patJets", postfix).jetIDMap = cms.InputTag( jetIdLabelNew )
793 else:
794 applyPostfix(process, "patJets", postfix).addJetID = cms.bool(False)
795
796 if (jetCorrLabel!=None):
797 ## replace jet energy corrections; catch
798 ## a couple of exceptions first
799 if (jetCorrLabel == False ):
800 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
801 if (jetCorrLabel == "None"):
802 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
803 ## check for the correct format
804 if type(jetCorrLabel) != type(('AK5Calo',['L2Relative'])):
805 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('payload',['correction1', 'correction2'])"
806
807 ## switch JEC parameters to the new jet collection
808 applyPostfix(process, "patJetCorrFactors", postfix).src = jetCollection
809 switchJetCorrLevels(process, jetCorrLabel = jetCorrLabel, postfix=postfix)
810 getattr( process, "patJets" + postfix).jetCorrFactorsSource = cms.VInputTag( cms.InputTag("patJetCorrFactors" + postfix ) )
811
812 ## find out type of jet collection, switch type1MET corrections off for JPTJets
813 jetCollType = ''
814 if ( 'CaloJets' in jetCollection.getModuleLabel() ):
815 jetCollType = 'Calo'
816 elif ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith('pfNo') or jetCollection.getModuleLabel() == 'particleFlow'):
817 jetCollType = 'PF'
818 else:
819 print '============================================='
820 print 'Type1MET corrections are switched off for '
821 print 'JPT Jets. Users are recommened to use tcMET '
822 print 'together with JPT jets. '
823 print '============================================='
824 doType1MET=False
825
826 ## add a clone of the type1MET correction for the new jet collection
827 if (doType1MET):
828 ## create jet correctors for MET corrections
829 from JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff import ak5PFL1Fastjet, ak5PFL1Offset, ak5PFL2Relative, ak5PFL3Absolute, ak5PFResidual
830 setattr(process, jetCorrLabel[0]+'L1FastJet' , ak5PFL1Fastjet.clone ( algorithm=jetCorrLabel[0]
831 , srcRho=cms.InputTag('kt6'+jetCollType+'Jets','rho') ) )
832 setattr(process, jetCorrLabel[0]+'L1Offset' , ak5PFL1Offset.clone ( algorithm=jetCorrLabel[0] ) )
833 setattr(process, jetCorrLabel[0]+'L2Relative' , ak5PFL2Relative.clone( algorithm=jetCorrLabel[0] ) )
834 setattr(process, jetCorrLabel[0]+'L3Absolute' , ak5PFL3Absolute.clone( algorithm=jetCorrLabel[0] ) )
835 setattr(process, jetCorrLabel[0]+'L2L3Residual', ak5PFResidual.clone ( algorithm=jetCorrLabel[0] ) )
836 ## combinded corrections
837 setattr(process, jetCorrLabel[0]+'CombinedCorrector', cms.ESProducer( 'JetCorrectionESChain'
838 , correctors = cms.vstring() ) )
839 for corrLbl in jetCorrLabel[1]:
840 if corrLbl != 'L1FastJet' and corrLbl != 'L1Offset' and corrLbl != 'L2Relative' and corrLbl != 'L3Absolute' and corrLbl != 'L2L3Residual':
841 print '========================================='
842 print ' Type1MET corrections are currently only '
843 print ' supported for the following corrections: '
844 print ' - L1FastJet'
845 print ' - L1Offset'
846 print ' - L2Relative'
847 print ' - L3Absolute'
848 print ' - L2L3Residual'
849 print ' But given was:'
850 print ' -', corrLbl
851 print '============================================='
852 raise ValueError, 'unsupported JEC for TypeI MET correction: '+corrLbl
853 else:
854 getattr(process, jetCorrLabel[0]+'CombinedCorrector').correctors.append(jetCorrLabel[0]+corrLbl)
855
856 ## configuration of MET corrections
857 if jetCollType == 'Calo':
858 from JetMETCorrections.Type1MET.caloMETCorrections_cff import caloJetMETcorr,caloType1CorrectedMet,caloType1p2CorrectedMet,produceCaloMETCorrections
859
860 setattr(process,'caloJetMETcorr'+ postfix, caloJetMETcorr.clone(srcMET = "corMetGlobalMuons"))
861 setattr(process,'caloType1CorrectedMet'+ postfix, caloType1CorrectedMet.clone(src = "corMetGlobalMuons"))
862 setattr(process,'caloType1p2CorrectedMet'+postfix, caloType1p2CorrectedMet.clone(src = "corMetGlobalMuons"))
863
864 getattr(process,'caloJetMETcorr'+postfix).src = cms.InputTag(jetCollection.getModuleLabel())
865 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
866 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
867 elif ('L1Offset' in jetCorrLabel[1]):
868 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
869 else:
870 getattr(process,'caloJetMETcorr'+postfix ).offsetCorrLabel = cms.string('')
871 getattr(process,'caloJetMETcorr'+postfix ).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector')
872
873 getattr(process,'caloType1CorrectedMet'+postfix ).srcType1Corrections = cms.VInputTag(
874 cms.InputTag('caloJetMETcorr'+postfix, 'type1')
875 )
876
877 getattr(process,'caloType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag(
878 cms.InputTag('caloJetMETcorr'+postfix, 'type1')
879 )
880 getattr(process,'caloType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag(
881 cms.InputTag('caloJetMETcorr'+postfix, 'type2'),
882 cms.InputTag('caloJetMETcorr'+postfix, 'offset'),
883 cms.InputTag('muonCaloMETcorr')
884 )
885
886 ## add MET corrections to sequence
887 getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('caloType1CorrectedMet'+postfix)
888 getattr(process,'produceCaloMETCorrections'+postfix)
889 getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'patMETs'+postfix),
890 getattr(process,'produceCaloMETCorrections'+postfix)
891 *getattr(process,'patMETs'+postfix) )
892 elif jetCollType == 'PF':
893 from JetMETCorrections.Type1MET.pfMETCorrections_cff import pfCandsNotInJet,pfJetMETcorr,pfCandMETcorr,pfType1CorrectedMet,pfType1p2CorrectedMet,producePFMETCorrections
894 setattr(process,'producePFMETCorrections'+postfix,producePFMETCorrections.copy())
895 setattr(process,'pfCandsNotInJet' +postfix,pfCandsNotInJet.clone(topCollection = jetCollection))
896 setattr(process,'pfCandMETcorr' +postfix,pfCandMETcorr.clone(src = cms.InputTag('pfCandsNotInJet'+postfix)))
897 setattr(process,'pfJetMETcorr' +postfix,pfJetMETcorr.clone(src = jetCollection))
898
899 if ('L1FastJet' in jetCorrLabel[1] or 'L1Fastjet' in jetCorrLabel[1]):
900 getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1FastJet')
901 elif ('L1Offset' in jetCorrLabel[1]):
902 getattr(process,'pfJetMETcorr' +postfix).offsetCorrLabel = cms.string(jetCorrLabel[0]+'L1Offset')
903 else:
904 getattr(process,'pfJetMETcorr'+postfix).offsetCorrLabel = cms.string('')
905 getattr(process,'pfJetMETcorr'+postfix).jetCorrLabel = cms.string(jetCorrLabel[0]+'CombinedCorrector')
906
907 getattr(process,'pfType1CorrectedMet'+postfix).srcCHSSums = cms.VInputTag(
908 cms.InputTag("pfchsMETcorr"+postfix,"type0")
909 )
910 getattr(process,'pfType1CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag(
911 cms.InputTag('pfJetMETcorr'+postfix, 'type1')
912 )
913
914 getattr(process,'pfType1p2CorrectedMet'+postfix).srcCHSSums = cms.VInputTag(
915 cms.InputTag("pfchsMETcorr"+postfix,"type0")
916 )
917 getattr(process,'pfType1p2CorrectedMet'+postfix).srcType1Corrections = cms.VInputTag(
918 cms.InputTag('pfJetMETcorr'+postfix, 'type1')
919 )
920 getattr(process,'pfType1p2CorrectedMet'+postfix).srcUnclEnergySums = cms.VInputTag(
921 cms.InputTag('pfJetMETcorr' +postfix, 'type2'),
922 cms.InputTag('pfJetMETcorr' +postfix, 'offset'),
923 cms.InputTag('pfCandMETcorr'+postfix)
924 )
925
926 ## add MET corrections to sequence
927 getattr(process, 'patMETs'+ postfix).metSource = cms.InputTag('pfType1CorrectedMet'+postfix)
928 getattr(process, 'patMETs'+ postfix).addMuonCorrections = False
929 getattr(process,'producePFMETCorrections'+postfix).remove(getattr(process,'kt6PFJets'))#, getattr(process,'kt6PFJets' +postfix))
930 getattr(process,'producePFMETCorrections'+postfix).remove(getattr(process,'ak5PFJets'))#, getattr(process,'ak5PFJets' +postfix))
931 getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfCandsNotInJet'), getattr(process,'pfCandsNotInJet' +postfix))
932 getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfJetMETcorr'), getattr(process,'pfJetMETcorr' +postfix))
933 getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfCandMETcorr'), getattr(process,'pfCandMETcorr' +postfix))
934 getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfchsMETcorr'), getattr(process,'pfchsMETcorr' +postfix))
935 getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfType1CorrectedMet'), getattr(process,'pfType1CorrectedMet' +postfix))
936 getattr(process,'producePFMETCorrections'+postfix).replace(getattr(process,'pfType1p2CorrectedMet'),getattr(process,'pfType1p2CorrectedMet'+postfix))
937
938 getattr(process,"patDefaultSequence"+postfix).replace( getattr(process,'patMETs'+postfix),
939 getattr(process,'producePFMETCorrections'+postfix)
940 *getattr(process,'patMETs'+postfix) )
941
942 getattr(process,'patDefaultSequence'+postfix).replace(getattr(process,'patJetCorrFactors'+postfix),
943 getattr(process,'kt6PFJets'+postfix)
944 *getattr(process,'patJetCorrFactors'+postfix))
945 else:
946 ## remove the jetCorrFactors from the std sequence
947 process.patJetMETCorrections.remove(process.patJetCorrFactors)
948 ## switch embedding of jetCorrFactors off
949 ## for pat jet production
950 applyPostfix(process, "patJets", postfix).addJetCorrFactors = False
951 applyPostfix(process, "patJets", postfix).jetCorrFactorsSource=[]
952
953 ## adjust output when switching to PFJets
954 if ( 'PFJets' in jetCollection.getModuleLabel() or jetCollection.getModuleLabel().startswith("pfNo") or jetCollection.getModuleLabel() == 'particleFlow' ):
955 ## in this case we can omit caloTowers and should keep pfCandidates
956 if len(outputModules) > 0:
957 for outMod in outputModules:
958 if hasattr(process,outMod):
959 getattr(process, outMod).outputCommands.append("keep *_selectedPatJets_pfCandidates_*")
960 getattr(process, outMod).outputCommands.append("drop *_selectedPatJets_caloTowers_*")
961 else:
962 raise KeyError, "process has no OutModule named", outMod
963
964 switchJetCollection=SwitchJetCollection()
965
966
967 class AddJetID(ConfigToolBase):
968
969 """ Compute jet id for process
970 """
971 _label='addJetID'
972 _defaultParameters=dicttypes.SortedKeysDict()
973 def __init__(self):
974 ConfigToolBase.__init__(self)
975 self.addParameter(self._defaultParameters,'jetSrc',self._defaultValue, "", Type=cms.InputTag)
976 self.addParameter(self._defaultParameters,'jetIdTag',self._defaultValue, "Tag to append to jet id map", Type=str)
977 self._parameters=copy.deepcopy(self._defaultParameters)
978 self._comment = ""
979
980 def getDefaultParameters(self):
981 return self._defaultParameters
982
983 def __call__(self,process,
984 jetSrc = None,
985 jetIdTag = None) :
986 if jetSrc is None:
987 jetSrc=self._defaultParameters['jetSrc'].value
988 if jetIdTag is None:
989 jetIdTag=self._defaultParameters['jetIdTag'].value
990 self.setParameter('jetSrc',jetSrc)
991 self.setParameter('jetIdTag',jetIdTag)
992 self.apply(process)
993
994 def toolCode(self, process):
995 jetSrc=self._parameters['jetSrc'].value
996 jetIdTag=self._parameters['jetIdTag'].value
997
998 jetIdLabel = jetIdTag + 'JetID'
999 print "Making new jet ID label with label " + jetIdTag
1000
1001 ## replace jet id sequence
1002 process.load("RecoJets.JetProducers.ak5JetID_cfi")
1003 setattr( process, jetIdLabel, process.ak5JetID.clone(src = jetSrc))
1004 process.makePatJets.replace( process.patJets, getattr(process,jetIdLabel) + process.patJets )
1005
1006 addJetID=AddJetID()
1007
1008
1009 class SetTagInfos(ConfigToolBase):
1010
1011 """ Replace tag infos for collection jetSrc
1012 """
1013 _label='setTagInfos'
1014 _defaultParameters=dicttypes.SortedKeysDict()
1015 def __init__(self):
1016 ConfigToolBase.__init__(self)
1017 self.addParameter(self._defaultParameters,'coll',"patJets","jet collection to set tag infos for")
1018 self.addParameter(self._defaultParameters,'tagInfos',cms.vstring( ), "tag infos to set")
1019 self._parameters=copy.deepcopy(self._defaultParameters)
1020 self._comment = ""
1021
1022 def getDefaultParameters(self):
1023 return self._defaultParameters
1024
1025 def __call__(self,process,
1026 coll = None,
1027 tagInfos = None) :
1028 if coll is None:
1029 coll=self._defaultParameters['coll'].value
1030 if tagInfos is None:
1031 tagInfos=self._defaultParameters['tagInfos'].value
1032 self.setParameter('coll',coll)
1033 self.setParameter('tagInfos',tagInfos)
1034 self.apply(process)
1035
1036 def toolCode(self, process):
1037 coll=self._parameters['coll'].value
1038 tagInfos=self._parameters['tagInfos'].value
1039
1040 found = False
1041 newTags = cms.VInputTag()
1042 iNewTags = 0
1043 for k in tagInfos :
1044 for j in getattr( process, coll ).tagInfoSources :
1045 vv = j.value();
1046 if ( vv.find(k) != -1 ):
1047 found = True
1048 newTags.append( j )
1049
1050 if not found:
1051 raise RuntimeError,"""
1052 Cannot replace tag infos in jet collection""" % (coll)
1053 else :
1054 getattr(process,coll).tagInfoSources = newTags
1055
1056 setTagInfos=SetTagInfos()
1057
1058 class SwitchJetCorrLevels(ConfigToolBase):
1059
1060 """ Switch from jet energy correction levels and do all necessary adjustments
1061 """
1062 _label='switchJetCorrLevels'
1063 _defaultParameters=dicttypes.SortedKeysDict()
1064 def __init__(self):
1065 ConfigToolBase.__init__(self)
1066 self.addParameter(self._defaultParameters,'jetCorrLabel',None, "payload and list of new jet correction labels, such as (\'AK5Calo\',[\'L2Relative\', \'L3Absolute\'])", tuple,acceptNoneValue=True )
1067 self.addParameter(self._defaultParameters,'postfix',"", "postfix of default sequence")
1068 self._parameters=copy.deepcopy(self._defaultParameters)
1069 self._comment = ""
1070
1071 def getDefaultParameters(self):
1072 return self._defaultParameters
1073
1074 def __call__(self,process,
1075 jetCorrLabel = None,
1076 postfix = None) :
1077 if jetCorrLabel is None:
1078 jetCorrLabel=self._defaultParameters['jetCorrLabel'].value
1079 if postfix is None:
1080 postfix=self._defaultParameters['postfix'].value
1081
1082 self.setParameter('jetCorrLabel',jetCorrLabel)
1083 self.setParameter('postfix',postfix)
1084
1085 self.apply(process)
1086
1087 def toolCode(self, process):
1088 jetCorrLabel=self._parameters['jetCorrLabel'].value
1089 postfix=self._parameters['postfix'].value
1090
1091 if (jetCorrLabel!=None):
1092 ## replace jet energy corrections; catch
1093 ## a couple of exceptions first
1094 if (jetCorrLabel == False ):
1095 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None', not 'False'"
1096 if (jetCorrLabel == "None"):
1097 raise ValueError, "In switchJetCollection 'jetCorrLabel' must be set to 'None' (without quotes)"
1098 ## check for the correct format
1099 if type(jetCorrLabel) != type(('AK5Calo',['L2Relative'])):
1100 raise ValueError, "In addJetCollection 'jetCorrLabel' must be 'None', or of type ('payload',['correction1', 'correction2'])"
1101
1102 jetCorrFactorsModule = getattr(process, "patJetCorrFactors"+postfix)
1103 jetCorrFactorsModule.payload = jetCorrLabel[0]
1104 jetCorrFactorsModule.levels = jetCorrLabel[1]
1105
1106 ## check whether L1Offset or L1FastJet is part of levels
1107 error = False
1108 for x in jetCorrLabel[1]:
1109 if x == 'L1Offset':
1110 if not error:
1111 jetCorrFactorsModule.useNPV = True
1112 jetCorrFactorsModule.primaryVertices = 'offlinePrimaryVertices'
1113 ## we set this to True now as a L1 correction type should appear only once
1114 ## otherwise levels is miss configured
1115 error = True
1116 else:
1117 print 'ERROR : you miss configured the levels parameter. A L1 correction'
1118 print ' type should appear not more than once in there.'
1119 print jetCorrLabel[1]
1120
1121 if x == 'L1FastJet':
1122 if not error:
1123 ## re-run jet algo to compute rho and jetArea for the L1Fastjet corrections
1124 jetType=''
1125 ## find out which jetType is used (PF or Calo)
1126 if jetCorrLabel[0].count('PF') > 0:
1127 ## only add module if it is not already part of the process
1128 ## ATTENTION: this assumes that new jet collection are always added after existing ones !!!
1129 if not hasattr(process,'kt6PFJets'+postfix):
1130 from RecoJets.JetProducers.kt4PFJets_cfi import kt4PFJets
1131 setattr(process,'kt6PFJets'+postfix, kt4PFJets.clone(doAreaFastjet=True, doRhoFastjet=True, rParam=0.6))
1132 jetType='PF'
1133 elif jetCorrLabel[0].count('Calo') > 0:
1134 ## only add module if it is not already part of the process
1135 ## ATTENTION: this assumes that new jet collection are always added after existing ones !!!
1136 if not hasattr(process,'kt6CaloJets'+postfix):
1137 from RecoJets.JetProducers.kt4CaloJets_cfi import kt4CaloJets
1138 setattr(process,'kt6CaloJets'+postfix, kt4CaloJets.clone(doAreaFastjet=True, doRhoFastjet=True, rParam=0.6))
1139 jetType='Calo'
1140 else:
1141 raise TypeError, "L1FastJet corrections are currently only supported for PF and Calo jets in PAT"
1142 ## check if a modified patDefaultSequence exists and add kt6Jets there (needed for example for usePF2PAT)
1143 if hasattr(process,'patDefaultSequence'+postfix):
1144 if not contains(getattr(process,'patDefaultSequence'+postfix), 'kt6'+jetType+'Jets'+postfix):
1145 getattr(process,'patDefaultSequence'+postfix).replace(jetCorrFactorsModule, getattr(process,'kt6'+jetType+'Jets'+postfix)*jetCorrFactorsModule)
1146 ## if no modified patDefaultSequence exists add kt6Jets to ordinary sequence (needed for example for addJetCollection)
1147 else:
1148 if not contains(getattr(process,'patDefaultSequence'), 'kt6'+jetType+'Jets'+postfix):
1149 getattr(process,'patDefaultSequence').replace(jetCorrFactorsModule, getattr(process,'kt6'+jetType+'Jets'+postfix)*jetCorrFactorsModule)
1150 ## configure module
1151 jetCorrFactorsModule.useRho = True
1152 jetCorrFactorsModule.rho = cms.InputTag('kt6'+jetType+'Jets'+postfix, 'rho')
1153 ## we set this to True now as a L1 correction type should appear only once
1154 ## otherwise levels is miss configured
1155 error = True
1156 else:
1157 print 'ERROR : you miss configured the levels parameter. A L1 correction'
1158 print ' type should appear not more than once in there.'
1159 print jetCorrLabel[1]
1160
1161 switchJetCorrLevels=SwitchJetCorrLevels()
1162
1163 def depricatedOptionOutputModule(obj):
1164 print "-------------------------------------------------------"
1165 print " Error: the option 'outputModule' is not supported"
1166 print " anymore by:"
1167 print " ", obj._label
1168 print " please use 'outputModules' now and specify the"
1169 print " names of all needed OutModules in there"
1170 print " (default: ['out'])"
1171 print "-------------------------------------------------------"
1172 raise KeyError, "unsupported option 'outputModule' used in '"+obj._label+"'"