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)),
411 puppi_value_map =
"puppi" 412 if pfCandidates.value() ==
'packedPFCandidates':
415 acceptedTagInfos = list()
416 for btagInfo
in requiredTagInfos:
417 if hasattr(btag,btagInfo):
418 if btagInfo ==
'pfImpactParameterTagInfos':
420 btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
423 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
424 _btagInfo.explicitJTA = cms.bool(explicitJTA)
426 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
427 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
428 _btagInfo.minimumNumberOfHits = cms.int32(8)
429 if btagInfo ==
'pfImpactParameterAK8TagInfos':
431 btag.pfImpactParameterAK8TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
434 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
435 _btagInfo.explicitJTA = cms.bool(explicitJTA)
437 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
438 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
439 _btagInfo.minimumNumberOfHits = cms.int32(8)
440 if btagInfo ==
'pfImpactParameterCA15TagInfos':
442 btag.pfImpactParameterCA15TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
445 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
446 _btagInfo.explicitJTA = cms.bool(explicitJTA)
448 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
449 _btagInfo.minimumNumberOfPixelHits = cms.int32(2)
450 _btagInfo.minimumNumberOfHits = cms.int32(8)
451 if btagInfo ==
'pfSecondaryVertexTagInfos':
453 btag.pfSecondaryVertexTagInfos.clone(
454 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)),
457 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
458 _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
459 _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
460 if btagInfo ==
'pfDeepCSVTagInfos':
462 btag.pfDeepCSVTagInfos.clone(
463 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
465 if svClustering
or fatJets != cms.InputTag(
''):
466 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
467 if btagInfo ==
'pfDeepCSVNegativeTagInfos':
469 btag.pfDeepCSVNegativeTagInfos.clone(
470 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderNegativeTagInfos'+labelName+postfix)),
472 if svClustering
or fatJets != cms.InputTag(
''):
473 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
474 if btagInfo ==
'pfDeepCSVPositiveTagInfos':
476 btag.pfDeepCSVPositiveTagInfos.clone(
477 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
479 if svClustering
or fatJets != cms.InputTag(
''):
480 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
481 if btagInfo ==
'pfDeepCMVATagInfos':
483 btag.pfDeepCMVATagInfos.clone(
484 deepNNTagInfos = cms.InputTag(btagPrefix+
'pfDeepCSVTagInfos'+labelName+postfix),
485 ipInfoSrc = cms.InputTag(btagPrefix+
"pfImpactParameterTagInfos"+labelName+postfix),
486 muInfoSrc = cms.InputTag(btagPrefix+
"softPFMuonsTagInfos"+labelName+postfix),
487 elInfoSrc = cms.InputTag(btagPrefix+
"softPFElectronsTagInfos"+labelName+postfix)),
489 if svClustering
or fatJets != cms.InputTag(
''):
490 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
491 if btagInfo ==
'pfDeepCMVANegativeTagInfos':
493 btag.pfDeepCMVATagInfos.clone(
494 deepNNTagInfos = cms.InputTag(btagPrefix+
'pfDeepCSVTagInfos'+labelName+postfix),
495 ipInfoSrc = cms.InputTag(btagPrefix+
"pfImpactParameterTagInfos"+labelName+postfix),
496 muInfoSrc = cms.InputTag(btagPrefix+
"softPFMuonsTagInfos"+labelName+postfix),
497 elInfoSrc = cms.InputTag(btagPrefix+
"softPFElectronsTagInfos"+labelName+postfix)),
499 if svClustering
or fatJets != cms.InputTag(
''):
500 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
501 if btagInfo ==
'pfDeepCMVAPositiveTagInfos':
503 btag.pfDeepCMVATagInfos.clone(
504 deepNNTagInfos = cms.InputTag(btagPrefix+
'pfDeepCSVTagInfos'+labelName+postfix),
505 ipInfoSrc = cms.InputTag(btagPrefix+
"pfImpactParameterTagInfos"+labelName+postfix),
506 muInfoSrc = cms.InputTag(btagPrefix+
"softPFMuonsTagInfos"+labelName+postfix),
507 elInfoSrc = cms.InputTag(btagPrefix+
"softPFElectronsTagInfos"+labelName+postfix)),
509 if svClustering
or fatJets != cms.InputTag(
''):
510 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
511 if btagInfo ==
'pfInclusiveSecondaryVertexFinderTagInfos':
513 btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
514 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
515 extSVCollection=svSource),
517 if svClustering
or fatJets != cms.InputTag(
''):
518 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
519 if btagInfo ==
'pfInclusiveSecondaryVertexFinderAK8TagInfos':
521 btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(
522 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterAK8TagInfos'+labelName+postfix),
523 extSVCollection=svSource),
525 if svClustering
or fatJets != cms.InputTag(
''):
526 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
527 if btagInfo ==
'pfBoostedDoubleSVAK8TagInfos':
529 btag.pfBoostedDoubleSVAK8TagInfos.clone(
530 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderAK8TagInfos'+labelName+postfix)),
532 if btagInfo ==
'pfInclusiveSecondaryVertexFinderCA15TagInfos':
534 btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(
535 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterCA15TagInfos'+labelName+postfix),
536 extSVCollection=svSource),
538 if svClustering
or fatJets != cms.InputTag(
''):
539 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
540 if btagInfo ==
'pfBoostedDoubleSVCA15TagInfos':
542 btag.pfBoostedDoubleSVCA15TagInfos.clone(
543 svTagInfos = cms.InputTag(btagPrefix+
'pfInclusiveSecondaryVertexFinderCA15TagInfos'+labelName+postfix)),
545 if btagInfo ==
'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
547 btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone(
548 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
549 extSVCollection=svSourceCvsL),
551 if svClustering
or fatJets != cms.InputTag(
''):
552 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
553 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
555 btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(
556 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
557 extSVCollection = btagPrefix+
'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix),
559 if svClustering
or fatJets != cms.InputTag(
''):
560 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
561 if btagInfo ==
'pfGhostTrackVertexTagInfos':
563 btag.pfGhostTrackVertexTagInfos.clone(
564 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)),
566 if btagInfo ==
'pfSecondaryVertexNegativeTagInfos':
568 btag.pfSecondaryVertexNegativeTagInfos.clone(
569 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix)),
572 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
573 _btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
574 _btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
575 if btagInfo ==
'pfInclusiveSecondaryVertexFinderNegativeTagInfos':
577 btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(
578 trackIPTagInfos = cms.InputTag(btagPrefix+
'pfImpactParameterTagInfos'+labelName+postfix),
579 extSVCollection=cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)),
581 if svClustering
or fatJets != cms.InputTag(
''):
582 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
583 if btagInfo ==
'impactParameterTagInfos':
585 btag.impactParameterTagInfos.clone(
586 jetTracks = cms.InputTag(
'jetTracksAssociatorAtVertex'+labelName+postfix),
587 primaryVertex=pvSource),
589 if btagInfo ==
'secondaryVertexTagInfos':
591 btag.secondaryVertexTagInfos.clone(
592 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
594 if btagInfo ==
'inclusiveSecondaryVertexFinderTagInfos':
596 btag.inclusiveSecondaryVertexFinderTagInfos.clone(
597 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
599 if svClustering
or fatJets != cms.InputTag(
''):
600 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
601 if btagInfo ==
'inclusiveSecondaryVertexFinderFilteredTagInfos':
603 btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(
604 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
606 if svClustering
or fatJets != cms.InputTag(
''):
607 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
608 if btagInfo ==
'secondaryVertexNegativeTagInfos':
610 btag.secondaryVertexNegativeTagInfos.clone(
611 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
613 if btagInfo ==
'inclusiveSecondaryVertexFinderNegativeTagInfos':
615 btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(
616 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
618 if svClustering
or fatJets != cms.InputTag(
''):
619 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
620 if btagInfo ==
'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos':
622 btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(
623 trackIPTagInfos = cms.InputTag(btagPrefix+
'impactParameterTagInfos'+labelName+postfix)),
625 if svClustering
or fatJets != cms.InputTag(
''):
626 setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
627 if btagInfo ==
'softMuonTagInfos':
629 btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource),
631 if btagInfo ==
'softPFMuonsTagInfos':
633 btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource),
635 if btagInfo ==
'softPFElectronsTagInfos':
637 btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource),
639 if btagInfo ==
'pixelClusterTagInfos':
641 btag.pixelClusterTagInfos.clone(jets = jetSource, vertices=pvSource),
645 if 'pfBoostedDouble' in btagInfo
or 'SecondaryVertex' in btagInfo:
646 _btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
647 _btagInfo.weights = cms.InputTag(puppi_value_map)
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':
662 vertex_associator = cms.InputTag(
"")
664 vertex_associator = cms.InputTag(
"primaryVertexAssociation",
"original")
667 is_weighted_jet =
False 668 if (
'puppi' in jetSource.value().lower()):
669 is_weighted_jet =
True 671 btag.pfDeepFlavourTagInfos.clone(
674 secondary_vertices=svUsed,
675 shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
676 puppi_value_map = puppi_value_map,
677 vertex_associator = vertex_associator,
678 is_weighted_jet = is_weighted_jet,
682 if (
'ParticleTransformerAK4TagInfos' in btagInfo)
and (
'UnifiedParticleTransformerAK4TagInfos' not in btagInfo):
684 if btagInfo ==
'pfNegativeParticleTransformerAK4TagInfos':
685 svUsed, flip, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix),
True, 10.
687 svUsed, flip, max_sip3dsig_for_flip = svSource,
False, -1.
690 if pfCandidates.value() ==
'packedPFCandidates':
691 vertex_associator = cms.InputTag(
"")
693 vertex_associator = cms.InputTag(
"primaryVertexAssociation",
"original")
696 is_weighted_jet =
False 697 if (
'puppi' in jetSource.value().lower()):
698 is_weighted_jet =
True 700 btag.pfParticleTransformerAK4TagInfos.clone(
703 secondary_vertices=svUsed,
704 puppi_value_map = puppi_value_map,
705 vertex_associator = vertex_associator,
706 is_weighted_jet = is_weighted_jet,
708 max_sip3dsig_for_flip=max_sip3dsig_for_flip),
711 if 'UnifiedParticleTransformerAK4TagInfos' in btagInfo:
713 if btagInfo ==
'pfNegativeUnifiedParticleTransformerAK4TagInfos':
714 svUsed = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
720 if pfCandidates.value() ==
'packedPFCandidates':
721 vertex_associator = cms.InputTag(
"")
723 vertex_associator = cms.InputTag(
"primaryVertexAssociation",
"original")
726 is_weighted_jet =
False 727 if (
'puppi' in jetSource.value().lower()):
728 is_weighted_jet =
True 730 btag.pfUnifiedParticleTransformerAK4TagInfos.clone(
733 secondary_vertices=svUsed,
734 puppi_value_map = puppi_value_map,
735 vertex_associator = vertex_associator,
736 is_weighted_jet = is_weighted_jet,
740 if btagInfo ==
'pfDeepDoubleXTagInfos':
742 if 'updated' not in jetSource.value().lower():
743 raise ValueError(
"Invalid jet collection: %s. pfDeepDoubleXTagInfos only supports running via updateJetCollection." % jetSource.value())
745 btag.pfDeepDoubleXTagInfos.clone(
748 secondary_vertices=svSource,
749 shallow_tag_infos = cms.InputTag(btagPrefix+
'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
750 puppi_value_map = puppi_value_map,
753 if btagInfo ==
'pfHiggsInteractionNetTagInfos':
755 btag.pfHiggsInteractionNetTagInfos.clone(
758 secondary_vertices = svSource,
759 pf_candidates = pfCandidates,
760 puppi_value_map = puppi_value_map
764 if btagInfo ==
'pfDeepBoostedJetTagInfos':
765 if pfCandidates.value() ==
'packedPFCandidates':
767 if 'updated' not in jetSource.value().lower():
768 raise ValueError(
"Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
769 vertex_associator =
"" 770 elif pfCandidates.value() ==
'particleFlow':
771 raise ValueError(
"Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
777 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
779 btag.pfDeepBoostedJetTagInfos.clone(
782 secondary_vertices = svSource,
783 pf_candidates = pfCandidates,
784 puppi_value_map = puppi_value_map,
785 vertex_associator = vertex_associator,
789 if btagInfo ==
'pfParticleNetTagInfos' or btagInfo ==
'pfGlobalParticleTransformerAK8TagInfos':
790 if pfCandidates.value() ==
'packedPFCandidates':
792 vertex_associator =
"" 793 elif pfCandidates.value() ==
'particleFlow':
794 raise ValueError(
"Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
796 vertex_associator =
"primaryVertexAssociation:original" 798 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
800 getattr(btag, btagInfo).
clone(
803 secondary_vertices = svSource,
804 pf_candidates = pfCandidates,
805 puppi_value_map = puppi_value_map,
806 vertex_associator = vertex_associator,
810 if 'ParticleNetAK4TagInfos' in btagInfo:
811 if btagInfo ==
'pfNegativeParticleNetAK4TagInfos':
812 secondary_vertices = btagPrefix + \
813 'inclusiveCandidateNegativeSecondaryVertices' + labelName + postfix
817 secondary_vertices = svSource
820 if pfCandidates.value() ==
'packedPFCandidates':
822 vertex_associator =
"" 823 elif pfCandidates.value() ==
'particleFlow':
824 raise ValueError(
"Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
826 vertex_associator =
"primaryVertexAssociation:original" 828 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
831 if "puppi" in jetSource.value().lower():
834 btag.pfParticleNetAK4TagInfos.clone(
837 secondary_vertices = secondary_vertices,
838 pf_candidates = pfCandidates,
839 puppi_value_map = puppi_value_map,
840 vertex_associator = vertex_associator,
841 flip_ip_sign = flip_ip_sign,
842 sip3dSigMax = sip3dSigMax,
843 use_puppiP4 = use_puppiP4
847 acceptedTagInfos.append(btagInfo)
848 elif hasattr(toptag, btagInfo) :
849 acceptedTagInfos.append(btagInfo)
850 elif btagInfo ==
'pfParticleNetFromMiniAODAK4PuppiCentralTagInfos' or btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4PuppiCentralTagInfos':
852 if btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4PuppiCentralTagInfos':
853 svUsed, flip_ip_sign, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix),
True, 10.
855 svUsed, flip_ip_sign, max_sip3dsig_for_flip = svSource,
False, -1.
856 if pfCandidates.value() !=
'packedPFCandidates':
857 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
859 pfParticleNetFromMiniAODAK4PuppiCentralTagInfos.clone(
862 secondary_vertices = svUsed,
863 pf_candidates = pfCandidates,
864 puppi_value_map = puppi_value_map,
865 flip_ip_sign = flip_ip_sign,
866 max_sip3dsig_for_flip = max_sip3dsig_for_flip,
869 acceptedTagInfos.append(btagInfo)
870 elif btagInfo ==
'pfParticleNetFromMiniAODAK4PuppiForwardTagInfos':
872 if pfCandidates.value() !=
'packedPFCandidates':
873 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
875 pfParticleNetFromMiniAODAK4PuppiForwardTagInfos.clone(
878 secondary_vertices = svSource,
879 pf_candidates = pfCandidates,
880 puppi_value_map = puppi_value_map
883 acceptedTagInfos.append(btagInfo)
884 elif btagInfo ==
'pfParticleNetFromMiniAODAK4CHSCentralTagInfos' or btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4CHSCentralTagInfos':
886 if btagInfo ==
'pfNegativeParticleNetFromMiniAODAK4CHSCentralTagInfos':
887 svUsed, flip_ip_sign, max_sip3dsig_for_flip = cms.InputTag(btagPrefix+
'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix),
True, 10.
889 svUsed, flip_ip_sign, max_sip3dsig_for_flip = svSource,
False, -1.
890 if pfCandidates.value() !=
'packedPFCandidates':
891 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
893 pfParticleNetFromMiniAODAK4CHSCentralTagInfos.clone(
896 secondary_vertices = svUsed,
897 pf_candidates = pfCandidates,
898 puppi_value_map = puppi_value_map,
899 flip_ip_sign = flip_ip_sign,
900 max_sip3dsig_for_flip = max_sip3dsig_for_flip,
903 acceptedTagInfos.append(btagInfo)
904 elif btagInfo ==
'pfParticleNetFromMiniAODAK4CHSForwardTagInfos':
906 if pfCandidates.value() !=
'packedPFCandidates':
907 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
909 pfParticleNetFromMiniAODAK4CHSForwardTagInfos.clone(
912 secondary_vertices = svSource,
913 pf_candidates = pfCandidates,
914 puppi_value_map = puppi_value_map,
917 acceptedTagInfos.append(btagInfo)
918 elif btagInfo ==
'pfParticleNetFromMiniAODAK8TagInfos':
920 if pfCandidates.value() !=
'packedPFCandidates':
921 raise ValueError(
"Invalid pfCandidates collection: %s." % pfCandidates.value())
923 pfParticleNetFromMiniAODAK8TagInfos.clone(
926 secondary_vertices = svSource,
927 pf_candidates = pfCandidates,
928 puppi_value_map = puppi_value_map,
931 acceptedTagInfos.append(btagInfo)
933 print(
' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
935 acceptedBtagDiscriminators = list()
936 for discriminator_name
in btagDiscriminators :
937 btagDiscr = discriminator_name.split(
':')[0]
939 newDiscr = btagPrefix+btagDiscr+labelName+postfix
940 if hasattr(btag,btagDiscr):
941 if hasattr(process, newDiscr):
943 elif hasattr(getattr(btag, btagDiscr),
'tagInfos'):
946 getattr(btag, btagDiscr).
clone(
947 tagInfos = cms.VInputTag(
948 *[ cms.InputTag(btagPrefix+x+labelName+postfix) \
949 for x
in supportedBtagDiscr[discriminator_name][0] ]
955 elif hasattr(getattr(btag, btagDiscr),
'src'):
958 getattr(btag, btagDiscr).
clone(
959 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
965 raise ValueError(
'I do not know how to update %s it does not have neither "tagInfos" nor "src" attributes' % btagDiscr)
966 acceptedBtagDiscriminators.append(discriminator_name)
967 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiCentralJetTags':
968 if hasattr(process, newDiscr):
972 pfParticleNetFromMiniAODAK4PuppiCentralJetTags.clone(
973 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
978 acceptedBtagDiscriminators.append(discriminator_name)
979 elif btagDiscr==
'pfNegativeParticleNetFromMiniAODAK4PuppiCentralJetTags':
980 if hasattr(process, newDiscr):
984 pfNegativeParticleNetFromMiniAODAK4PuppiCentralJetTags.clone(
985 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
990 acceptedBtagDiscriminators.append(discriminator_name)
991 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiForwardJetTags':
992 if hasattr(process, newDiscr):
996 pfParticleNetFromMiniAODAK4PuppiForwardJetTags.clone(
997 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1002 acceptedBtagDiscriminators.append(discriminator_name)
1003 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSCentralJetTags':
1004 if hasattr(process, newDiscr):
1008 pfParticleNetFromMiniAODAK4CHSCentralJetTags.clone(
1009 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1014 acceptedBtagDiscriminators.append(discriminator_name)
1015 elif btagDiscr==
'pfNegativeParticleNetFromMiniAODAK4CHSCentralJetTags':
1016 if hasattr(process, newDiscr):
1020 pfNegativeParticleNetFromMiniAODAK4CHSCentralJetTags.clone(
1021 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1026 acceptedBtagDiscriminators.append(discriminator_name)
1027 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSForwardJetTags':
1028 if hasattr(process, newDiscr):
1032 pfParticleNetFromMiniAODAK4CHSForwardJetTags.clone(
1033 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1038 acceptedBtagDiscriminators.append(discriminator_name)
1039 elif btagDiscr==
'pfParticleNetFromMiniAODAK8JetTags':
1040 if hasattr(process, newDiscr):
1044 pfParticleNetFromMiniAODAK8JetTags.clone(
1045 src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
1050 acceptedBtagDiscriminators.append(discriminator_name)
1052 print(
' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
1055 for meta_tagger
in present_meta:
1056 btagDiscr = meta_tagger.split(
':')[0]
1058 newDiscr = btagPrefix+btagDiscr+labelName+postfix
1059 if hasattr(btag,btagDiscr):
1060 if hasattr(process, newDiscr):
1065 getattr(btag, btagDiscr).
clone(),
1069 for dependency
in supportedMetaDiscr[meta_tagger]:
1070 if ':' in dependency:
1071 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1073 new_dep = btagPrefix+dependency+labelName+postfix
1074 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1075 replace.doIt(getattr(process, newDiscr), newDiscr)
1076 acceptedBtagDiscriminators.append(meta_tagger)
1077 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags':
1078 if hasattr(process, newDiscr):
1083 pfParticleNetFromMiniAODAK4PuppiCentralDiscriminatorsJetTags.clone(),
1087 for dependency
in supportedMetaDiscr[meta_tagger]:
1088 if ':' in dependency:
1089 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1091 new_dep = btagPrefix+dependency+labelName+postfix
1092 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1093 replace.doIt(getattr(process, newDiscr), newDiscr)
1094 acceptedBtagDiscriminators.append(meta_tagger)
1095 elif btagDiscr==
'pfParticleNetFromMiniAODAK4PuppiForwardDiscriminatorsJetTags':
1096 if hasattr(process, newDiscr):
1101 pfParticleNetFromMiniAODAK4PuppiForwardDiscriminatorsJetTags.clone(),
1105 for dependency
in supportedMetaDiscr[meta_tagger]:
1106 if ':' in dependency:
1107 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1109 new_dep = btagPrefix+dependency+labelName+postfix
1110 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1111 replace.doIt(getattr(process, newDiscr), newDiscr)
1112 acceptedBtagDiscriminators.append(meta_tagger)
1113 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags':
1114 if hasattr(process, newDiscr):
1119 pfParticleNetFromMiniAODAK4CHSCentralDiscriminatorsJetTags.clone(),
1123 for dependency
in supportedMetaDiscr[meta_tagger]:
1124 if ':' in dependency:
1125 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1127 new_dep = btagPrefix+dependency+labelName+postfix
1128 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1129 replace.doIt(getattr(process, newDiscr), newDiscr)
1130 acceptedBtagDiscriminators.append(meta_tagger)
1131 elif btagDiscr==
'pfParticleNetFromMiniAODAK4CHSForwardDiscriminatorsJetTags':
1132 if hasattr(process, newDiscr):
1137 pfParticleNetFromMiniAODAK4CHSForwardDiscriminatorsJetTags.clone(),
1141 for dependency
in supportedMetaDiscr[meta_tagger]:
1142 if ':' in dependency:
1143 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1145 new_dep = btagPrefix+dependency+labelName+postfix
1146 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1147 replace.doIt(getattr(process, newDiscr), newDiscr)
1148 acceptedBtagDiscriminators.append(meta_tagger)
1149 elif btagDiscr==
'pfParticleNetFromMiniAODAK8DiscriminatorsJetTags':
1150 if hasattr(process, newDiscr):
1155 pfParticleNetFromMiniAODAK8DiscriminatorsJetTags.clone(),
1159 for dependency
in supportedMetaDiscr[meta_tagger]:
1160 if ':' in dependency:
1161 new_dep = btagPrefix+dependency.split(
':')[0]+labelName+postfix+
':'+dependency.split(
':')[1]
1163 new_dep = btagPrefix+dependency+labelName+postfix
1164 replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
1165 replace.doIt(getattr(process, newDiscr), newDiscr)
1166 acceptedBtagDiscriminators.append(meta_tagger)
1169 print(
' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
1172 patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix)
for x
in acceptedTagInfos ] )
1173 patJets.discriminatorSources = cms.VInputTag(*[
1174 cms.InputTag(btagPrefix+x+labelName+postfix) \
1175 if ':' not in x
else \
1176 cms.InputTag(btagPrefix+x.split(
':')[0]+labelName+postfix+
':'+x.split(
':')[1]) \
1177 for x
in acceptedBtagDiscriminators
1179 if len(acceptedBtagDiscriminators) > 0 :
1180 patJets.addBTagInfo =
True 1183 if not tightBTagNTkHits:
1184 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
1189 ivfbTagInfos = [
'pfInclusiveSecondaryVertexFinderTagInfos',
'pfInclusiveSecondaryVertexFinderAK8TagInfos',
'pfInclusiveSecondaryVertexFinderCA15TagInfos']
1190 if any(i
in acceptedTagInfos
for i
in ivfbTagInfos)
and not runIVFforCTagOnly:
1191 if not hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
1192 loadWithPrefix(process,
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
1193 if tightBTagNTkHits:
1194 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
1195 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinder')
1196 _temp.minHits = cms.uint32(8)
1198 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
1199 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinder' ):
1200 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinder')
1201 _temp.primaryVertices = pvSource
1202 _temp.tracks = pfCandidates
1203 if hasattr( process, btagPrefix+
'candidateVertexArbitrator' ):
1204 _temp = getattr(process, btagPrefix+
'candidateVertexArbitrator')
1205 _temp.primaryVertices = pvSource
1206 _temp.tracks = pfCandidates
1207 if hasattr( process, btagPrefix+
'inclusiveCandidateSecondaryVertices' )
and not hasattr( process, svSource.getModuleLabel() ):
1209 getattr(process, btagPrefix+
'inclusiveCandidateSecondaryVertices').
clone(),
1211 if any(i
in acceptedTagInfos
for i
in ivfcTagInfos):
1212 if not hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
1213 loadWithPrefix(process,
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
1214 if tightBTagNTkHits:
1215 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
1216 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL')
1217 _temp.minHits = cms.uint32(8)
1219 if pvSource.getModuleLabel() ==
'offlineSlimmedPrimaryVertices':
1220 if hasattr( process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL' ):
1221 _temp = getattr(process, btagPrefix+
'inclusiveCandidateVertexFinderCvsL')
1222 _temp.primaryVertices = pvSource
1223 _temp.tracks = pfCandidates
1224 if hasattr( process, btagPrefix+
'candidateVertexArbitratorCvsL' ):
1225 _temp = getattr(process, btagPrefix+
'candidateVertexArbitratorCvsL')
1226 _temp.primaryVertices = pvSource
1227 _temp.tracks = pfCandidates
1228 if hasattr( process, btagPrefix+
'inclusiveCandidateSecondaryVerticesCvsL' )
and not hasattr( process, svSourceCvsL.getModuleLabel() ):
1230 getattr(process, btagPrefix+
'inclusiveCandidateSecondaryVerticesCvsL').
clone(),
1232 if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
1233 if not hasattr( process,
'inclusiveVertexing' ):
1234 process.load(
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
1235 task.add(process.inclusiveVertexingTask)
1236 task.add(process.inclusiveCandidateVertexingTask)
1237 task.add(process.inclusiveCandidateVertexingCvsLTask)
1238 if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
1239 if not hasattr( process,
'inclusiveVertexing' ):
1240 process.load(
'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
1241 task.add(process.inclusiveVertexingTask)
1242 task.add(process.inclusiveCandidateVertexingTask)
1243 task.add(process.inclusiveCandidateVertexingCvsLTask)
1244 if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
1245 if not hasattr( process,
'inclusiveSecondaryVerticesFiltered' ):
1246 process.load(
'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
1247 task.add(process.inclusiveSecondaryVerticesFiltered)
1248 task.add(process.bVertexFilter)
1249 if not hasattr( process,
'bToCharmDecayVertexMerged' ):
1250 process.load(
'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
1251 task.add(process.bToCharmDecayVertexMerged)
1252 if 'caTopTagInfos' in acceptedTagInfos :
1253 patJets.addTagInfos =
True 1254 if not hasattr( process,
'caTopTagInfos' )
and not hasattr( process,
'caTopTagInfosAK8' ):
1255 process.load(
'RecoJets.JetProducers.caTopTaggers_cff' )
1256 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)