-
Notifications
You must be signed in to change notification settings - Fork 5
/
crosschecks.py
1341 lines (1042 loc) · 42.9 KB
/
crosschecks.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 OptionHandler import flag_as_option, flag_as_parser_options
import os, logging, copy, sys, re, numpy
from array import array
from math import sqrt
import ROOT
import LatestPaths, LatestBinning
import differentials
import differentialutils
from differentials.plotting.canvas import c
class XHCrossSectionComputer(object):
"""docstring for XHCrossSectionComputer"""
VBF = [
0.0302808 ,
0.08105017,
0.12008017,
0.28295281,
0.23772335,
0.17833799,
0.05676226,
0.01239741,
0.00041504
]
ttH = [
0.01870376,
0.08153892,
0.06226964,
0.18633147,
0.22279926,
0.26817637,
0.15245306,
0.01341177,
-0.00568425
]
ggH = LatestBinning.shape_pth_ggH
VBF_fid = LatestBinning.normalize([
4.01797329,
11.38545513,
16.26351532,
38.34970613,
33.52387842,
27.15370537,
8.07272155,
1.63987341,
0.13854119
])
ttH_fid = LatestBinning.normalize([
0.21016141,
1.13122164,
0.67626803,
2.9775316 ,
2.84087811,
4.56748822,
3.11240395,
0.21556108,
-0.12546014
])
xH = LatestBinning.shape_pth_xH
inclxs_ggF = LatestBinning.YR4_ggF_n3lo
inclxs_ttH = LatestBinning.YR4_ttH
inclxs_VBF = LatestBinning.YR4_VBF
inclxs_VH = LatestBinning.YR4_WH + LatestBinning.YR4_ZH
inclxs_xH = inclxs_ttH + inclxs_VBF + inclxs_VH
fidxs_ggF = LatestBinning.SM_BR_hgg * 0.60 * LatestBinning.YR4_ggF_n3lo
fidxs_ttH = LatestBinning.SM_BR_hgg * 0.52 * LatestBinning.YR4_ttH
fidxs_VBF = LatestBinning.SM_BR_hgg * 0.60 * LatestBinning.YR4_VBF
fidxs_VH = LatestBinning.SM_BR_hgg * 0.52 * (LatestBinning.YR4_WH + LatestBinning.YR4_ZH)
fidxs_xH = fidxs_ttH + fidxs_VBF + fidxs_VH
def __init__(self):
super(XHCrossSectionComputer, self).__init__()
# Diff cross section, full phase space
def dsigma_full_ggH(self, kappat=1.0):
return [ acc * self.inclxs_ggF for acc in self.ggH ]
def dsigma_full_ttH(self, kappat=1.0):
return [ kappat**2 * acc * self.inclxs_ttH for acc in self.ttH ]
def dsigma_full_VBF(self):
return [ acc * self.inclxs_VBF for acc in self.VBF ]
def dsigma_full_VH(self):
return [ acc * self.inclxs_VH for acc in self.VH ]
def dsigma_full_xH(self):
return [ acc * self.inclxs_xH for acc in self.xH ]
# Diff cross section, fiducial phase space
def dsigma_fid_ttH(self, kappat=1.0):
return [ kappat**2 * acc * self.fidxs_ttH for acc in self.ttH_fid ]
def dsigma_fid_VBF(self):
return [ acc * self.fidxs_VBF for acc in self.VBF_fid ]
# Unbinned cross sections, in fid and full phase space
def sigma_fid_VBF_ttH(self, kappat=1.0):
return kappat**2 * self.fidxs_ttH + self.fidxs_VBF
def sigma_full_VBF_ttH(self, kappat=1.0):
return kappat**2 * self.inclxs_ttH + self.inclxs_VBF
# Fiducial acceptances per bin
def fid_acc_ttH(self, kappat=1.0):
return [ fid / full if full != 0. else 0. for fid, full in zip(self.dsigma_fid_ttH(kappat), self.dsigma_full_ttH(kappat)) ]
def fid_acc_VBF(self):
return [ fid / full for fid, full in zip(self.dsigma_fid_VBF(), self.dsigma_full_VBF()) ]
# Get fid acceptance xH based on ttH and VBF
def fid_acc_xH(self, kappat=1.0):
sigma_xH_full = self.sigma_full_VBF_ttH(kappat) # Neglecting VH for now
A_ttH = self.fid_acc_ttH(kappat)
dsigma_full_ttH = self.dsigma_full_ttH(kappat)
A_VBF = self.fid_acc_VBF()
dsigma_full_VBF = self.dsigma_full_VBF()
A_average = []
for i in xrange(len(A_ttH)):
A_average.append(
(dsigma_full_ttH[i] * A_ttH[i] + dsigma_full_VBF[i] * A_VBF[i])
/
(dsigma_full_ttH[i] + dsigma_full_VBF[i])
)
return A_average
# OLD:
def get_average_acceptance_ttH_VBF(self):
return [ (i+j)/(self.inclxs_xH-self.inclxs_VH) for i, j in zip(self.dsigma_full_ttH(), self.dsigma_full_VBF()) ]
def dsigma_full_ttH_kappatdep(self, kappat=1.0):
return [ kappat**2 * acc * self.inclxs_ttH for acc in self.ttH ]
def inclxs_ttH_kappatdep(self, kappat=1.0):
return kappat**2 * self.inclxs_ttH
def get_average_acceptance_ttH_VBF_kappatdep(self, kappat=1.0):
inclxs_xH_minus_VH = self.inclxs_VBF + self.inclxs_ttH_kappatdep(kappat)
return [
(i+j) / inclxs_xH_minus_VH
for i, j in zip(self.dsigma_full_ttH_kappatdep(kappat), self.dsigma_full_VBF())
]
@flag_as_option
def check_pasquale(args):
computer = XHCrossSectionComputer()
flist = lambda l: ', '.join([ '{0:7.4f}'.format(i) for i in l ])
print computer.dsigma_full_ggH()
print computer.dsigma_full_ttH()
print flist([ i/j for i, j in zip(computer.dsigma_full_ggH(), computer.dsigma_full_ttH()) ])
print flist([ i/j for i, j in zip(computer.dsigma_full_ggH(), computer.dsigma_full_ttH(kappat=3)) ])
def printlist(l):
print ', '.join([ '{0:7.4f}'.format(i) for i in l ])
@flag_as_option
def check_kappat_acceptance_effect(args):
computer = XHCrossSectionComputer()
flist = lambda l: ', '.join([ '{0:7.4f}'.format(i) for i in l ])
print 'SM fid acceptances:'
print 'VBF:' + flist(computer.fid_acc_VBF())
print 'ttH:' + flist(computer.fid_acc_ttH())
print
fvariation = lambda kappat: 'kappat = {0:<6} | A_average = {1}'.format(kappat, flist(computer.fid_acc_xH(kappat=kappat)))
print fvariation(0.0)
print fvariation(0.25)
print fvariation(0.5)
print fvariation(0.75)
print fvariation(1.0)
print fvariation(2.0)
print fvariation(3.0)
print fvariation(1000.0)
@flag_as_option
def check_kappat_acceptance_effect_old(args):
computer = XHCrossSectionComputer()
# printlist(computer.xH)
# printlist(computer.get_average_acceptance_ttH_VBF())
print 'acceptance_xH, kappa_t = 0.0 (VBF only, no ttH)'
printlist(computer.get_average_acceptance_ttH_VBF_kappatdep(0.0))
print 'acceptance_xH, kappa_t = 0.5'
printlist(computer.get_average_acceptance_ttH_VBF_kappatdep(0.5))
print 'acceptance_xH, kappa_t = 1.0 (SM)'
printlist(computer.get_average_acceptance_ttH_VBF_kappatdep(1.0))
print 'acceptance_xH, kappa_t = 1.5'
printlist(computer.get_average_acceptance_ttH_VBF_kappatdep(1.5))
print 'acceptance_xH, kappa_t = 3.0 (max probed range in our fits)'
printlist(computer.get_average_acceptance_ttH_VBF_kappatdep(3.0))
print 'acceptance_xH, kappa_t = 1000.0 (ttH only, no VBF)'
printlist(computer.get_average_acceptance_ttH_VBF_kappatdep(1000.0))
@flag_as_option
def check_numbers_vittorio(args):
VBF = [
4.01797329,
11.38545513,
16.26351532,
38.34970613,
33.52387842,
27.15370537,
8.07272155,
1.63987341,
0.13854119
]
ttH = [
0.21016141,
1.13122164,
0.67626803,
2.9775316 ,
2.84087811,
4.56748822,
3.11240395,
0.21556108,
-0.12546014
]
#____________________________________________________________________
class WSParametrizationCtCb(differentials.parametrization.WSParametrization):
def __init__(self, ws):
super(WSParametrizationCtCb, self).__init__(ws)
# Set the sm xs
self.get_smxs_from_ws()
self.set_smxs_xH(LatestBinning.obs_pth_xH.crosssection())
self.exp_binning = [ 0., 15., 30., 45., 80., 120., 200., 350., 600., 800. ]
self.select_decay_channel('hgg')
self.tag = ''
def get_histogram(self, ys):
return differentials.plotting.pywrappers.Histogram(
differentials.plotting.plotting_utils.get_unique_rootname(),
'',
self.exp_binning,
ys,
)
def get_hist_ggH(self, ct, cb):
xs = self.get_xs_exp_ggH(ct=ct, cb=cb)
hist = self.get_histogram(xs)
hist.title = 'ggH (#kappa_{{t}} = {0}, #kappa_{{b}} = {1})'.format(ct, cb)
if len(self.tag) > 0: hist.title = self.tag + ':' + hist.title
return hist
def get_hist_xH(self, ct, cb):
xs = self.get_xs_exp_xH(ct=ct, cb=cb)
hist = self.get_histogram(xs)
hist.title = 'xH (#kappa_{{t}} = {0}, #kappa_{{b}} = {1})'.format(ct, cb)
if len(self.tag) > 0: hist.title = self.tag + ':' + hist.title
return hist
def get_hist_smH(self, ct, cb):
xs_ggH = self.get_xs_exp_ggH(ct=ct, cb=cb)
xs_xH = self.get_xs_exp_xH(ct=ct, cb=cb)
xs = [ x1+x2 for x1, x2 in zip(xs_ggH, xs_xH) ]
hist = self.get_histogram(xs)
hist.title = 'smH (#kappa_{{t}} = {0}, #kappa_{{b}} = {1})'.format(ct, cb)
if len(self.tag) > 0: hist.title = self.tag + ':' + hist.title
return hist
@flag_as_option
def check_ctcb_xHBRscaling(args):
ws_noBRscaling = 'out/workspaces_May28/combWithHbb_TopCtCb_reweighted_scalingbbHttH_couplingdependentBRs.root'
ws_xHBRscaling = 'out/workspaces_May29/combWithHbb_TopCtCb_reweighted_scalingbbHttH_couplingdependentBRs.root'
noBRscaling = WSParametrizationCtCb(ws_noBRscaling)
xHBRscaling = WSParametrizationCtCb(ws_xHBRscaling)
xHBRscaling.tag = 'xH_scaling'
points = [
( 1.0, 1.0 ),
( 0.5, 0.0 ),
( 1.65, 1.4 ),
]
plotname = 'xcheck_xHBRscaling'
plot = differentials.plotting.plots.QuickPlot(
plotname,
x_min = 0., x_max= 350., y_min=0., y_max=20.
)
plot.x_title = 'pT'
plot.y_title = '#sigma'
for ct, cb in points:
plot.clear()
colors = iter([ 2, 4, 3, 8, 9, 42 ])
plot.plotname = plotname + '_ct{0}_cb{1}'.format(differentials.core.float_to_str(ct), differentials.core.float_to_str(cb))
color = next(colors)
smH_noBRscaling = noBRscaling.get_hist_smH(ct, cb)
smH_xHBRscaling = xHBRscaling.get_hist_smH(ct, cb)
smH_noBRscaling.color = color
smH_xHBRscaling.color = color
color = next(colors)
ggH_noBRscaling = noBRscaling.get_hist_ggH(ct, cb)
ggH_xHBRscaling = xHBRscaling.get_hist_ggH(ct, cb)
ggH_noBRscaling.color = color
ggH_xHBRscaling.color = color
color = next(colors)
xH_noBRscaling = noBRscaling.get_hist_xH(ct, cb)
xH_xHBRscaling = xHBRscaling.get_hist_xH(ct, cb)
xH_noBRscaling.color = color
xH_xHBRscaling.color = color
plot.add(smH_noBRscaling, 'repr_basic_histogram')
plot.add(smH_xHBRscaling, 'repr_basic_dashed_histogram')
plot.add(ggH_noBRscaling, 'repr_basic_histogram')
plot.add(ggH_xHBRscaling, 'repr_basic_dashed_histogram')
plot.add(xH_noBRscaling, 'repr_basic_histogram')
plot.add(xH_xHBRscaling, 'repr_basic_dashed_histogram')
plot.draw()
plot.wrapup()
persistence = []
new_tcolor_index = 5001
def make_lighter_color(color):
tcolor = ROOT.gROOT.GetColor(color)
r = tcolor.GetRed()
b = tcolor.GetBlue()
g = tcolor.GetGreen()
new_r = min(1.0, r + 4./256.)
new_b = min(1.0, b + 4./256.)
new_g = min(1.0, g + 4./256.)
print 'old r: {0}, new r: {1}'.format(r, new_r)
print 'old b: {0}, new b: {1}'.format(b, new_b)
print 'old g: {0}, new g: {1}'.format(g, new_g)
global new_tcolor_index
new_tcolor_index += 1
new_color_index = new_tcolor_index
new_tcolor = ROOT.TColor(new_color_index, new_r, new_b, new_g)
ROOT.SetOwnership(new_tcolor, False)
persistence.append(new_tcolor)
return new_tcolor.GetNumber()
#____________________________________________________________________
class ShapeGetterFromWS(object):
"""Wrapper around WSParametrization"""
def __init__(self, ws):
super(ShapeGetterFromWS, self).__init__()
self.ws = ws
self.parametrization = differentials.parametrization.WSParametrization(ws)
self.smxs = [ roovar.getVal() for roovar in differentials.core.read_set(ws, 'SMXS', return_names=False) ]
self.parametrization.set_smxs(self.smxs)
self.exp_binning = [ 0., 15., 30., 45., 80., 120. ]
def get_shape_histogram(self, kb, kc):
shape = self.parametrization.get_shape_exp(kappab=kb, kappac=kc)
histogram = differentials.plotting.pywrappers.Histogram(
differentials.plotting.plotting_utils.get_unique_rootname(),
'#kappa_{{b}} = {0}, #kappa_{{c}} = {1}'.format(kb, kc),
self.exp_binning,
shape,
# color = 2
)
return histogram
@flag_as_option
def check_shapes(args):
ggH = ShapeGetterFromWS('out/workspaces_May24/combination_Yukawa_reweighted_floatingBRs.root')
ggH_plus_bbH = ShapeGetterFromWS('out/workspaces_May22/combination_Yukawa_reweighted_scalingbbH_floatingBRs.root')
# plot_parametrizations_in_workspace_for_some_points(
# ggH_plus_bbH,
# plotname = 'xcheck_shapes_ggH_plus_bbH'
# )
# plot_parametrizations_in_workspace_for_some_points(
# ggH,
# plotname = 'xcheck_shapes_ggH'
# )
# shapes for some specific points for both
points = [
( 1.0, 1.0 ),
( 40.0, 1.0 ),
( -40.0, 1.0 ),
]
plot = differentials.plotting.plots.QuickPlot(
'xcheck_shapes_directcompare',
x_min = 0., x_max= 120., y_min=0., y_max=0.55
)
plot.x_title = 'pT'
plot.y_title = 'Shape'
colors = iter([ 2, 4, 3, 8, 9, 42 ])
for kb, kc in points:
color = next(colors)
hist_ggH = ggH.get_shape_histogram(kb, kc)
hist_ggH.color = color
hist_ggH_plus_bbH = ggH_plus_bbH.get_shape_histogram(kb, kc)
hist_ggH_plus_bbH.color = color
hist_ggH_plus_bbH.title += ' (incl. bbH)'
hist_ggH_plus_bbH.line_width = 4
plot.add(hist_ggH, 'repr_basic_histogram')
plot.add(hist_ggH_plus_bbH, 'repr_basic_dashed_histogram')
plot.draw()
plot.wrapup()
def plot_parametrizations_in_workspace_for_some_points(
shapegetter,
plotname='xcheck_shapes'
):
points = [
( 1., 1. ),
#
( 10., 1. ),
( 10., 10. ),
( 1., 10. ),
( -10., 1. ),
( -10., -10. ),
( 1., -10. ),
( 10., -10. ),
( -10., 10. ),
#
( 10000., 1. ),
( 10000., 10000. ),
( 1., 10000. ),
( -10000., 1. ),
( -10000., -10000. ),
( 1., -10000. ),
( 10000., -10000. ),
( -10000., 10000. ),
]
histograms = [ shapegetter.get_shape_histogram(kb, kc) for kb, kc in points ]
plot = differentials.plotting.plots.QuickPlot(
plotname,
x_min = 0., x_max= 120., y_min=0., y_max=1.0
)
plot.x_title = 'pT'
plot.y_title = 'Shape'
for histogram in histograms:
plot.add(histogram, 'repr_basic_histogram')
plot.draw()
plot.wrapup()
#____________________________________________________________________
@flag_as_option
def check_fiducial_vs_inclusive_shape(args):
# LatestBinning.shape_pth_smH
# LatestBinning.shape_pth_ggH
# LatestBinning.shape_pth_xH
auc = AcceptanceUncertaintyCalculator('suppliedInput/fromVittorio/scaleWeightVariationFullPhaseSpaceCombination_Pt.npz')
smH = auc.get_central_shape()
print LatestBinning.shape_pth_smH
print LatestBinning.shape_pth_ggH
#____________________________________________________________________
@flag_as_option
def xH_systematic_uncertainty(args):
ggH = LatestBinning.obs_pth_ggH
xH = LatestBinning.obs_pth_xH
ggH.Print()
print
xH.Print()
print 'inclusive xH (pb):', LatestBinning.YR4_xH
print 'Unc on inclusive xH (pb): {0} (fraction: {1:.4f} )'.format(
LatestBinning.xH_unc_inclusive, LatestBinning.xH_unc_inclusive_fraction
)
#____________________________________________________________________
class CouplingDependenceOfFunction(object):
"""docstring for CouplingDependenceOfFunction"""
def __init__(self):
super(CouplingDependenceOfFunction, self).__init__()
self.n_points = 100
def get_x_y(self, x_var, y_func, x_min=-10., x_max=10.):
x_axis = self.get_axis(self.n_points, x_min, x_max)
y_axis = []
init_val_x_var = x_var.getVal()
for x in x_axis:
x_var.setVal(x)
y_axis.append(y_func.getVal())
x_var.setVal(init_val_x_var)
return x_axis, y_axis
def get_axis(self, n_points, x_min, x_max):
dx = (x_max-x_min) / (n_points-1)
return [ x_min + i*dx for i in xrange(n_points) ]
def to_graph(self, x_axis, y_axis, title=''):
g = differentials.plotting.pywrappers.Graph(
differentials.plotting.plotting_utils.get_unique_rootname(),
title,
x_axis, y_axis
)
return g
def get_x_y_graph(self, x_var, y_func, x_min=-10., x_max=10.):
x_axis, y_axis = self.get_x_y(x_var, y_func, x_min, x_max)
return self.to_graph(x_axis, y_axis, '{0}({1})'.format(y_func.GetTitle(), x_var.GetTitle()) )
@flag_as_option
def plot_mu_parabolas(args):
ws = 'out/workspaces_May16/combination_Yukawa_reweighted_G1A_noTheoryUnc_scaledByMuTotalXS.root'
w = differentials.core.get_ws(ws)
mu_inc_unreweighted = w.function('totalXSmodifier')
kb = w.var('kappab')
kc = w.var('kappac')
calc = CouplingDependenceOfFunction()
g_kb = calc.get_x_y_graph(kb, mu_inc_unreweighted)
g_kc = calc.get_x_y_graph(kc, mu_inc_unreweighted)
plot = differentials.plotting.plots.QuickPlot(
'xy_' + mu_inc_unreweighted.GetTitle(),
x_min = -10., x_max = 10., y_min = 1., y_max = 3.
)
plot.x_title = '#kappa_{x}'
plot.y_title = mu_inc_unreweighted.GetTitle()
plot.add(g_kb, 'repr_basic_line')
plot.add(g_kc, 'repr_basic_line')
plot.draw()
plot.wrapup()
@flag_as_option
def crosscheck_htt_kappat_scaling(args):
exp_binning = LatestBinning.binning_pth
n_bins = len(exp_binning)-1
coupling_variations = differentials.theory.theory_utils.FileFinder(
cb=1.0, muR=1.0, muF=1.0, Q=1.0, directory=LatestPaths.theory.top.filedir
).get()
sm = [ v for v in coupling_variations if v.ct==1.0 and v.cg==0.0 ][0]
coupling_variations.pop(coupling_variations.index(sm))
parametrization = differentials.parametrization.Parametrization()
parametrization.parametrize_by_matrix_inversion = True
parametrization.do_linear_terms = False
parametrization.c1_name = 'ct'
parametrization.c2_name = 'cg'
parametrization.c2_SM = 0.0
for v in coupling_variations[:6]:
parametrization.add_variation(v.ct, v.cg, v.crosssection)
parametrization.parametrize()
parametrization.make_rebinner(sm.binBoundaries, exp_binning)
# Assume ttH shape is the same
# fraction_ttH_xH = LatestBinning.YR4_ttH / LatestBinning.YR4_xH
# smxs_ttH = [ fraction_ttH_xH * xs for xs in parametrization.evaluate(1.0, 0.0) ]
# smxs_ttH = [ s * LatestBinning.YR4_ttH for s in LatestBinning.shape_pth_xH ]
smxs_ttH = LatestBinning.obs_pth_ttH.crosssection()
# # Check at SM
# smxs_ggH = parametrization.get_xs_exp_integrated_per_bin(1., 0.)
# print sum(smxs_ttH), LatestBinning.YR4_ttH
# print sum(smxs_ggH), LatestBinning.YR4_ggF_n3lo
# for i in xrange(n_bins):
# r = (
# 'bin {0}, left = {1:<6.1f}, smxs_ttH = {2:<7.4f}, smxs_ggH = {3:<7.4f}'
# .format(
# i, exp_binning[i], smxs_ttH[i], smxs_ggH[i]
# )
# )
# print r
# sys.exit()
# Function that calculates the fraction ttH / ggH per bin
def fraction_ttH(ct, cg, verbose=True):
r = []
xs_ggH = parametrization.get_xs_exp_integrated_per_bin(ct, cg)
if verbose: print '\nct = {0:5.2f}, cg={1:5.2f}'.format(ct, cg)
for i in xrange(n_bins):
ttH = ct*ct * smxs_ttH[i]
ggH = xs_ggH[i]
r.append(ttH/ggH)
if verbose:
print 'Bin {0}: ttH = {1:<8.4f}, ggH = {2:<8.4f}, fraction = {3}'.format(
i, ttH, ggH, ttH/ggH
)
return r
# observed:
# 0.6 < ct < 3.4
# -0.2 < cg < 0.04
ct_min = 0.6
ct_max = 3.4
cg_min = -0.2
cg_max = 0.04
points = [
( 1.0, 0.0 ),
( ct_max, 0.0 ),
( ct_min, cg_max ),
( ct_max, cg_min )
]
histograms = []
for ct, cg in points:
histogram = differentials.plotting.pywrappers.Histogram(
differentials.plotting.plotting_utils.get_unique_rootname(),
'#kappa_{{t}} = {0}, c_{{g}} = {1}'.format(ct, cg),
exp_binning,
fraction_ttH(ct, cg),
# color = 2
)
histograms.append(histogram)
y_max = 1.25 * max([ H.y_max() for H in histograms ])
plot = differentials.plotting.plots.QuickPlot(
'ttH_fractions',
x_min = exp_binning[0], x_max=800.,
y_min = 0.0,
# y_max = 2.0,
y_max = y_max,
)
plot.x_title = 'p_{T} (GeV)'
plot.y_title = '(#kappa_{t}^{2} #sigma_{ttH}^{SM}) / #sigma_{ggH}(#kappa_{t},c_{g})'
for H in histograms:
plot.add(H, 'repr_basic_histogram')
plot.draw()
plot.wrapup()
@flag_as_option
def crosscheck_hbb_kappab_scaling(args):
coupling_variations = differentials.theory.theory_utils.FileFinder(
muR=1.0, muF=1.0, Q=1.0, directory=LatestPaths.theory.yukawa.filedir
).get()
sm = [ v for v in coupling_variations if v.kappab==1.0 and v.kappac==1.0 ][0]
coupling_variations.pop(coupling_variations.index(sm))
parametrization = differentials.parametrization.Parametrization()
parametrization.parametrize_by_matrix_inversion = True
parametrization.c1_name = 'kappab'
parametrization.c2_name = 'kappac'
for v in coupling_variations[:6]:
parametrization.add_variation(v.kappab, v.kappac, v.crosssection)
parametrization.parametrize()
# Assume bbH shape is the same
fraction_bbH_SM = LatestBinning.YR4_bbH / LatestBinning.YR4_ggF_n3lo
smxs_bbH = [ fraction_bbH_SM * xs for xs in parametrization.evaluate(1.0, 1.0) ]
n_bins = len(sm.crosssection)
# Function that calculates the fraction bbH / ggH per bin
def fraction_bbH(kappab, kappac):
r = []
xs_ggH = parametrization.evaluate(kappab, kappac)
for i in xrange(n_bins):
r.append(
kappab*kappab * smxs_bbH[i] / xs_ggH[i]
)
return r
# ( -2.1 < kb < 3.8 expected)
# ( -8.6 < kc < 10.5 expected)
kb_min = -2.1
kb_max = 3.8
kc_min = -8.6
kc_max = 10.5
points = [
( 1.0, 1.0 ),
( 1.0, kc_min ),
( 1.0, kc_max ),
( kb_min, 1.0 ),
( kb_max, 1.0 ),
( kb_min, kc_min ),
( kb_max, kc_max ),
]
histograms = []
for kappab, kappac in points:
histogram = differentials.plotting.pywrappers.Histogram(
differentials.plotting.plotting_utils.get_unique_rootname(),
'#kappa_{{b}} = {0}, #kappa_{{c}} = {1}'.format(kappab, kappac),
sm.binBoundaries,
fraction_bbH(kappab, kappac),
# color = 2
)
histograms.append(histogram)
y_max = 1.25 * max([ H.y_max() for H in histograms ])
plot = differentials.plotting.plots.QuickPlot(
'bbH_fractions',
x_min = sm.binBoundaries[0], x_max=sm.binBoundaries[-1], y_min=0.0, y_max = y_max
)
plot.x_title = 'p_{T} (GeV)'
plot.y_title = '(#kappa_{b}^{2} #sigma_{bbH}^{SM}) / #sigma_{ggH}(#kappa_{b},#kappa_{c})'
for H in histograms:
plot.add(H, 'repr_basic_histogram')
plot.draw()
plot.wrapup()
@flag_as_option
def theory_uncertainty_on_inclusive_xs_yukawa(args):
get_inc_xs_uncertainty(LatestPaths.theory.yukawa.filedir_gluoninduced)
get_inc_xs_uncertainty(LatestPaths.theory.yukawa.filedir)
def get_inc_xs_uncertainty(theory_filedir):
print '\nComputing inc xs uncertainty for {0}'.format(theory_filedir)
coupling_variations = differentials.theory.theory_utils.FileFinder(
kappab=1.0, kappac=1.0, directory=theory_filedir
).get()
sm = [ v for v in coupling_variations if v.muR==1.0 and v.muF==1.0 and v.Q==1.0 ][0]
coupling_variations.pop(coupling_variations.index(sm))
def print_var(v, is_sm=False):
r = ' muR = {0}, muF = {1}, Q = {2}: {3}'.format(v.muR, v.muF, v.Q, v.inc_xs)
if is_sm: r += ' (SM)'
print r
print 'Inc xs per scale variation:'
inc_xs = []
sm['inc_xs'] = sum(sm['crosssection_integrated'])
print_var(sm, is_sm=True)
for v in coupling_variations:
v['inc_xs'] = sum(v['crosssection_integrated'])
inc_xs.append(v.inc_xs)
print_var(v)
down = (sm.inc_xs - min(inc_xs)) / sm.inc_xs
up = (max(inc_xs) - sm.inc_xs) / sm.inc_xs
symm = 0.5*(abs(up)+abs(down))
print 'Unc down: {0}'.format(down)
print 'Unc up : {0}'.format(up)
print 'Unc symm: {0}'.format(symm)
print ' Double check for sm:'
n_bins = len(sm.binBoundaries)-1
smxs_inc = 0.0
for i in xrange(n_bins):
smxs_inc += sm.crosssection[i] * (sm.binBoundaries[i+1] - sm.binBoundaries[i])
print ' smxs_inc = {0} (from xs/GeV * bin widths)'.format(smxs_inc)
print ' smxs_inc = {0} (from sum(crosssection_integrated))'.format(sum(sm.crosssection_integrated))
class AcceptanceUncertaintyCalculator(object):
"""docstring for AcceptanceUncertaintyCalculator"""
def __init__(self, npz_file):
super(AcceptanceUncertaintyCalculator, self).__init__()
self.npz_file = npz_file
self.npz = numpy.load(self.npz_file)
self.reinit_lists()
def reinit_lists(self):
self.central = []
self.up = []
self.down = []
self.symm = []
def get_index(self, binstr):
return int(re.match(r'bin(\d+)', binstr).group(1))
def get_keys(self):
r = self.npz.keys()
r.sort(key=lambda k: self.get_index(k))
return r
def binstr_to_proper_str(self, binstr):
index = self.get_index(binstr)
boundaries = [ 0., 15., 30., 45., 80., 120., 200., 350., 600. ]
if index < 8:
return '[{0:0d},{1:0d})'.format(boundaries[index], boundaries[index+1])
else:
return '[{0:0d},#infty)'.format(boundaries[index])
def get_unc_for_bin(self, A):
B = list(A[:].flatten())
logging.debug(B)
B.pop(7) # Remove ratio 4 scale variations (higher index first to not mess up the next pop)
B.pop(5) # Remove ratio 4 scale variations
central = B[0]
up = abs(max(B))/central - 1
down = 1 - abs(min(B))/central
symm = 0.5*(abs(down)+abs(up))
return central, down, up, symm
def get_cud(self):
self.reinit_lists()
for k in self.get_keys():
logging.debug('Doing key {0}'.format(k))
central, down, up, symm = self.get_unc_for_bin(self.npz[k])
self.central.append(central)
self.up.append(up)
self.down.append(down)
self.symm.append(symm)
def get_central_shape(self):
self.get_cud()
return self.central
@flag_as_option
def check_acceptance_uncertainties(args):
# Get acceptance uncertainties
auc = AcceptanceUncertaintyCalculator('suppliedInput/fromVittorio/scaleWeightVariationFullPhaseSpaceCombination_Pt.npz')
auc.get_cud()
logging.info('Found following set of acceptance uncertainties per bin: {0}'.format(auc.symm))
obstuple = LatestBinning.obstuple_pth_ggH
scandict = LatestPaths.scan.pth_ggH.asimov if args.asimov else LatestPaths.scan.pth_ggH.observed
systshapemaker = differentials.systshapemaker.SystShapeMaker()
systshapemaker.set_sm(obstuple.combWithHbb.crosssection_over_binwidth(normalize_by_second_to_last_bin_width=False))
combWithHbb = differentials.scans.DifferentialSpectrum('combWithHbb', scandict.combWithHbb)
combWithHbb.set_sm(obstuple.combWithHbb.crosssection_over_binwidth(normalize_by_second_to_last_bin_width=True))
combWithHbb.read()
systonly_histogram, systonly_histogram_xs = systshapemaker.get_systonly_histogram(combWithHbb, scandict.combWithHbb_statonly)
# get symmetrized systematic uncertainty from histogram
symm = [ 0.5*(abs(up)+abs(down)) for down, up in zip(systonly_histogram.errs_down, systonly_histogram.errs_up) ]
logging.info('acceptance uncertainties: {0}'.format(auc.symm))
logging.info('syst error before adding: {0}'.format(symm))
symm_plus_AU = [ sqrt(s1**2+s2**2) for s1, s2 in zip(auc.symm, symm) ]
change_in_syst = [ after/before-1. for before, after in zip(symm, symm_plus_AU) ]
logging.info('syst error after adding: {0}'.format(symm_plus_AU))
logging.info('syst error rel change: {0}'.format(change_in_syst))
total_histogram = combWithHbb.to_hist()
total = [ 0.5*(abs(up)+abs(down)) for down, up in zip(total_histogram.errs_down, total_histogram.errs_up) ]
total_plus_AU = [ sqrt(s1**2+s2**2) for s1, s2 in zip(auc.symm, total) ]
change_in_total = [ after/before-1. for before, after in zip(total, total_plus_AU) ]
bounds = [ '0', '15', '30', '45', '80', '120', '200', '350', '600', 'infinity' ]
bounds_line = [ '[{0},{1})'.format(left, right) for left, right in zip(bounds[:-1], bounds[1:]) ]
table_py = [
['Bins'] + bounds_line,
['Acc. uncertainties'] + auc.symm,
['Rel. change in syst. unc.'] + change_in_syst,
['Rel. change in tot. unc.'] + change_in_total,
]
table = differentials.plotting.tables.Table()
table.from_list(table_py)
formatter = differentials.plotting.tables.Formatter(
include_sign = False,
n_decimals = 1,
is_percentage = True,
)
table.formatter = formatter
table.max_col_width = 28
print table.repr_terminal()
print table.repr_twiki()
@flag_as_option
def check_reweighting_for_inc_xs(args):
ws = LatestPaths.ws.yukawa.nominal.combination
w = differentials.core.get_ws(ws)
reweightor_names = [
'reweightor_ggH_PTH_0_15',
'reweightor_ggH_PTH_15_30',
'reweightor_ggH_PTH_30_45',
'reweightor_ggH_PTH_45_80',
'reweightor_ggH_PTH_80_120',
]
weights = []
for name in reweightor_names:
weights.append(w.function(name).getVal())
smxs_Pier = [ 13.0137626356, 12.3785279848, 6.87788869197, 7.08329398674, 3.07720573252 ]
smxs_Vitt = [ 12.158274514, 12.6947320234, 8.0889999211, 9.15091631806, 3.78165937525 ]
mu = sum(smxs_Pier) / sum(smxs_Vitt)
print 'Overall mu: {0}'.format(mu)
print ' sum(smxs) Pier (up to 120 GeV): {0}'.format(sum(smxs_Pier))
print ' sum(smxs) Vitt (up to 120 GeV): {0}'.format(sum(smxs_Vitt))
class PDFDrawer(object):
"""docstring for PDFDrawer"""
def __init__(self, ws):
super(PDFDrawer, self).__init__()
self.ws = ws
self.w = differentials.core.get_ws(self.ws)
self.MH = self.w.var('MH')
self.MH.setVal(125.)
self.mH_hgg = self.w.var('CMS_hgg_mass')
ROOT.SetOwnership( self.mH_hgg, False )
self.default_mH_hgg_range = [ self.mH_hgg.getMin(), self.mH_hgg.getMax() ]
self.default_mH_hgg_nBins = self.mH_hgg.getBins()
self.all_pdfs = []
all_pdfs_arglist = ROOT.RooArgList(self.w.allPdfs())
for i_pdf in xrange(all_pdfs_arglist.getSize()):
self.all_pdfs.append( all_pdfs_arglist[i_pdf].GetName() )
self.all_pdfs.sort()
self.bin_width = 0.25
self.hgg_cat = self.w.cat('CMS_channel')