forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jetTools.py
1866 lines (1778 loc) · 123 KB
/
jetTools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import print_function
from FWCore.GuiBrowsers.ConfigToolBase import *
from FWCore.ParameterSet.Mixins import PrintOptions,_ParameterTypeBase,_SimpleParameterTypeBase, _Parameterizable, _ConfigureComponent, _TypedParameterizable, _Labelable, _Unlabelable, _ValidatingListBase
from FWCore.ParameterSet.SequenceTypes import _ModuleSequenceType, _Sequenceable
from FWCore.ParameterSet.SequenceTypes import *
from PhysicsTools.PatAlgos.tools.helpers import *
from PhysicsTools.PatAlgos.recoLayer0.bTagging_cff import *
import sys
from FWCore.ParameterSet.MassReplace import MassSearchReplaceAnyInputTagVisitor
## dictionary with supported jet clustering algorithms
supportedJetAlgos = {
'ak' : 'AntiKt'
, 'ca' : 'CambridgeAachen'
, 'kt' : 'Kt'
}
def checkJetCorrectionsFormat(jetCorrections):
## check for the correct format
if not isinstance(jetCorrections, type(('PAYLOAD-LABEL',['CORRECTION-LEVEL-A','CORRECTION-LEVEL-B'], 'MET-LABEL'))):
raise ValueError("In addJetCollection: 'jetCorrections' must be 'None' (as a python value w/o quotation marks), or of type ('PAYLOAD-LABEL', ['CORRECTION-LEVEL-A', \
'CORRECTION-LEVEL-B', ...], 'MET-LABEL'). Note that 'MET-LABEL' can be set to 'None' (as a string in quotation marks) in case you do not want to apply MET(Type1) \
corrections.")
def setupJetCorrections(process, knownModules, jetCorrections, jetSource, pvSource, patJets, labelName, postfix):
task = getPatAlgosToolsTask(process)
## determine type of jet constituents from jetSource; supported
## jet constituent types are calo, pf, jpt, for pf also particleflow
## is aloowed as part of the jetSource label, which might be used
## in CommonTools.ParticleFlow
_type="NONE"
if jetCorrections[0].count('PF')>0:
_type='PF'
elif jetCorrections[0].count('Calo')>0:
_type='Calo'
elif jetCorrections[0].count('JPT')>0:
_type='JPT'
else:
raise TypeError("In addJetCollection: Jet energy corrections are only supported for PF, JPT and Calo jets.")
from PhysicsTools.PatAlgos.recoLayer0.jetCorrFactors_cfi import patJetCorrFactors
if 'patJetCorrFactors'+labelName+postfix in knownModules :
_newPatJetCorrFactors=getattr(process, 'patJetCorrFactors'+labelName+postfix)
_newPatJetCorrFactors.src=jetSource
_newPatJetCorrFactors.primaryVertices=pvSource
else:
addToProcessAndTask('patJetCorrFactors'+labelName+postfix,
patJetCorrFactors.clone(src=jetSource, primaryVertices=pvSource),
process, task)
_newPatJetCorrFactors=getattr(process, "patJetCorrFactors"+labelName+postfix)
_newPatJetCorrFactors.payload=jetCorrections[0]
_newPatJetCorrFactors.levels=jetCorrections[1]
## check whether L1Offset or L1FastJet is part of levels
error=False
for x in jetCorrections[1]:
if x == 'L1Offset' :
if not error :
_newPatJetCorrFactors.useNPV=True
_newPatJetCorrFactors.primaryVertices='offlinePrimaryVertices'
_newPatJetCorrFactors.useRho=False
## we set this to True now as a L1 correction type should appear only once
## otherwise levels is miss configured
error=True
else:
raise ValueError("In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
once. Check the list of correction levels you requested to be applied: "+ jetCorrections[1])
if x == 'L1FastJet' :
if not error :
if _type == "JPT" :
raise TypeError("In addJetCollection: L1FastJet corrections are only supported for PF and Calo jets.")
## configure module
_newPatJetCorrFactors.useRho=True
if "PF" in _type :
_newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAll')
else :
_newPatJetCorrFactors.rho=cms.InputTag('fixedGridRhoFastjetAllCalo')
## we set this to True now as a L1 correction type should appear only once
## otherwise levels is miss configured
error=True
else:
raise ValueError("In addJetCollection: Correction levels for jet energy corrections are miss configured. An L1 correction type should appear not more than \
once. Check the list of correction levels you requested to be applied: "+ jetCorrections[1])
patJets.jetCorrFactorsSource=cms.VInputTag(cms.InputTag('patJetCorrFactors'+labelName+postfix))
## configure MET(Type1) corrections
if jetCorrections[2].lower() != 'none' and jetCorrections[2] != '':
if not jetCorrections[2].lower() == 'type-1' and not jetCorrections[2].lower() == 'type-2':
raise ValueError("In addJetCollection: Wrong choice of MET corrections for new jet collection. Possible choices are None (or empty string), Type-1, Type-2 (i.e.\
Type-1 and Type-2 corrections applied). This choice is not case sensitive. Your choice was: "+ jetCorrections[2])
if _type == "JPT":
raise ValueError("In addJecCollection: MET(type1) corrections are not supported for JPTJets. Please set the MET-LABEL to \"None\" (as string in quatiation \
marks) and use raw tcMET together with JPTJets.")
## set up jet correctors for MET corrections
process.load( "JetMETCorrections.Configuration.JetCorrectorsAllAlgos_cff") # FIXME: This adds a lot of garbage
# I second the FIXME comment on the last line. When I counted it, this brought in 344 EDProducers
# to be available to run unscheduled. All jet correctors, probably some small fraction of which
# are actually used.
task.add(process.jetCorrectorsAllAlgosTask)
_payloadType = jetCorrections[0].split(_type)[0].lower()+_type
if "PF" in _type :
addToProcessAndTask(jetCorrections[0]+'L1FastJet',
getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAll')),
process, task)
else :
addToProcessAndTask(jetCorrections[0]+'L1FastJet',
getattr(process, _payloadType+'L1FastjetCorrector').clone(srcRho=cms.InputTag('fixedGridRhoFastjetAllCalo')),
process, task)
addToProcessAndTask(jetCorrections[0]+'L1Offset', getattr(process, _payloadType+'L1OffsetCorrector').clone(), process, task)
addToProcessAndTask(jetCorrections[0]+'L2Relative', getattr(process, _payloadType+'L2RelativeCorrector').clone(), process, task)
addToProcessAndTask(jetCorrections[0]+'L3Absolute', getattr(process, _payloadType+'L3AbsoluteCorrector').clone(), process, task)
addToProcessAndTask(jetCorrections[0]+'L2L3Residual', getattr(process, _payloadType+'ResidualCorrector').clone(), process, task)
addToProcessAndTask(jetCorrections[0]+'CombinedCorrector',
cms.EDProducer( 'ChainedJetCorrectorProducer', correctors = cms.VInputTag()),
process, task)
for x in jetCorrections[1]:
if x != 'L1FastJet' and x != 'L1Offset' and x != 'L2Relative' and x != 'L3Absolute' and x != 'L2L3Residual':
raise ValueError('In addJetCollection: Unsupported JEC for MET(Type1). Currently supported jet correction levels are L1FastJet, L1Offset, L2Relative, L3Asolute, L2L3Residual. Requested was: %s'%(x))
else:
_corrector = _payloadType
if x == 'L1FastJet':
_corrector += 'L1Fastjet'
elif x == 'L2L3Residual':
_corrector += 'Residual'
else:
_corrector += x
_corrector += 'Corrector'
getattr(process, jetCorrections[0]+'CombinedCorrector').correctors.append(cms.InputTag(_corrector))
## set up MET(Type1) correction modules
_labelCorrName = labelName
if labelName != '':
_labelCorrName = 'For' + labelName
if _type == 'Calo':
from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType1
from JetMETCorrections.Type1MET.correctionTermsCaloMet_cff import corrCaloMetType2
from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1
from JetMETCorrections.Type1MET.correctedMet_cff import caloMetT1T2
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix,
corrCaloMetType1.clone(src=jetSource,srcMET = "caloMetM",jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector')),
process, task)
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix,
corrCaloMetType2.clone(srcUnclEnergySums = cms.VInputTag(
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),
cms.InputTag('muCaloMetCorr'))),
process, task)
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix,
caloMetT1.clone(src = "caloMetM", srcCorrections = cms.VInputTag(
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'))),
process, task)
addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix,
caloMetT1T2.clone(src = "caloMetM", srcCorrections = cms.VInputTag(
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'),
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr2'+postfix))),
process, task)
elif _type == 'PF':
from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfJetsPtrForMetCorr
from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsPtrForMetCorr
from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandsNotInJetsForMetCorr
from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import pfCandMETcorr
from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import corrPfMetType1
from JetMETCorrections.Type1MET.correctionTermsPfMetType1Type2_cff import corrPfMetType2
from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1
from JetMETCorrections.Type1MET.correctedMet_cff import pfMetT1T2
addToProcessAndTask(jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix,
pfJetsPtrForMetCorr.clone(src = jetSource), process, task)
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix,
pfCandsNotInJetsPtrForMetCorr.clone(topCollection = jetCorrections[0]+_labelCorrName+'pfJetsPtrForMetCorr'+postfix),
process, task)
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix,
pfCandsNotInJetsForMetCorr.clone(src = jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsPtrForMetCorr'+postfix),
process, task)
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix,
pfCandMETcorr.clone(src = cms.InputTag(jetCorrections[0]+_labelCorrName+'pfCandsNotInJetsForMetCorr'+postfix)),
process, task)
addToProcessAndTask(
jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix,
corrPfMetType1.clone(src = jetSource, jetCorrLabel = cms.InputTag(jetCorrections[0]+'CombinedCorrector')),
process, task) # FIXME: Originally w/o jet corrections?
addToProcessAndTask(jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix,
corrPfMetType2.clone(srcUnclEnergySums = cms.VInputTag(
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type2'),
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'offset'),
cms.InputTag(jetCorrections[0]+_labelCorrName+'CandMETcorr'+postfix))),
process, task)
addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix,
pfMetT1.clone(srcCorrections = cms.VInputTag(
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'))),
process, task)
addToProcessAndTask(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix,
pfMetT1T2.clone(srcCorrections = cms.VInputTag(
cms.InputTag(jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix, 'type1'),
jetCorrections[0]+_labelCorrName+'corrPfMetType2'+postfix)),
process, task)
## common configuration for Calo and PF
if ('L1FastJet' in jetCorrections[1] or 'L1Fastjet' in jetCorrections[1]):
getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1FastJet')
#FIXME: What is wrong here?
#elif ('L1Offset' in jetCorrections[1]):
#getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag(jetCorrections[0]+'L1Offset')
else:
getattr(process,jetCorrections[0]+_labelCorrName+'JetMETcorr'+postfix).offsetCorrLabel = cms.InputTag('')
from PhysicsTools.PatAlgos.producersLayer1.metProducer_cfi import patMETs
if jetCorrections[2].lower() == 'type-1':
addToProcessAndTask('patMETs'+labelName+postfix,
patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1CorMet'+postfix),
addMuonCorrections = False),
process, task)
elif jetCorrections[2].lower() == 'type-2':
addToProcessAndTask('patMETs'+labelName+postfix,
patMETs.clone(metSource = cms.InputTag(jetCorrections[0]+_labelCorrName+'Type1p2CorMet'+postfix),
addMuonCorrections = False),
process, task)
def setupSVClustering(btagInfo, svClustering, algo, rParam, fatJets=cms.InputTag(''), groomedFatJets=cms.InputTag('')):
btagInfo.useSVClustering = cms.bool(svClustering)
btagInfo.jetAlgorithm = cms.string(algo)
btagInfo.rParam = cms.double(rParam)
## if the jet is actually a subjet
if fatJets != cms.InputTag(''):
btagInfo.fatJets = fatJets
if groomedFatJets != cms.InputTag(''):
btagInfo.groomedFatJets = groomedFatJets
def setupBTagging(process, jetSource, pfCandidates, explicitJTA, pvSource, svSource, elSource, muSource, runIVF, tightBTagNTkHits, loadStdRecoBTag, svClustering, fatJets, groomedFatJets,
algo, rParam, btagDiscriminators, btagInfos, patJets, labelName, btagPrefix, postfix):
task = getPatAlgosToolsTask(process)
## expand the btagDiscriminators to remove the meta taggers and substitute the equivalent sources
discriminators = set(btagDiscriminators)
present_meta = discriminators.intersection(set(supportedMetaDiscr.keys()))
discriminators -= present_meta
for meta_tagger in present_meta:
for src in supportedMetaDiscr[meta_tagger]:
discriminators.add(src)
btagDiscriminators = list(discriminators)
## expand tagInfos to what is explicitly required by user + implicit
## requirements that come in from one or the other discriminator
requiredTagInfos = list(btagInfos)
for btagDiscr in btagDiscriminators :
for tagInfoList in supportedBtagDiscr[btagDiscr] :
for requiredTagInfo in tagInfoList :
tagInfoCovered = False
for tagInfo in requiredTagInfos :
if requiredTagInfo == tagInfo :
tagInfoCovered = True
break
if not tagInfoCovered :
requiredTagInfos.append(requiredTagInfo)
## load sequences and setups needed for btagging
if hasattr( process, 'candidateJetProbabilityComputer' ) == False :
if loadStdRecoBTag: # also loading modules already run in the standard reconstruction
process.load("RecoBTag.ImpactParameter.impactParameter_cff")
task.add(process.impactParameterTask)
process.load("RecoBTag.SecondaryVertex.secondaryVertex_cff")
task.add(process.secondaryVertexTask)
process.load("RecoBTag.SoftLepton.softLepton_cff")
task.add(process.softLeptonTask)
process.load("RecoBTag.Combined.combinedMVA_cff")
task.add(process.combinedMVATask)
process.load("RecoBTag.CTagging.cTagging_cff")
task.add(process.cTaggingTask)
else: # to prevent loading of modules already run in the standard reconstruction
process.load("RecoBTag.ImpactParameter.impactParameter_EventSetup_cff")
process.load("RecoBTag.SecondaryVertex.secondaryVertex_EventSetup_cff")
process.load("RecoBTag.SoftLepton.softLepton_EventSetup_cff")
process.load("RecoBTag.Combined.combinedMVA_EventSetup_cff")
process.load("RecoBTag.CTagging.cTagging_EventSetup_cff")
import RecoBTag.Configuration.RecoBTag_cff as btag
import RecoJets.JetProducers.caTopTaggers_cff as toptag
if tightBTagNTkHits:
if not runIVF:
sys.stderr.write("-------------------------------------------------------------------\n")
sys.stderr.write(" Warning: For a complete switch to the legacy tight b-tag track\n")
sys.stderr.write(" selection, please also enable the \'runIVF\' switch.\n")
sys.stderr.write("-------------------------------------------------------------------\n")
if btagPrefix == '':
sys.stderr.write("-------------------------------------------------------------------\n")
sys.stderr.write(" Warning: With the tight b-tag track selection enabled, it is\n")
sys.stderr.write(" advisable to set \'btagPrefix\' to a non-empty string to\n")
sys.stderr.write(" avoid unintentional modifications to the default\n")
sys.stderr.write(" b tagging setup that might be loaded in the same job.\n")
sys.stderr.write("-------------------------------------------------------------------\n")
## define c tagging CvsL SV source (for now tied to the default SV source
## in the first part of the module label, product instance label and process name)
svSourceCvsL = copy.deepcopy(svSource)
svSourceCvsL.setModuleLabel(svSource.getModuleLabel()+'CvsL')
## check if and under what conditions to re-run IVF
runIVFforCTagOnly = False
ivfcTagInfos = ['pfInclusiveSecondaryVertexFinderCvsLTagInfos', 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos']
## if MiniAOD and running c tagging
if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices' and any(i in requiredTagInfos for i in ivfcTagInfos) and not runIVF:
runIVFforCTagOnly = True
runIVF = True
sys.stderr.write("-------------------------------------------------------------------\n")
sys.stderr.write(" Info: To run c tagging on MiniAOD, c-tag-specific IVF secondary\n")
sys.stderr.write(" vertices will be remade.\n")
sys.stderr.write("-------------------------------------------------------------------\n")
## adjust svSources
if runIVF and btagPrefix != '':
if runIVFforCTagOnly:
svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
else:
svSource.setModuleLabel(btagPrefix+svSource.getModuleLabel())
svSourceCvsL.setModuleLabel(btagPrefix+svSourceCvsL.getModuleLabel())
## setup all required btagInfos : we give a dedicated treatment for different
## types of tagInfos here. A common treatment is possible but might require a more
## general approach anyway in coordination with the btagging POG.
runNegativeVertexing = False
runNegativeCvsLVertexing = False
for btagInfo in requiredTagInfos:
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos' or btagInfo == 'pfNegativeDeepFlavourTagInfos':
runNegativeVertexing = True
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
runNegativeCvsLVertexing = True
if runNegativeVertexing or runNegativeCvsLVertexing:
import RecoVertex.AdaptiveVertexFinder.inclusiveNegativeVertexing_cff as NegVertex
if runNegativeVertexing:
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeVertexFinder.clone(primaryVertices = pvSource,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix,
NegVertex.candidateNegativeVertexMerger.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinder'+labelName+postfix)),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix,
NegVertex.candidateNegativeVertexArbitrator.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMerger'+labelName+postfix)
,primaryVertices = pvSource
,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeSecondaryVertices.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitrator'+labelName+postfix)),
process, task)
if runNegativeCvsLVertexing:
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeVertexFinderCvsL.clone(primaryVertices = pvSource,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix,
NegVertex.candidateNegativeVertexMergerCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeVertexFinderCvsL'+labelName+postfix)),
process, task)
addToProcessAndTask(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix,
NegVertex.candidateNegativeVertexArbitratorCvsL.clone( secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexMergerCvsL'+labelName+postfix)
,primaryVertices = pvSource
,tracks=pfCandidates),
process, task)
addToProcessAndTask(btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix,
NegVertex.inclusiveCandidateNegativeSecondaryVerticesCvsL.clone(secondaryVertices = cms.InputTag(btagPrefix+'candidateNegativeVertexArbitratorCvsL'+labelName+postfix)),
process, task)
acceptedTagInfos = list()
for btagInfo in requiredTagInfos:
if hasattr(btag,btagInfo):
if btagInfo == 'pfImpactParameterTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfImpactParameterTagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
process, task)
if explicitJTA:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.explicitJTA = cms.bool(explicitJTA)
if tightBTagNTkHits:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.minimumNumberOfPixelHits = cms.int32(2)
_btagInfo.minimumNumberOfHits = cms.int32(8)
if btagInfo == 'pfImpactParameterAK8TagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfImpactParameterAK8TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
process, task)
if explicitJTA:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.explicitJTA = cms.bool(explicitJTA)
if tightBTagNTkHits:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.minimumNumberOfPixelHits = cms.int32(2)
_btagInfo.minimumNumberOfHits = cms.int32(8)
if btagInfo == 'pfImpactParameterCA15TagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfImpactParameterCA15TagInfos.clone(jets = jetSource,primaryVertex=pvSource,candidates=pfCandidates),
process, task)
if explicitJTA:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.explicitJTA = cms.bool(explicitJTA)
if tightBTagNTkHits:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.minimumNumberOfPixelHits = cms.int32(2)
_btagInfo.minimumNumberOfHits = cms.int32(8)
if btagInfo == 'pfSecondaryVertexTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfSecondaryVertexTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
process, task)
if tightBTagNTkHits:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
_btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
if btagInfo == 'pfDeepCSVTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepCSVTagInfos.clone(
svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfDeepCSVNegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepCSVNegativeTagInfos.clone(
svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderNegativeTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfDeepCSVPositiveTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepCSVPositiveTagInfos.clone(
svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfDeepCMVATagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepCMVATagInfos.clone(
deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfDeepCMVANegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepCMVATagInfos.clone(
deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfDeepCMVAPositiveTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepCMVATagInfos.clone(
deepNNTagInfos = cms.InputTag(btagPrefix+'pfDeepCSVTagInfos'+labelName+postfix),
ipInfoSrc = cms.InputTag(btagPrefix+"pfImpactParameterTagInfos"+labelName+postfix),
muInfoSrc = cms.InputTag(btagPrefix+"softPFMuonsTagInfos"+labelName+postfix),
elInfoSrc = cms.InputTag(btagPrefix+"softPFElectronsTagInfos"+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
extSVCollection=svSource),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderAK8TagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderAK8TagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterAK8TagInfos'+labelName+postfix),
extSVCollection=svSource),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfBoostedDoubleSVAK8TagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfBoostedDoubleSVAK8TagInfos.clone(
svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderAK8TagInfos'+labelName+postfix)),
process, task)
if btagInfo == 'pfInclusiveSecondaryVertexFinderCA15TagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderCA15TagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterCA15TagInfos'+labelName+postfix),
extSVCollection=svSource),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfBoostedDoubleSVCA15TagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfBoostedDoubleSVCA15TagInfos.clone(
svTagInfos = cms.InputTag(btagPrefix+'pfInclusiveSecondaryVertexFinderCA15TagInfos'+labelName+postfix)),
process, task)
if btagInfo == 'pfInclusiveSecondaryVertexFinderCvsLTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderCvsLTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
extSVCollection=svSourceCvsL),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderNegativeCvsLTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
extSVCollection = btagPrefix+'inclusiveCandidateNegativeSecondaryVerticesCvsL'+labelName+postfix),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'pfGhostTrackVertexTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfGhostTrackVertexTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
process, task)
if btagInfo == 'pfSecondaryVertexNegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfSecondaryVertexNegativeTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix)),
process, task)
if tightBTagNTkHits:
_btagInfo = getattr(process, btagPrefix+btagInfo+labelName+postfix)
_btagInfo.trackSelection.pixelHitsMin = cms.uint32(2)
_btagInfo.trackSelection.totalHitsMin = cms.uint32(8)
if btagInfo == 'pfInclusiveSecondaryVertexFinderNegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfInclusiveSecondaryVertexFinderNegativeTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'pfImpactParameterTagInfos'+labelName+postfix),
extSVCollection=cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'impactParameterTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.impactParameterTagInfos.clone(
jetTracks = cms.InputTag('jetTracksAssociatorAtVertex'+labelName+postfix),
primaryVertex=pvSource),
process, task)
if btagInfo == 'secondaryVertexTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.secondaryVertexTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
process, task)
if btagInfo == 'inclusiveSecondaryVertexFinderTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.inclusiveSecondaryVertexFinderTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'inclusiveSecondaryVertexFinderFilteredTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.inclusiveSecondaryVertexFinderFilteredTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'secondaryVertexNegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.secondaryVertexNegativeTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
process, task)
if btagInfo == 'inclusiveSecondaryVertexFinderNegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.inclusiveSecondaryVertexFinderNegativeTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'inclusiveSecondaryVertexFinderFilteredNegativeTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.inclusiveSecondaryVertexFinderFilteredNegativeTagInfos.clone(
trackIPTagInfos = cms.InputTag(btagPrefix+'impactParameterTagInfos'+labelName+postfix)),
process, task)
if svClustering or fatJets != cms.InputTag(''):
setupSVClustering(getattr(process, btagPrefix+btagInfo+labelName+postfix), svClustering, algo, rParam, fatJets, groomedFatJets)
if btagInfo == 'softMuonTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.softMuonTagInfos.clone(jets = jetSource, primaryVertex=pvSource),
process, task)
if btagInfo == 'softPFMuonsTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.softPFMuonsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, muons=muSource),
process, task)
if btagInfo == 'softPFElectronsTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.softPFElectronsTagInfos.clone(jets = jetSource, primaryVertex=pvSource, electrons=elSource),
process, task)
if 'DeepFlavourTagInfos' in btagInfo:
svUsed = svSource
if btagInfo == 'pfNegativeDeepFlavourTagInfos':
deep_csv_tag_infos = 'pfDeepCSVNegativeTagInfos'
svUsed = cms.InputTag(btagPrefix+'inclusiveCandidateNegativeSecondaryVertices'+labelName+postfix)
flip = True
else:
deep_csv_tag_infos = 'pfDeepCSVTagInfos'
flip = False
# use right input tags when running with RECO PF candidates, which actually
# depens of wether jets were slimmed or not (check for s/S-limmed in name)
if not ('limmed' in jetSource.value()):
puppi_value_map = cms.InputTag("puppi")
vertex_associator = cms.InputTag("primaryVertexAssociation","original")
else:
puppi_value_map = cms.InputTag("")
vertex_associator = cms.InputTag("")
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepFlavourTagInfos.clone(
jets = jetSource,
vertices=pvSource,
secondary_vertices=svUsed,
shallow_tag_infos = cms.InputTag(btagPrefix+deep_csv_tag_infos+labelName+postfix),
puppi_value_map = puppi_value_map,
vertex_associator = vertex_associator,
flip = flip),
process, task)
if btagInfo == 'pfDeepDoubleXTagInfos':
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepDoubleXTagInfos.clone(
jets = jetSource,
vertices=pvSource,
secondary_vertices=svSource,
shallow_tag_infos = cms.InputTag(btagPrefix+'pfBoostedDoubleSVAK8TagInfos'+labelName+postfix),
),
process, task)
if btagInfo == 'pfDeepBoostedJetTagInfos':
if pfCandidates.value() == 'packedPFCandidates':
# case 1: running over jets whose daughters are PackedCandidates (only via updateJetCollection for now)
jetSrcName = jetSource.value().lower()
if 'updated' in jetSrcName:
puppi_value_map = ""
vertex_associator = ""
if 'withpuppidaughter' in jetSrcName:
# special case for Puppi jets reclustered from MiniAOD by analyzers
# need to specify 'WithPuppiDaughters' in the postfix when calling updateJetCollection
# daughters of these jets are already scaled by their puppi weights
has_puppi_weighted_daughters = True
else:
# default case for updating jet collection stored in MiniAOD, e.g., slimmedJetsAK8
# daughters are links to the original PackedCandidates, so NOT scaled by their puppi weights yet
has_puppi_weighted_daughters = False
else:
raise ValueError("Invalid jet collection: %s. pfDeepBoostedJetTagInfos only supports running via updateJetCollection." % jetSource.value())
elif pfCandidates.value() == 'particleFlow':
raise ValueError("Running pfDeepBoostedJetTagInfos with reco::PFCandidates is currently not supported.")
# case 2: running on new jet collection whose daughters are PFCandidates (e.g., cluster jets in RECO/AOD)
# daughters are the particles used in jet clustering, so already scaled by their puppi weights
# Uncomment the lines below after running pfDeepBoostedJetTagInfos with reco::PFCandidates becomes supported
# has_puppi_weighted_daughters = True
# puppi_value_map = "puppi"
# vertex_associator = "primaryVertexAssociation:original"
else:
raise ValueError("Invalid pfCandidates collection: %s." % pfCandidates.value())
addToProcessAndTask(btagPrefix+btagInfo+labelName+postfix,
btag.pfDeepBoostedJetTagInfos.clone(
jets = jetSource,
vertices = pvSource,
secondary_vertices = svSource,
has_puppi_weighted_daughters = has_puppi_weighted_daughters,
puppi_value_map = puppi_value_map,
vertex_associator = vertex_associator,
),
process, task)
acceptedTagInfos.append(btagInfo)
elif hasattr(toptag, btagInfo) :
acceptedTagInfos.append(btagInfo)
else:
print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagInfo))
## setup all required btagDiscriminators
acceptedBtagDiscriminators = list()
for discriminator_name in btagDiscriminators :
btagDiscr = discriminator_name.split(':')[0] #split input tag to get the producer label
#print discriminator_name, '-->', btagDiscr
if hasattr(btag,btagDiscr):
newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
if hasattr(process, newDiscr):
pass
elif hasattr(getattr(btag, btagDiscr), 'tagInfos'):
addToProcessAndTask(
newDiscr,
getattr(btag, btagDiscr).clone(
tagInfos = cms.VInputTag(
*[ cms.InputTag(btagPrefix+x+labelName+postfix) \
for x in supportedBtagDiscr[discriminator_name][0] ]
)
),
process,
task
)
elif hasattr(getattr(btag, btagDiscr), 'src'):
addToProcessAndTask(
newDiscr,
getattr(btag, btagDiscr).clone(
src = cms.InputTag(btagPrefix+supportedBtagDiscr[discriminator_name][0][0]+labelName+postfix)
),
process,
task
)
else:
raise ValueError('I do not know how to update %s it does not have neither "tagInfos" nor "src" attributes' % btagDiscr)
acceptedBtagDiscriminators.append(discriminator_name)
else:
print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
#update meta-taggers, if any
for meta_tagger in present_meta:
btagDiscr = meta_tagger.split(':')[0] #split input tag to get the producer label
#print discriminator_name, '-->', btagDiscr
if hasattr(btag,btagDiscr):
newDiscr = btagPrefix+btagDiscr+labelName+postfix #new discriminator name
if hasattr(process, newDiscr):
pass
else:
addToProcessAndTask(
newDiscr,
getattr(btag, btagDiscr).clone(),
process,
task
)
for dependency in supportedMetaDiscr[meta_tagger]:
if ':' in dependency:
new_dep = btagPrefix+dependency.split(':')[0]+labelName+postfix+':'+dependency.split(':')[1]
else:
new_dep = btagPrefix+dependency+labelName+postfix
replace = MassSearchReplaceAnyInputTagVisitor(dependency, new_dep)
replace.doIt(getattr(process, newDiscr), newDiscr)
acceptedBtagDiscriminators.append(meta_tagger)
else:
print(' --> %s ignored, since not available via RecoBTag.Configuration.RecoBTag_cff!'%(btagDiscr))
## replace corresponding tags for pat jet production
patJets.tagInfoSources = cms.VInputTag( *[ cms.InputTag(btagPrefix+x+labelName+postfix) for x in acceptedTagInfos ] )
patJets.discriminatorSources = cms.VInputTag(*[
cms.InputTag(btagPrefix+x+labelName+postfix) \
if ':' not in x else \
cms.InputTag(btagPrefix+x.split(':')[0]+labelName+postfix+':'+x.split(':')[1]) \
for x in acceptedBtagDiscriminators
])
if len(acceptedBtagDiscriminators) > 0 :
patJets.addBTagInfo = True
## if re-running IVF
if runIVF:
if not tightBTagNTkHits:
if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices': ## MiniAOD case
if not runIVFforCTagOnly: rerunningIVFMiniAOD()
else:
rerunningIVF()
from PhysicsTools.PatAlgos.tools.helpers import loadWithPrefix
ivfbTagInfos = ['pfInclusiveSecondaryVertexFinderTagInfos', 'pfInclusiveSecondaryVertexFinderAK8TagInfos', 'pfInclusiveSecondaryVertexFinderCA15TagInfos']
if any(i in acceptedTagInfos for i in ivfbTagInfos) and not runIVFforCTagOnly:
if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
if tightBTagNTkHits:
if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
_temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
_temp.minHits = cms.uint32(8)
## MiniAOD case
if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinder' ):
_temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinder')
_temp.primaryVertices = pvSource
_temp.tracks = pfCandidates
if hasattr( process, btagPrefix+'candidateVertexArbitrator' ):
_temp = getattr(process, btagPrefix+'candidateVertexArbitrator')
_temp.primaryVertices = pvSource
_temp.tracks = pfCandidates
if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVertices' ) and not hasattr( process, svSource.getModuleLabel() ):
addToProcessAndTask(svSource.getModuleLabel(),
getattr(process, btagPrefix+'inclusiveCandidateSecondaryVertices').clone(),
process, task)
if any(i in acceptedTagInfos for i in ivfcTagInfos):
if not hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
loadWithPrefix(process, 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff', btagPrefix, task.label())
if tightBTagNTkHits:
if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
_temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
_temp.minHits = cms.uint32(8)
## MiniAOD case
if pvSource.getModuleLabel() == 'offlineSlimmedPrimaryVertices':
if hasattr( process, btagPrefix+'inclusiveCandidateVertexFinderCvsL' ):
_temp = getattr(process, btagPrefix+'inclusiveCandidateVertexFinderCvsL')
_temp.primaryVertices = pvSource
_temp.tracks = pfCandidates
if hasattr( process, btagPrefix+'candidateVertexArbitratorCvsL' ):
_temp = getattr(process, btagPrefix+'candidateVertexArbitratorCvsL')
_temp.primaryVertices = pvSource
_temp.tracks = pfCandidates
if hasattr( process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL' ) and not hasattr( process, svSourceCvsL.getModuleLabel() ):
addToProcessAndTask(svSourceCvsL.getModuleLabel(),
getattr(process, btagPrefix+'inclusiveCandidateSecondaryVerticesCvsL').clone(),
process, task)
if 'inclusiveSecondaryVertexFinderTagInfos' in acceptedTagInfos:
if not hasattr( process, 'inclusiveVertexing' ):
process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
task.add(process.inclusiveVertexingTask)
task.add(process.inclusiveCandidateVertexingTask)
task.add(process.inclusiveCandidateVertexingCvsLTask)
if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
if not hasattr( process, 'inclusiveVertexing' ):
process.load( 'RecoVertex.AdaptiveVertexFinder.inclusiveVertexing_cff' )
task.add(process.inclusiveVertexingTask)
task.add(process.inclusiveCandidateVertexingTask)
task.add(process.inclusiveCandidateVertexingCvsLTask)
if 'inclusiveSecondaryVertexFinderFilteredTagInfos' in acceptedTagInfos:
if not hasattr( process, 'inclusiveSecondaryVerticesFiltered' ):
process.load( 'RecoBTag.SecondaryVertex.inclusiveSecondaryVerticesFiltered_cfi' )
task.add(process.inclusiveSecondaryVerticesFiltered)
task.add(process.bVertexFilter)
if not hasattr( process, 'bToCharmDecayVertexMerged' ):
process.load( 'RecoBTag.SecondaryVertex.bToCharmDecayVertexMerger_cfi' )
task.add(process.bToCharmDecayVertexMerged)
if 'caTopTagInfos' in acceptedTagInfos :
patJets.addTagInfos = True
if not hasattr( process, 'caTopTagInfos' ) and not hasattr( process, 'caTopTagInfosAK8' ):
process.load( 'RecoJets.JetProducers.caTopTaggers_cff' )
task.add(process.caTopTaggersTask)
class AddJetCollection(ConfigToolBase):
"""
Tool to add a new jet collection to your PAT Tuple or to modify an existing one.
"""
_label='addJetCollection'
_defaultParameters=dicttypes.SortedKeysDict()
def __init__(self):
"""
Initialize elements of the class. Note that the tool needs to be derived from ConfigToolBase to be usable in the configEditor.
"""
## initialization of the base class
ConfigToolBase.__init__(self)
## add all parameters that should be known to the class
self.addParameter(self._defaultParameters,'labelName', 'UNDEFINED', "Label name of the new patJet collection.", str)
self.addParameter(self._defaultParameters,'postfix','', "Postfix from usePF2PAT.", str)
self.addParameter(self._defaultParameters,'btagPrefix','', "Prefix to be added to b-tag discriminator and TagInfo names", str)
self.addParameter(self._defaultParameters,'jetSource','', "Label of the input collection from which the new patJet collection should be created", cms.InputTag)
self.addParameter(self._defaultParameters,'pfCandidates',cms.InputTag('particleFlow'), "Label of the input collection for candidatecandidatese used in b-tagging", cms.InputTag)
self.addParameter(self._defaultParameters,'explicitJTA', False, "Use explicit jet-track association")
self.addParameter(self._defaultParameters,'pvSource',cms.InputTag('offlinePrimaryVertices'), "Label of the input collection for primary vertices used in b-tagging", cms.InputTag)
self.addParameter(self._defaultParameters,'svSource',cms.InputTag('inclusiveCandidateSecondaryVertices'), "Label of the input collection for IVF vertices used in b-tagging", cms.InputTag)
self.addParameter(self._defaultParameters,'elSource',cms.InputTag('gedGsfElectrons'), "Label of the input collection for electrons used in b-tagging", cms.InputTag)
self.addParameter(self._defaultParameters,'muSource',cms.InputTag('muons'), "Label of the input collection for muons used in b-tagging", cms.InputTag)
self.addParameter(self._defaultParameters,'runIVF', False, "Re-run IVF secondary vertex reconstruction")
self.addParameter(self._defaultParameters,'tightBTagNTkHits', False, "Enable legacy tight b-tag track selection")
self.addParameter(self._defaultParameters,'loadStdRecoBTag', False, "Load the standard reconstruction b-tagging modules")
self.addParameter(self._defaultParameters,'svClustering', False, "Secondary vertices ghost-associated to jets using jet clustering (mostly intended for subjets)")
self.addParameter(self._defaultParameters,'fatJets', cms.InputTag(''), "Fat jet collection used for secondary vertex clustering", cms.InputTag)
self.addParameter(self._defaultParameters,'groomedFatJets', cms.InputTag(''), "Groomed fat jet collection used for secondary vertex clustering", cms.InputTag)
self.addParameter(self._defaultParameters,'algo', 'AK', "Jet algorithm of the input collection from which the new patJet collection should be created")
self.addParameter(self._defaultParameters,'rParam', 0.4, "Jet size (distance parameter R used in jet clustering)")
self.addParameter(self._defaultParameters,'getJetMCFlavour', True, "Get jet MC truth flavour")
self.addParameter(self._defaultParameters,'genJetCollection', cms.InputTag("ak4GenJets"), "GenJet collection to match to", cms.InputTag)
self.addParameter(self._defaultParameters,'genParticles', cms.InputTag("genParticles"), "GenParticle collection to be used", cms.InputTag)
self.addParameter(self._defaultParameters,'jetCorrections',None, "Add all relevant information about jet energy corrections that you want to be added to your new patJet \
collection. The format has to be given in a python tuple of type: (\'AK4Calo\',[\'L2Relative\', \'L3Absolute\'], patMet). Here the first argument corresponds to the payload \
in the CMS Conditions database for the given jet collection; the second argument corresponds to the jet energy correction levels that you want to be embedded into your \
new patJet collection. This should be given as a list of strings. Available values are L1Offset, L1FastJet, L1JPTOffset, L2Relative, L3Absolute, L5Falvour, L7Parton; the \
third argument indicates whether MET(Type1/2) corrections should be applied corresponding to the new patJetCollection. If so a new patMet collection will be added to your PAT \
Tuple in addition to the raw patMet. This new patMet collection will have the MET(Type1/2) corrections applied. The argument can have the following types: \'type-1\' for \
type-1 corrected MET; \'type-2\' for type-1 plus type-2 corrected MET; \'\' or \'none\' if no further MET corrections should be applied to your MET. The arguments \'type-1\' \
and \'type-2\' are not case sensitive.", tuple, acceptNoneValue=True)
self.addParameter(self._defaultParameters,'btagDiscriminators',['None'], "If you are interested in btagging, in most cases just the labels of the btag discriminators that \
you are interested in is all relevant information that you need for a high level analysis. Add here all btag discriminators, that you are interested in as a list of strings. \
If this list is empty no btag discriminator information will be added to your new patJet collection.", allowedValues=(list(set().union(supportedBtagDiscr.keys(),supportedMetaDiscr.keys()))),Type=list)
self.addParameter(self._defaultParameters,'btagInfos',['None'], "The btagInfos objects contain all relevant information from which all discriminators of a certain \
type have been calculated. You might be interested in keeping this information for low level tests or to re-calculate some discriminators from hand. Note that this information \
on the one hand can be very space consuming and that it is not necessary to access the pre-calculated btag discriminator information that has been derived from it. Only in very \
special cases the btagInfos might really be needed in your analysis. Add here all btagInfos, that you are interested in as a list of strings. If this list is empty no btagInfos \
will be added to your new patJet collection.", allowedValues=supportedBtagInfos,Type=list)
self.addParameter(self._defaultParameters,'jetTrackAssociation',False, "Add JetTrackAssociation and JetCharge from reconstructed tracks to your new patJet collection. This \
switch is only of relevance if you don\'t add any btag information to your new patJet collection (btagDiscriminators or btagInfos) and still want this information added to \
your new patJetCollection. If btag information of any form is added to the new patJet collection this information will be added automatically.")
self.addParameter(self._defaultParameters,'outputModules',['out'],"Add a list of all output modules to which you would like the new jet collection to be added. Usually this is \
just one single output module with name \'out\', which corresponds also the default configuration of the tool. There is cases though where you might want to add this collection \
to more than one output module.")
## set defaults
self._parameters=copy.deepcopy(self._defaultParameters)
## add comments
self._comment = "This is a tool to add more patJet collectinos to your PAT Tuple or to re-configure the default collection. You can add and embed additional information like jet\
energy correction factors, btag information and generator match information to the new patJet collection depending on the parameters that you pass on to this function. Consult \
the descriptions of each parameter for more information."
def getDefaultParameters(self):
"""
Return default parameters of the class
"""
return self._defaultParameters
def __call__(self,process,labelName=None,postfix=None,btagPrefix=None,jetSource=None,pfCandidates=None,explicitJTA=None,pvSource=None,svSource=None,elSource=None,muSource=None,runIVF=None,tightBTagNTkHits=None,loadStdRecoBTag=None,svClustering=None,fatJets=None,groomedFatJets=None,algo=None,rParam=None,getJetMCFlavour=None,genJetCollection=None,genParticles=None,jetCorrections=None,btagDiscriminators=None,btagInfos=None,jetTrackAssociation=None,outputModules=None):
"""
Function call wrapper. This will check the parameters and call the actual implementation that
can be found in toolCode via the base class function apply.
"""
if labelName is None:
labelName=self._defaultParameters['labelName'].value
self.setParameter('labelName', labelName)
if postfix is None:
postfix=self._defaultParameters['postfix'].value
self.setParameter('postfix', postfix)
if btagPrefix is None:
btagPrefix=self._defaultParameters['btagPrefix'].value
self.setParameter('btagPrefix', btagPrefix)
if jetSource is None:
jetSource=self._defaultParameters['jetSource'].value
self.setParameter('jetSource', jetSource)
if pfCandidates is None:
pfCandidates=self._defaultParameters['pfCandidates'].value
self.setParameter('pfCandidates', pfCandidates)
if explicitJTA is None:
explicitJTA=self._defaultParameters['explicitJTA'].value
self.setParameter('explicitJTA', explicitJTA)
if pvSource is None:
pvSource=self._defaultParameters['pvSource'].value
self.setParameter('pvSource', pvSource)
if svSource is None:
svSource=self._defaultParameters['svSource'].value
self.setParameter('svSource', svSource)
if elSource is None:
elSource=self._defaultParameters['elSource'].value
self.setParameter('elSource', elSource)
if muSource is None:
muSource=self._defaultParameters['muSource'].value
self.setParameter('muSource', muSource)
if runIVF is None:
runIVF=self._defaultParameters['runIVF'].value
self.setParameter('runIVF', runIVF)
if tightBTagNTkHits is None:
tightBTagNTkHits=self._defaultParameters['tightBTagNTkHits'].value
self.setParameter('tightBTagNTkHits', tightBTagNTkHits)
if loadStdRecoBTag is None:
loadStdRecoBTag=self._defaultParameters['loadStdRecoBTag'].value
self.setParameter('loadStdRecoBTag', loadStdRecoBTag)
if svClustering is None:
svClustering=self._defaultParameters['svClustering'].value
self.setParameter('svClustering', svClustering)
if fatJets is None:
fatJets=self._defaultParameters['fatJets'].value
self.setParameter('fatJets', fatJets)
if groomedFatJets is None:
groomedFatJets=self._defaultParameters['groomedFatJets'].value
self.setParameter('groomedFatJets', groomedFatJets)
if algo is None:
algo=self._defaultParameters['algo'].value
self.setParameter('algo', algo)
if rParam is None:
rParam=self._defaultParameters['rParam'].value
self.setParameter('rParam', rParam)
if getJetMCFlavour is None:
getJetMCFlavour=self._defaultParameters['getJetMCFlavour'].value
self.setParameter('getJetMCFlavour', getJetMCFlavour)
if genJetCollection is None:
genJetCollection=self._defaultParameters['genJetCollection'].value
self.setParameter('genJetCollection', genJetCollection)
if genParticles is None:
genParticles=self._defaultParameters['genParticles'].value
self.setParameter('genParticles', genParticles)
if jetCorrections is None:
jetCorrections=self._defaultParameters['jetCorrections'].value
self.setParameter('jetCorrections', jetCorrections)
if btagDiscriminators is None:
btagDiscriminators=self._defaultParameters['btagDiscriminators'].value
self.setParameter('btagDiscriminators', btagDiscriminators)
if btagInfos is None:
btagInfos=self._defaultParameters['btagInfos'].value
self.setParameter('btagInfos', btagInfos)
if jetTrackAssociation is None:
jetTrackAssociation=self._defaultParameters['jetTrackAssociation'].value
self.setParameter('jetTrackAssociation', jetTrackAssociation)
if outputModules is None:
outputModules=self._defaultParameters['outputModules'].value
self.setParameter('outputModules', outputModules)
self.apply(process)
def toolCode(self, process):
"""
Tool code implementation
"""
task = getPatAlgosToolsTask(process)
## initialize parameters
labelName=self._parameters['labelName'].value
postfix=self._parameters['postfix'].value
btagPrefix=self._parameters['btagPrefix'].value
jetSource=self._parameters['jetSource'].value
pfCandidates=self._parameters['pfCandidates'].value
explicitJTA=self._parameters['explicitJTA'].value
pvSource=self._parameters['pvSource'].value
svSource=self._parameters['svSource'].value
elSource=self._parameters['elSource'].value
muSource=self._parameters['muSource'].value
runIVF=self._parameters['runIVF'].value
tightBTagNTkHits=self._parameters['tightBTagNTkHits'].value
loadStdRecoBTag=self._parameters['loadStdRecoBTag'].value