175 algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
178 requiredTagInfos =
list(btagInfos)
179 for btagDiscr
in btagDiscriminators :
180 for tagInfoList
in supportedBtagDiscr[btagDiscr] :
181 for requiredTagInfo
in tagInfoList :
182 tagInfoCovered =
False
183 for tagInfo
in requiredTagInfos :
184 if requiredTagInfo == tagInfo :
185 tagInfoCovered =
True
187 if not tagInfoCovered :
188 requiredTagInfos.append(requiredTagInfo)
190 if hasattr( process,
'candidateJetProbabilityComputer' ) ==
False :
192 process.load(
"RecoBTag.ImpactParameter.impactParameter_cff")
193 process.load(
"RecoBTag.SecondaryVertex.secondaryVertex_cff")
194 process.load(
"RecoBTag.SoftLepton.softLepton_cff")
195 process.load(
"RecoBTag.Combined.combinedMVA_cff")
196 process.load(
"RecoBTag.CTagging.cTagging_cff")
198 process.load(
"RecoBTag.ImpactParameter.impactParameter_EventSetup_cff")
199 process.load(
"RecoBTag.SecondaryVertex.secondaryVertex_EventSetup_cff")
200 process.load(
"RecoBTag.SoftLepton.softLepton_EventSetup_cff")
201 process.load(
"RecoBTag.Combined.combinedMVA_EventSetup_cff")
202 process.load(
"RecoBTag.CTagging.cTagging_EventSetup_cff")
208 print "-------------------------------------------------------------------"
209 print " Warning: For a complete switch to the legacy tight b-tag track"
210 print " selection, please also enable the \'runIVF\' switch."
211 print "-------------------------------------------------------------------"
213 print "-------------------------------------------------------------------"
214 print " Warning: With the tight b-tag track selection enabled, it is"
215 print " advisable to set \'btagPrefix\' to a non-empty string to"
216 print " avoid unintentional modifications to the default"
217 print " b tagging setup that might be loaded in the same job."
218 print "-------------------------------------------------------------------"
222 svSourceCvsL = copy.deepcopy(svSource)
223 svSourceCvsL.setModuleLabel(svSource.getModuleLabel()+
'CvsL')
226 runIVFforCTagOnly =
False
227 ivfcTagInfos = [
'pfInclusiveSecondaryVertexFinderCvsLTagInfos',
'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos']
229 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices' and any(i
in requiredTagInfos
for i
in ivfcTagInfos)
and not runIVF:
230 runIVFforCTagOnly =
True
232 print "-------------------------------------------------------------------"
233 print " Info: To run c tagging on MiniAOD, c-tag-specific IVF secondary"
234 print " vertices will be remade."
235 print "-------------------------------------------------------------------"
237 if runIVF
and btagPrefix !=
'':
238 if runIVFforCTagOnly:
239 svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
241 svSource.setModuleLabel(btagPrefix+svSource.getModuleLabel())
242 svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
247 acceptedTagInfos =
list()
248 for btagInfo
in requiredTagInfos:
249 if hasattr(btag,btagInfo):
250 if btagInfo ==
'pfImpactParameterTagInfos':
251 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates))
253 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
254 _btagInfo.explicitJTA = cms.bool(explicitJTA)
256 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
257 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
258 _btagInfo.minimumNumberOfHits = cms.int32(8)
259 if btagInfo ==
'pfImpactParameterAK8TagInfos':
260 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfImpactParameterAK8TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates))
262 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
263 _btagInfo.explicitJTA = cms.bool(explicitJTA)
265 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
266 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
267 _btagInfo.minimumNumberOfHits = cms.int32(8)
268 if btagInfo ==
'pfImpactParameterCA15TagInfos':
269 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfImpactParameterCA15TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates))
271 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
272 _btagInfo.explicitJTA = cms.bool(explicitJTA)
274 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
275 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
276 _btagInfo.minimumNumberOfHits = cms.int32(8)
277 if btagInfo ==
'pfSecondaryVertexTagInfos':
278 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfSecondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)))
280 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
281 _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
282 _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
283 if btagInfo ==
'pfInclusiveSecondaryVertexFinderTagInfos':
284 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix), extSVCollection=svSource))
285 if svClustering
or fatJets != cms.InputTag(
''):
286 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
287 if btagInfo ==
'pfInclusiveSecondaryVertexFinderAK8TagInfos':
288 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterAK8TagInfos'+labelName+postfix), extSVCollection=svSource))
289 if svClustering
or fatJets != cms.InputTag(
''):
290 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
291 if btagInfo ==
'pfBoostedDoubleSVAK8TagInfos':
292 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfBoostedDoubleSVAK8TagInfos.clone(svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderAK8TagInfos'+labelName+postfix)))
293 if btagInfo ==
'pfInclusiveSecondaryVertexFinderCA15TagInfos':
294 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterCA15TagInfos'+labelName+postfix), extSVCollection=svSource))
295 if svClustering
or fatJets != cms.InputTag(
''):
296 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
297 if btagInfo ==
'pfBoostedDoubleSVCA15TagInfos':
298 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfBoostedDoubleSVCA15TagInfos.clone(svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderCA15TagInfos'+labelName+postfix)))
299 if btagInfo ==
'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
300 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix), extSVCollection=svSourceCvsL))
301 if svClustering
or fatJets != cms.InputTag(
''):
302 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
303 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
304 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix), extSVCollection=svSourceCvsL))
305 if svClustering
or fatJets != cms.InputTag(
''):
306 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
307 if btagInfo ==
'pfGhostTrackVertexTagInfos':
308 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfGhostTrackVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)))
309 if btagInfo ==
'pfSecondaryVertexNegativeTagInfos':
310 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfSecondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)))
312 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
313 _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
314 _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
315 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeTagInfos':
316 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix), extSVCollection=svSource))
317 if svClustering
or fatJets != cms.InputTag(
''):
318 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
319 if btagInfo ==
'impactParameterTagInfos':
320 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.impactParameterTagInfos.clone(jetTracks = cms.InputTag(
'jetTracksAssociatorAtVertex'+labelName+postfix), primaryVertex=pvSource))
321 if btagInfo ==
'secondaryVertexTagInfos':
322 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.secondaryVertexTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)))
323 if btagInfo ==
'inclusiveSecondaryVertexFinderTagInfos':
324 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)))
325 if svClustering
or fatJets != cms.InputTag(
''):
326 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
327 if btagInfo ==
'inclusiveSecondaryVertexFinderFilteredTagInfos':
328 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)))
329 if svClustering
or fatJets != cms.InputTag(
''):
330 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
331 if btagInfo ==
'secondaryVertexNegativeTagInfos':
332 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.secondaryVertexNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)))
333 if btagInfo ==
'inclusiveSecondaryVertexFinderNegativeTagInfos':
334 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)))
335 if svClustering
or fatJets != cms.InputTag(
''):
336 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
337 if btagInfo ==
'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos':
338 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)))
339 if svClustering
or fatJets != cms.InputTag(
''):
340 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
341 if btagInfo ==
'softMuonTagInfos':
342 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource))
343 if btagInfo ==
'softPFMuonsTagInfos':
344 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource))
345 if btagInfo ==
'softPFElectronsTagInfos':
346 setattr(process, btagPrefix+btagInfo+labelName+postfix, btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource))
347 acceptedTagInfos.append(btagInfo)
348 elif hasattr(toptag, btagInfo) :
349 acceptedTagInfos.append(btagInfo)
351 print ' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo)
353 acceptedBtagDiscriminators =
list()
354 for btagDiscr
in btagDiscriminators :
355 if hasattr(btag,btagDiscr):
356 setattr(process, btagPrefix+btagDiscr+labelName+postfix, getattr(btag, btagDiscr).
clone(tagInfos = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix)
for x
in supportedBtagDiscr[btagDiscr][0] ] )))
357 acceptedBtagDiscriminators.append(btagDiscr)
359 print ' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr)
361 patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix)
for x
in acceptedTagInfos ] )
362 patJets.discriminatorSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix)
for x
in acceptedBtagDiscriminators ] )
363 if len(acceptedBtagDiscriminators) > 0 :
364 patJets.addBTagInfo =
True
367 if not tightBTagNTkHits:
368 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
373 ivfbTagInfos = [
'pfInclusiveSecondaryVertexFinderTagInfos',
'pfInclusiveSecondaryVertexFinderAK8TagInfos',
'pfInclusiveSecondaryVertexFinderCA15TagInfos']
374 if any(i
in acceptedTagInfos
for i
in ivfbTagInfos)
and not runIVFforCTagOnly:
375 if not hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
376 loadWithPrefix(process,
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix)
378 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
379 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinder')
380 _temp.minHits = cms.uint32(8)
382 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
383 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
384 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinder')
385 _temp.primaryVertices = pvSource
386 _temp.tracks = pfCandidates
387 if hasattr( process, btagPrefix+
'candidateVertexArbitrator' ):
388 _temp = getattr(process, btagPrefix+
'candidateVertexArbitrator')
389 _temp.primaryVertices = pvSource
390 _temp.tracks = pfCandidates
391 if hasattr( process, btagPrefix+
'inclusiveCandidateSecondaryVertices' )
and not hasattr( process, svSource.getModuleLabel() ):
392 setattr(process, svSource.getModuleLabel(), getattr(process, btagPrefix+
'inclusiveCandidateSecondaryVertices').
clone() )
393 if any(i
in acceptedTagInfos
for i
in ivfcTagInfos):
394 if not hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
395 loadWithPrefix(process,
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix)
397 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
398 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL')
399 _temp.minHits = cms.uint32(8)
401 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
402 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
403 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL')
404 _temp.primaryVertices = pvSource
405 _temp.tracks = pfCandidates
406 if hasattr( process, btagPrefix+
'candidateVertexArbitratorCvsL' ):
407 _temp = getattr(process, btagPrefix+
'candidateVertexArbitratorCvsL')
408 _temp.primaryVertices = pvSource
409 _temp.tracks = pfCandidates
410 if hasattr( process, btagPrefix+
'inclusiveCandidateSecondaryVerticesCvsL' )
and not hasattr( process, svSourceCvsL.getModuleLabel() ):
411 setattr(process, svSourceCvsL.getModuleLabel(), getattr(process, btagPrefix+
'inclusiveCandidateSecondaryVerticesCvsL').
clone() )
412 if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
413 if not hasattr( process,
'inclusiveVertexing' ):
414 process.load(
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
415 if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
416 if not hasattr( process,
'inclusiveVertexing' ):
417 process.load(
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
418 if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
419 if not hasattr( process,
'inclusiveSecondaryVerticesFiltered' ):
420 process.load(
'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
421 if not hasattr( process,
'bToCharmDecayVertexMerged' ):
422 process.load(
'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
423 if 'caTopTagInfos' in acceptedTagInfos :
424 patJets.addTagInfos =
True
425 if not hasattr( process,
'caTopTagInfos' )
and not hasattr( process,
'caTopTagInfosAK8' ):
426 process.load(
'RecoJets.JetProducers.caTopTaggers_cff' )