271 algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
276 discriminators = set(btagDiscriminators)
277 present_metaSet = discriminators.intersection(set(supportedMetaDiscr.keys()))
278 discriminators -= present_metaSet
279 for meta_tagger
in present_metaSet:
280 for src
in supportedMetaDiscr[meta_tagger]:
281 discriminators.add(src)
282 present_meta = sorted(present_metaSet)
283 btagDiscriminators = sorted(discriminators)
287 requiredTagInfos = list(btagInfos)
288 for btagDiscr
in btagDiscriminators :
289 for tagInfoList
in supportedBtagDiscr[btagDiscr] :
290 for requiredTagInfo
in tagInfoList :
291 tagInfoCovered =
False 292 for tagInfo
in requiredTagInfos :
293 if requiredTagInfo == tagInfo :
294 tagInfoCovered =
True 296 if not tagInfoCovered :
297 requiredTagInfos.append(requiredTagInfo)
299 if hasattr( process,
'candidateJetProbabilityComputer' ) ==
False :
301 process.load(
"RecoBTag.ImpactParameter.impactParameter_cff")
302 task.add(process.impactParameterTask)
303 process.load(
"RecoBTag.SecondaryVertex.secondaryVertex_cff")
304 task.add(process.secondaryVertexTask)
305 process.load(
"RecoBTag.SoftLepton.softLepton_cff")
306 task.add(process.softLeptonTask)
307 process.load(
"RecoBTag.Combined.combinedMVA_cff")
308 task.add(process.combinedMVATask)
309 process.load(
"RecoBTag.CTagging.cTagging_cff")
310 task.add(process.cTaggingTask)
312 process.load(
"RecoBTag.ImpactParameter.impactParameter_EventSetup_cff")
313 process.load(
"RecoBTag.SecondaryVertex.secondaryVertex_EventSetup_cff")
314 process.load(
"RecoBTag.SoftLepton.softLepton_EventSetup_cff")
315 process.load(
"RecoBTag.Combined.combinedMVA_EventSetup_cff")
316 process.load(
"RecoBTag.CTagging.cTagging_EventSetup_cff")
318 import RecoJets.JetProducers.caTopTaggers_cff
as toptag
322 sys.stderr.write(
"-------------------------------------------------------------------\n")
323 sys.stderr.write(
" Warning: For a complete switch to the legacy tight b-tag track\n")
324 sys.stderr.write(
" selection, please also enable the \'runIVF\' switch.\n")
325 sys.stderr.write(
"-------------------------------------------------------------------\n")
327 sys.stderr.write(
"-------------------------------------------------------------------\n")
328 sys.stderr.write(
" Warning: With the tight b-tag track selection enabled, it is\n")
329 sys.stderr.write(
" advisable to set \'btagPrefix\' to a non-empty string to\n")
330 sys.stderr.write(
" avoid unintentional modifications to the default\n")
331 sys.stderr.write(
" b tagging setup that might be loaded in the same job.\n")
332 sys.stderr.write(
"-------------------------------------------------------------------\n")
336 svSourceCvsL = copy.deepcopy(svSource)
337 svSourceCvsL.setModuleLabel(svSource.getModuleLabel()+
'CvsL')
340 runIVFforCTagOnly =
False 341 ivfcTagInfos = [
'pfInclusiveSecondaryVertexFinderCvsLTagInfos',
'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos']
343 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices' and any(i
in requiredTagInfos
for i
in ivfcTagInfos)
and not runIVF:
344 runIVFforCTagOnly =
True 346 sys.stderr.write(
"-------------------------------------------------------------------\n")
347 sys.stderr.write(
" Info: To run c tagging on MiniAOD, c-tag-specific IVF secondary\n")
348 sys.stderr.write(
" vertices will be remade.\n")
349 sys.stderr.write(
"-------------------------------------------------------------------\n")
351 if runIVF
and btagPrefix !=
'':
352 if runIVFforCTagOnly:
353 svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
355 svSource.setModuleLabel(btagPrefix+svSource.getModuleLabel())
356 svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
362 runNegativeVertexing =
False 363 runNegativeCvsLVertexing =
False 364 for btagInfo
in requiredTagInfos:
366 'pfInclusiveSecondaryVertexFinderNegativeTagInfos',
367 'pfNegativeDeepFlavourTagInfos',
368 'pfNegativeParticleNetAK4TagInfos',
370 runNegativeVertexing =
True 371 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
372 runNegativeCvsLVertexing =
True 374 if runNegativeVertexing
or runNegativeCvsLVertexing:
375 import RecoVertex.AdaptiveVertexFinder.inclusiveNegativeVertexing_cff
as NegVertex
377 if runNegativeVertexing:
379 NegVertex.inclusiveCandidateNegativeVertexFinder.clone(primaryVertices = pvSource,tracks=pfCandidates),
382 NegVertex.candidateNegativeVertexMerger.clone(secondaryVertices = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeVertexFinder'+labelName+postfix)),
385 NegVertex.candidateNegativeVertexArbitrator.clone( secondaryVertices = cms.InputTag(btagPrefix+
'candidateNegativeVertexMerger'+labelName+postfix)
386 ,primaryVertices = pvSource
387 ,tracks=pfCandidates),
389 addToProcessAndTask(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix,
390 NegVertex.inclusiveCandidateNegativeSecondaryVertices.clone(secondaryVertices = cms.InputTag(btagPrefix+
'candidateNegativeVertexArbitrator'+labelName+postfix)),
393 if runNegativeCvsLVertexing:
394 addToProcessAndTask(btagPrefix+
'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix,
395 NegVertex.inclusiveCandidateNegativeVertexFinderCvsL.clone(primaryVertices = pvSource,tracks=pfCandidates),
398 NegVertex.candidateNegativeVertexMergerCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix)),
401 NegVertex.candidateNegativeVertexArbitratorCvsL.clone( secondaryVertices = cms.InputTag(btagPrefix+
'candidateNegativeVertexMergerCvsL'+labelName+postfix)
402 ,primaryVertices = pvSource
403 ,tracks=pfCandidates),
405 addToProcessAndTask(btagPrefix+
'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix,
406 NegVertex.inclusiveCandidateNegativeSecondaryVerticesCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+
'candidateNegativeVertexArbitratorCvsL'+labelName+postfix)),
410 acceptedTagInfos = list()
411 for btagInfo
in requiredTagInfos:
412 if hasattr(btag,btagInfo):
413 if btagInfo ==
'pfImpactParameterTagInfos':
415 btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
418 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
419 _btagInfo.explicitJTA = cms.bool(explicitJTA)
421 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
422 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
423 _btagInfo.minimumNumberOfHits = cms.int32(8)
424 if btagInfo ==
'pfImpactParameterAK8TagInfos':
426 btag.pfImpactParameterAK8TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
429 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
430 _btagInfo.explicitJTA = cms.bool(explicitJTA)
432 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
433 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
434 _btagInfo.minimumNumberOfHits = cms.int32(8)
435 if btagInfo ==
'pfImpactParameterCA15TagInfos':
437 btag.pfImpactParameterCA15TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
440 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
441 _btagInfo.explicitJTA = cms.bool(explicitJTA)
443 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
444 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
445 _btagInfo.minimumNumberOfHits = cms.int32(8)
446 if btagInfo ==
'pfSecondaryVertexTagInfos':
448 btag.pfSecondaryVertexTagInfos.clone(
449 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)),
452 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
453 _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
454 _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
455 if btagInfo ==
'pfDeepCSVTagInfos':
457 btag.pfDeepCSVTagInfos.clone(
458 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
460 if svClustering
or fatJets != cms.InputTag(
''):
461 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
462 if btagInfo ==
'pfDeepCSVNegativeTagInfos':
464 btag.pfDeepCSVNegativeTagInfos.clone(
465 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderNegativeTagInfos'+labelName+postfix)),
467 if svClustering
or fatJets != cms.InputTag(
''):
468 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
469 if btagInfo ==
'pfDeepCSVPositiveTagInfos':
471 btag.pfDeepCSVPositiveTagInfos.clone(
472 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
474 if svClustering
or fatJets != cms.InputTag(
''):
475 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
476 if btagInfo ==
'pfDeepCMVATagInfos':
478 btag.pfDeepCMVATagInfos.clone(
479 deepNNTagInfos = cms.InputTag(btagPrefix+
'pfDeepCSVTagInfos'+labelName+postfix),
480 ipInfoSrc = cms.InputTag(btagPrefix+
"pfImpactParameterTagInfos"+labelName+postfix),
481 muInfoSrc = cms.InputTag(btagPrefix+
"softPFMuonsTagInfos"+labelName+postfix),
482 elInfoSrc = cms.InputTag(btagPrefix+
"softPFElectronsTagInfos"+labelName+postfix)),
484 if svClustering
or fatJets != cms.InputTag(
''):
485 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
486 if btagInfo ==
'pfDeepCMVANegativeTagInfos':
488 btag.pfDeepCMVATagInfos.clone(
489 deepNNTagInfos = cms.InputTag(btagPrefix+
'pfDeepCSVTagInfos'+labelName+postfix),
490 ipInfoSrc = cms.InputTag(btagPrefix+
"pfImpactParameterTagInfos"+labelName+postfix),
491 muInfoSrc = cms.InputTag(btagPrefix+
"softPFMuonsTagInfos"+labelName+postfix),
492 elInfoSrc = cms.InputTag(btagPrefix+
"softPFElectronsTagInfos"+labelName+postfix)),
494 if svClustering
or fatJets != cms.InputTag(
''):
495 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
496 if btagInfo ==
'pfDeepCMVAPositiveTagInfos':
498 btag.pfDeepCMVATagInfos.clone(
499 deepNNTagInfos = cms.InputTag(btagPrefix+
'pfDeepCSVTagInfos'+labelName+postfix),
500 ipInfoSrc = cms.InputTag(btagPrefix+
"pfImpactParameterTagInfos"+labelName+postfix),
501 muInfoSrc = cms.InputTag(btagPrefix+
"softPFMuonsTagInfos"+labelName+postfix),
502 elInfoSrc = cms.InputTag(btagPrefix+
"softPFElectronsTagInfos"+labelName+postfix)),
504 if svClustering
or fatJets != cms.InputTag(
''):
505 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
506 if btagInfo ==
'pfInclusiveSecondaryVertexFinderTagInfos':
508 btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
509 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
510 extSVCollection=svSource),
512 if svClustering
or fatJets != cms.InputTag(
''):
513 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
514 if btagInfo ==
'pfInclusiveSecondaryVertexFinderAK8TagInfos':
516 btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(
517 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterAK8TagInfos'+labelName+postfix),
518 extSVCollection=svSource),
520 if svClustering
or fatJets != cms.InputTag(
''):
521 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
522 if btagInfo ==
'pfBoostedDoubleSVAK8TagInfos':
524 btag.pfBoostedDoubleSVAK8TagInfos.clone(
525 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderAK8TagInfos'+labelName+postfix)),
527 if btagInfo ==
'pfInclusiveSecondaryVertexFinderCA15TagInfos':
529 btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(
530 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterCA15TagInfos'+labelName+postfix),
531 extSVCollection=svSource),
533 if svClustering
or fatJets != cms.InputTag(
''):
534 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
535 if btagInfo ==
'pfBoostedDoubleSVCA15TagInfos':
537 btag.pfBoostedDoubleSVCA15TagInfos.clone(
538 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderCA15TagInfos'+labelName+postfix)),
540 if btagInfo ==
'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
542 btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone(
543 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
544 extSVCollection=svSourceCvsL),
546 if svClustering
or fatJets != cms.InputTag(
''):
547 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
548 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
550 btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(
551 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
552 extSVCollection = btagPrefix+
'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix),
554 if svClustering
or fatJets != cms.InputTag(
''):
555 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
556 if btagInfo ==
'pfGhostTrackVertexTagInfos':
558 btag.pfGhostTrackVertexTagInfos.clone(
559 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)),
561 if btagInfo ==
'pfSecondaryVertexNegativeTagInfos':
563 btag.pfSecondaryVertexNegativeTagInfos.clone(
564 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)),
567 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
568 _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
569 _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
570 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeTagInfos':
572 btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(
573 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
574 extSVCollection=cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)),
576 if svClustering
or fatJets != cms.InputTag(
''):
577 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
578 if btagInfo ==
'impactParameterTagInfos':
580 btag.impactParameterTagInfos.clone(
581 jetTracks = cms.InputTag(
'jetTracksAssociatorAtVertex'+labelName+postfix),
582 primaryVertex=pvSource),
584 if btagInfo ==
'secondaryVertexTagInfos':
586 btag.secondaryVertexTagInfos.clone(
587 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
589 if btagInfo ==
'inclusiveSecondaryVertexFinderTagInfos':
591 btag.inclusiveSecondaryVertexFinderTagInfos.clone(
592 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
594 if svClustering
or fatJets != cms.InputTag(
''):
595 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
596 if btagInfo ==
'inclusiveSecondaryVertexFinderFilteredTagInfos':
598 btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(
599 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
601 if svClustering
or fatJets != cms.InputTag(
''):
602 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
603 if btagInfo ==
'secondaryVertexNegativeTagInfos':
605 btag.secondaryVertexNegativeTagInfos.clone(
606 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
608 if btagInfo ==
'inclusiveSecondaryVertexFinderNegativeTagInfos':
610 btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(
611 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
613 if svClustering
or fatJets != cms.InputTag(
''):
614 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
615 if btagInfo ==
'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos':
617 btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(
618 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
620 if svClustering
or fatJets != cms.InputTag(
''):
621 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
622 if btagInfo ==
'softMuonTagInfos':
624 btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource),
626 if btagInfo ==
'softPFMuonsTagInfos':
628 btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource),
630 if btagInfo ==
'softPFElectronsTagInfos':
632 btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource),
634 if btagInfo ==
'pixelClusterTagInfos':
636 btag.pixelClusterTagInfos.clone(jets = jetSource, vertices=pvSource),
641 if 'pfBoostedDouble' in btagInfo
or 'SecondaryVertex' in btagInfo:
642 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
643 if pfCandidates.value() ==
'packedPFCandidates':
645 _btagInfo.weights = cms.InputTag(packedPFPuppiLabel)
647 _btagInfo.weights = cms.InputTag(
"puppi")
649 if 'DeepFlavourTagInfos' in btagInfo:
651 if btagInfo ==
'pfNegativeDeepFlavourTagInfos':
652 deep_csv_tag_infos =
'pfDeepCSVNegativeTagInfos' 653 svUsed = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
656 deep_csv_tag_infos =
'pfDeepCSVTagInfos' 661 if pfCandidates.value() ==
'packedPFCandidates':
663 vertex_associator = cms.InputTag(
"")
665 puppi_value_map = cms.InputTag(
"puppi")
666 vertex_associator = cms.InputTag(
"primaryVertexAssociation",
"original")
669 is_weighted_jet =
False 670 if (
'puppi' in jetSource.value().lower()):
671 is_weighted_jet =
True 673 btag.pfDeepFlavourTagInfos.clone(
676 secondary_vertices=svUsed,
677 shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
678 puppi_value_map = puppi_value_map,
679 vertex_associator = vertex_associator,
680 is_weighted_jet = is_weighted_jet,
684 if (
'ParticleTransformerAK4TagInfos' in btagInfo)
and (
'UnifiedParticleTransformerAK4TagInfos' not in btagInfo):
686 if btagInfo ==
'pfNegativeParticleTransformerAK4TagInfos':
687 svUsed, flip, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix),
True, 10.
689 svUsed, flip, max_sip3dsig_for_flip = svSource,
False, -1.
692 if pfCandidates.value() ==
'packedPFCandidates':
694 vertex_associator = cms.InputTag(
"")
696 puppi_value_map = cms.InputTag(
"puppi")
697 vertex_associator = cms.InputTag(
"primaryVertexAssociation",
"original")
700 is_weighted_jet =
False 701 if (
'puppi' in jetSource.value().lower()):
702 is_weighted_jet =
True 704 btag.pfParticleTransformerAK4TagInfos.clone(
707 secondary_vertices=svUsed,
708 puppi_value_map = puppi_value_map,
709 vertex_associator = vertex_associator,
710 is_weighted_jet = is_weighted_jet,
712 max_sip3dsig_for_flip=max_sip3dsig_for_flip),
715 if 'UnifiedParticleTransformerAK4TagInfos' in btagInfo:
717 if btagInfo ==
'pfNegativeUnifiedParticleTransformerAK4TagInfos':
718 svUsed = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
724 if pfCandidates.value() ==
'packedPFCandidates':
726 vertex_associator = cms.InputTag(
"")
728 puppi_value_map = cms.InputTag(
"puppi")
729 vertex_associator = cms.InputTag(
"primaryVertexAssociation",
"original")
732 is_weighted_jet =
False 733 if (
'puppi' in jetSource.value().lower()):
734 is_weighted_jet =
True 736 btag.pfUnifiedParticleTransformerAK4TagInfos.clone(
739 secondary_vertices=svUsed,
740 puppi_value_map = puppi_value_map,
741 vertex_associator = vertex_associator,
742 is_weighted_jet = is_weighted_jet,
746 if btagInfo ==
'pfDeepDoubleXTagInfos':
748 if 'updated' not in jetSource.value().lower():
749 raise ValueError(
"Invalid jet collection: %s. pfDeepDoubleXTagInfos only supports running via updateJetCollection." % jetSource.value())
751 puppi_value_map = cms.InputTag(packedPFPuppiLabel)
753 btag.pfDeepDoubleXTagInfos.clone(
756 secondary_vertices=svSource,
757 shallow_tag_infos = cms.InputTag(btagPrefix+
'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
758 puppi_value_map = puppi_value_map,
761 if btagInfo ==
'pfHiggsInteractionNetTagInfos':
763 puppi_value_map = cms.InputTag(packedPFPuppiLabel)
765 btag.pfHiggsInteractionNetTagInfos.clone(
768 secondary_vertices = svSource,
769 pf_candidates = pfCandidates,
770 puppi_value_map = puppi_value_map
774 if btagInfo ==
'pfDeepBoostedJetTagInfos':
775 if pfCandidates.value() ==
'packedPFCandidates':
777 if 'updated' not in jetSource.value().lower():
778 raise ValueError(
"Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
780 vertex_associator =
"" 781 elif pfCandidates.value() ==
'particleFlow':
782 raise ValueError(
"Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
789 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
791 btag.pfDeepBoostedJetTagInfos.clone(
794 secondary_vertices = svSource,
795 pf_candidates = pfCandidates,
796 puppi_value_map = puppi_value_map,
797 vertex_associator = vertex_associator,
801 if btagInfo ==
'pfParticleNetTagInfos':
802 if pfCandidates.value() ==
'packedPFCandidates':
805 vertex_associator =
"" 806 elif pfCandidates.value() ==
'particleFlow':
807 raise ValueError(
"Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
809 puppi_value_map =
"puppi" 810 vertex_associator =
"primaryVertexAssociation:original" 812 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
814 btag.pfParticleNetTagInfos.clone(
817 secondary_vertices = svSource,
818 pf_candidates = pfCandidates,
819 puppi_value_map = puppi_value_map,
820 vertex_associator = vertex_associator,
824 if 'ParticleNetAK4TagInfos' in btagInfo:
825 if btagInfo ==
'pfNegativeParticleNetAK4TagInfos':
826 secondary_vertices = btagPrefix + \
827 'inclusiveCandidateNegativeSecondaryVertices' + labelName + postfix
831 secondary_vertices = svSource
834 if pfCandidates.value() ==
'packedPFCandidates':
837 vertex_associator =
"" 838 elif pfCandidates.value() ==
'particleFlow':
839 raise ValueError(
"Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
841 puppi_value_map =
"puppi" 842 vertex_associator =
"primaryVertexAssociation:original" 844 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
847 if "puppi" in jetSource.value().lower():
850 btag.pfParticleNetAK4TagInfos.clone(
853 secondary_vertices = secondary_vertices,
854 pf_candidates = pfCandidates,
855 puppi_value_map = puppi_value_map,
856 vertex_associator = vertex_associator,
857 flip_ip_sign = flip_ip_sign,
858 sip3dSigMax = sip3dSigMax,
859 use_puppiP4 = use_puppiP4
863 acceptedTagInfos.append(btagInfo)
864 elif hasattr(toptag, btagInfo) :
865 acceptedTagInfos.append(btagInfo)
866 elif btagInfo ==
'pfParticleNetFromMiniAODAK4PuppiCentralTagInfos' or btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4PuppiCentralTagInfos':
868 if btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4PuppiCentralTagInfos':
869 svUsed, flip_ip_sign, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix),
True, 10.
871 svUsed, flip_ip_sign, max_sip3dsig_for_flip = svSource,
False, -1.
872 if pfCandidates.value() !=
'packedPFCandidates':
873 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
875 pfParticleNetFromMiniAODAK4PuppiCentralTagInfos.clone(
878 secondary_vertices = svUsed,
879 pf_candidates = pfCandidates,
880 flip_ip_sign = flip_ip_sign,
881 max_sip3dsig_for_flip = max_sip3dsig_for_flip,
884 acceptedTagInfos.append(btagInfo)
885 elif btagInfo ==
'pfParticleNetFromMiniAODAK4PuppiForwardTagInfos':
887 if pfCandidates.value() !=
'packedPFCandidates':
888 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
890 pfParticleNetFromMiniAODAK4PuppiForwardTagInfos.clone(
893 secondary_vertices = svSource,
894 pf_candidates = pfCandidates,
897 acceptedTagInfos.append(btagInfo)
898 elif btagInfo ==
'pfParticleNetFromMiniAODAK4CHSCentralTagInfos' or btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4PuppiForwardTagInfos':
900 if btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4PuppiForwardTagInfos':
901 svUsed, flip_ip_sign, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix),
True, 10.
903 svUsed, flip_ip_sign, max_sip3dsig_for_flip = svSource,
False, -1.
904 if pfCandidates.value() !=
'packedPFCandidates':
905 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
907 pfParticleNetFromMiniAODAK4CHSCentralTagInfos.clone(
910 secondary_vertices = svUsed,
911 pf_candidates = pfCandidates,
912 flip_ip_sign = flip_ip_sign,
913 max_sip3dsig_for_flip = max_sip3dsig_for_flip,
916 acceptedTagInfos.append(btagInfo)
917 elif btagInfo ==
'pfParticleNetFromMiniAODAK4CHSForwardTagInfos':
919 if pfCandidates.value() !=
'packedPFCandidates':
920 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
922 pfParticleNetFromMiniAODAK4CHSForwardTagInfos.clone(
925 secondary_vertices = svSource,
926 pf_candidates = pfCandidates,
929 acceptedTagInfos.append(btagInfo)
930 elif btagInfo ==
'pfParticleNetFromMiniAODAK8TagInfos':
932 if pfCandidates.value() !=
'packedPFCandidates':
933 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
935 pfParticleNetFromMiniAODAK8TagInfos.clone(
938 secondary_vertices = svSource,
939 pf_candidates = pfCandidates,
942 acceptedTagInfos.append(btagInfo)
944 print(
' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
946 acceptedBtagDiscriminators = list()
947 for discriminator_name
in btagDiscriminators :
948 btagDiscr = discriminator_name.split(
':')[0]
950 newDiscr = btagPrefix+btagDiscr+labelName+postfix
951 if hasattr(btag,btagDiscr):
952 if hasattr(process, newDiscr):
954 elif hasattr(getattr(btag, btagDiscr),
'tagInfos'):
957 getattr(btag, btagDiscr).
clone(
958 tagInfos = cms.VInputTag(
959 *[ cms.InputTag(btagPrefix+x+labelName+postfix) \
960 for x
in supportedBtagDiscr[discriminator_name][0] ]
966 elif hasattr(getattr(btag, btagDiscr),
'src'):
969 getattr(btag, btagDiscr).
clone(
970 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
976 raise ValueError(
'I do not know how to update %s it does not have neither "tagInfos" nor "src" attributes' % btagDiscr)
977 acceptedBtagDiscriminators.append(discriminator_name)
978 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiCentralJetTags':
979 if hasattr(process, newDiscr):
983 pfParticleNetFromMiniAODAK4PuppiCentralJetTags.clone(
984 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
989 acceptedBtagDiscriminators.append(discriminator_name)
990 elif btagDiscr==
'pfNegativeParticleNetFromMiniAODAK4PuppiCentralJetTags':
991 if hasattr(process, newDiscr):
995 pfNegativeParticleNetFromMiniAODAK4PuppiCentralJetTags.clone(
996 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1001 acceptedBtagDiscriminators.append(discriminator_name)
1002 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiForwardJetTags':
1003 if hasattr(process, newDiscr):
1007 pfParticleNetFromMiniAODAK4PuppiForwardJetTags.clone(
1008 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1013 acceptedBtagDiscriminators.append(discriminator_name)
1014 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSCentralJetTags':
1015 if hasattr(process, newDiscr):
1019 pfParticleNetFromMiniAODAK4CHSCentralJetTags.clone(
1020 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1025 acceptedBtagDiscriminators.append(discriminator_name)
1026 elif btagDiscr==
'pfNegativeParticleNetFromMiniAODAK4CHSCentralJetTags':
1027 if hasattr(process, newDiscr):
1031 pfNegativeParticleNetFromMiniAODAK4CHSCentralJetTags.clone(
1032 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1037 acceptedBtagDiscriminators.append(discriminator_name)
1038 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSForwardJetTags':
1039 if hasattr(process, newDiscr):
1043 pfParticleNetFromMiniAODAK4CHSForwardJetTags.clone(
1044 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1049 acceptedBtagDiscriminators.append(discriminator_name)
1050 elif btagDiscr==
'pfParticleNetFromMiniAODAK8JetTags':
1051 if hasattr(process, newDiscr):
1055 pfParticleNetFromMiniAODAK8JetTags.clone(
1056 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1061 acceptedBtagDiscriminators.append(discriminator_name)
1063 print(
' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
1066 for meta_tagger
in present_meta:
1067 btagDiscr = meta_tagger.split(
':')[0]
1069 newDiscr = btagPrefix+btagDiscr+labelName+postfix
1070 if hasattr(btag,btagDiscr):
1071 if hasattr(process, newDiscr):
1076 getattr(btag, btagDiscr).
clone(),
1080 for dependency
in supportedMetaDiscr[meta_tagger]:
1081 if ':' in dependency:
1082 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1084 new_dep = btagPrefix+dependency+labelName+postfix
1085 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1086 replace.doIt(getattr(process, newDiscr), newDiscr)
1087 acceptedBtagDiscriminators.append(meta_tagger)
1088 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags':
1089 if hasattr(process, newDiscr):
1094 pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags.clone(),
1098 for dependency
in supportedMetaDiscr[meta_tagger]:
1099 if ':' in dependency:
1100 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1102 new_dep = btagPrefix+dependency+labelName+postfix
1103 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1104 replace.doIt(getattr(process, newDiscr), newDiscr)
1105 acceptedBtagDiscriminators.append(meta_tagger)
1106 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiForwardDiscriminatorsJetTags':
1107 if hasattr(process, newDiscr):
1112 pfParticleNetFromMiniAODAK4PuppiForwardDiscriminatorsJetTags.clone(),
1116 for dependency
in supportedMetaDiscr[meta_tagger]:
1117 if ':' in dependency:
1118 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1120 new_dep = btagPrefix+dependency+labelName+postfix
1121 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1122 replace.doIt(getattr(process, newDiscr), newDiscr)
1123 acceptedBtagDiscriminators.append(meta_tagger)
1124 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags':
1125 if hasattr(process, newDiscr):
1130 pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags.clone(),
1134 for dependency
in supportedMetaDiscr[meta_tagger]:
1135 if ':' in dependency:
1136 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1138 new_dep = btagPrefix+dependency+labelName+postfix
1139 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1140 replace.doIt(getattr(process, newDiscr), newDiscr)
1141 acceptedBtagDiscriminators.append(meta_tagger)
1142 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSForwardDiscriminatorsJetTags':
1143 if hasattr(process, newDiscr):
1148 pfParticleNetFromMiniAODAK4CHSForwardDiscriminatorsJetTags.clone(),
1152 for dependency
in supportedMetaDiscr[meta_tagger]:
1153 if ':' in dependency:
1154 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1156 new_dep = btagPrefix+dependency+labelName+postfix
1157 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1158 replace.doIt(getattr(process, newDiscr), newDiscr)
1159 acceptedBtagDiscriminators.append(meta_tagger)
1160 elif btagDiscr==
'pfParticleNetFromMiniAODAK8DiscriminatorsJetTags':
1161 if hasattr(process, newDiscr):
1166 pfParticleNetFromMiniAODAK8DiscriminatorsJetTags.clone(),
1170 for dependency
in supportedMetaDiscr[meta_tagger]:
1171 if ':' in dependency:
1172 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1174 new_dep = btagPrefix+dependency+labelName+postfix
1175 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1176 replace.doIt(getattr(process, newDiscr), newDiscr)
1177 acceptedBtagDiscriminators.append(meta_tagger)
1180 print(
' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
1183 patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix)
for x
in acceptedTagInfos ] )
1184 patJets.discriminatorSources = cms.VInputTag(*[
1185 cms.InputTag(btagPrefix+x+labelName+postfix) \
1186 if ':' not in x
else \
1187 cms.InputTag(btagPrefix+x.split(
':')[0]+labelName+postfix+
':'+x.split(
':')[1]) \
1188 for x
in acceptedBtagDiscriminators
1190 if len(acceptedBtagDiscriminators) > 0 :
1191 patJets.addBTagInfo =
True 1194 if not tightBTagNTkHits:
1195 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
1200 ivfbTagInfos = [
'pfInclusiveSecondaryVertexFinderTagInfos',
'pfInclusiveSecondaryVertexFinderAK8TagInfos',
'pfInclusiveSecondaryVertexFinderCA15TagInfos']
1201 if any(i
in acceptedTagInfos
for i
in ivfbTagInfos)
and not runIVFforCTagOnly:
1202 if not hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
1203 loadWithPrefix(process,
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
1204 if tightBTagNTkHits:
1205 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
1206 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinder')
1207 _temp.minHits = cms.uint32(8)
1209 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
1210 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
1211 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinder')
1212 _temp.primaryVertices = pvSource
1213 _temp.tracks = pfCandidates
1214 if hasattr( process, btagPrefix+
'candidateVertexArbitrator' ):
1215 _temp = getattr(process, btagPrefix+
'candidateVertexArbitrator')
1216 _temp.primaryVertices = pvSource
1217 _temp.tracks = pfCandidates
1218 if hasattr( process, btagPrefix+
'inclusiveCandidateSecondaryVertices' )
and not hasattr( process, svSource.getModuleLabel() ):
1220 getattr(process, btagPrefix+
'inclusiveCandidateSecondaryVertices').
clone(),
1222 if any(i
in acceptedTagInfos
for i
in ivfcTagInfos):
1223 if not hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
1224 loadWithPrefix(process,
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
1225 if tightBTagNTkHits:
1226 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
1227 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL')
1228 _temp.minHits = cms.uint32(8)
1230 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
1231 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
1232 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL')
1233 _temp.primaryVertices = pvSource
1234 _temp.tracks = pfCandidates
1235 if hasattr( process, btagPrefix+
'candidateVertexArbitratorCvsL' ):
1236 _temp = getattr(process, btagPrefix+
'candidateVertexArbitratorCvsL')
1237 _temp.primaryVertices = pvSource
1238 _temp.tracks = pfCandidates
1239 if hasattr( process, btagPrefix+
'inclusiveCandidateSecondaryVerticesCvsL' )
and not hasattr( process, svSourceCvsL.getModuleLabel() ):
1241 getattr(process, btagPrefix+
'inclusiveCandidateSecondaryVerticesCvsL').
clone(),
1243 if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
1244 if not hasattr( process,
'inclusiveVertexing' ):
1245 process.load(
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
1246 task.add(process.inclusiveVertexingTask)
1247 task.add(process.inclusiveCandidateVertexingTask)
1248 task.add(process.inclusiveCandidateVertexingCvsLTask)
1249 if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
1250 if not hasattr( process,
'inclusiveVertexing' ):
1251 process.load(
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
1252 task.add(process.inclusiveVertexingTask)
1253 task.add(process.inclusiveCandidateVertexingTask)
1254 task.add(process.inclusiveCandidateVertexingCvsLTask)
1255 if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
1256 if not hasattr( process,
'inclusiveSecondaryVerticesFiltered' ):
1257 process.load(
'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
1258 task.add(process.inclusiveSecondaryVerticesFiltered)
1259 task.add(process.bVertexFilter)
1260 if not hasattr( process,
'bToCharmDecayVertexMerged' ):
1261 process.load(
'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
1262 task.add(process.bToCharmDecayVertexMerged)
1263 if 'caTopTagInfos' in acceptedTagInfos :
1264 patJets.addTagInfos =
True 1265 if not hasattr( process,
'caTopTagInfos' )
and not hasattr( process,
'caTopTagInfosAK8' ):
1266 process.load(
'RecoJets.JetProducers.caTopTaggers_cff' )
1267 task.add(process.caTopTaggersTask)
bool any(const std::vector< T > &v, const T &what)
def addToProcessAndTask(label, module, process, task)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def loadWithPrefix(process, moduleName, prefix='', loadedProducersAndFilters=None)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
def getPatAlgosToolsTask(process)