-
Notifications
You must be signed in to change notification settings - Fork 1
/
limit.py
executable file
·760 lines (665 loc) · 28.5 KB
/
limit.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
#! /usr/bin/env python
###
### Macro for creating the exclusion limits plots from the combine outputs.
###
import os, sys, getopt
import copy
import time
import math
import json
from array import array
from ROOT import gROOT, gRandom
from ROOT import TFile, TTree, TCut, TH1F, TH2F, TGraph, TGraph2D, TGraphErrors, TGraphAsymmErrors
from ROOT import TStyle, TCanvas, TPad
from ROOT import TLegend, TLatex, TText, TColor
#from DMPD.Heppy.tools.samples import *
from utils import *
from theoryXs import HVT, SSM
#from thdmXs import THDM
# Combine output
# 0 - Observed Limit
# 1 - Expected 2.5%
# 2 - Expected 16.0%
# 3 - Expected 50.0%
# 4 - Expected 84.0%
# 5 - Expected 97.5%
# 6 - Significance
# 7 - p-value
# 8 - Best fit r
# 9 - Best fit r down
#10 - Best fit r up
import optparse
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage)
parser.add_option("-y", "--year", action="store", type="string", dest="year",default="2017")
parser.add_option("-M", "--isMC", action="store_true", default=False, dest="isMC")
parser.add_option("-c", "--category", action="store", type="string", dest="category", default="")
parser.add_option("-B", "--blind", action="store_true", default=False, dest="blind")
parser.add_option("-b", "--btagging", action="store", type="string", dest="btagging", default="medium")
parser.add_option("-A", "--Acceptance", action="store_true", default=False, dest="Acceptance")
parser.add_option("-E", "--Efficiency", action="store_true", default=False, dest="Efficiency")
parser.add_option("", "--no_BR", action="store_true", default=False, dest="no_BR")
(options, args) = parser.parse_args()
gStyle.SetOptStat(0)
gROOT.SetBatch(True)
#luminosities = {'2016':35920., '2017':41530., '2018':59740., 'run2':137190.}
luminosities = {'2016':36330., '2017':41530., '2018':59740., 'run2':137600.}
#HTOBB = 0.5824#0.577
MAIN_DIR = "./"
## FIXME temporary FIXME
#MAIN_DIR = "/eos/user/m/msommerh/jan/"
ZPTOBB = 1.
LUMI = 35867
MAXIMUM = {'XVHsl' : 4500., 'XWHsl' : 4500., 'XZHsl' : 3500., 'bb':100}
BTAGGING = options.btagging
YEAR = options.year
ISMC = options.isMC
CATEGORY = options.category
INCLUDEACC = options.Acceptance
INCLUDEEFF = options.Efficiency
NO_BR = options.no_BR
assert not (INCLUDEACC and INCLUDEEFF), "cannot use both acceptance and efficiency mode"
CAT_LABELS = {'bb': "2 b tag", 'bq': "1 b tag", 'mumu': "1 #mu", 'bb_bq': "2 b tag + 1 b tag"}
if YEAR not in ['2016', '2017', '2018', 'run2', 'run2c']:
print "unknown year:", YEAR
sys.exit()
if BTAGGING not in ['tight', 'medium', 'loose', 'semimedium']:
print "unknown btagging requirement:", BTAGGING
sys.exit()
if CATEGORY not in ['', 'bb', 'bq', 'mumu', 'bb_bq']:
print "unknown btagging category"
sys.exit()
if YEAR=='run2c':
YEAR='run2'
SY=True
print "Plotting the result from combine on separate years for run2..."
else:
SY=False
if CATEGORY=='bb_bq':
print "bb_bq category implemented only for separately combined fits"
sys.exit()
LUMI = luminosities[YEAR]
#SIGNALS = range(1600, 8000+1, 100)
SIGNALS = range(1800, 8000+1, 100)
ACCEPTANCE = {}
for s in range(500,9000+1,100): ACCEPTANCE[s] = 0.405 ##FIXME could include mass dependent exact value FIXME
EFFICIENCY = {1800: 0.244, 1900: 0.26349999999999996, 2000: 0.283, 2100: 0.286, 2200: 0.289, 2300: 0.292, 2400: 0.295, 2500: 0.298, 2600: 0.2956, 2700: 0.29319999999999996, 2800: 0.2908, 2900: 0.2884, 3000: 0.286, 3100: 0.2818, 3200: 0.2776, 3300: 0.2734, 3400: 0.2692, 3500: 0.265, 3600: 0.2604, 3700: 0.2558, 3800: 0.2512, 3900: 0.24659999999999999, 4000: 0.242, 4100: 0.2382, 4200: 0.2344, 4300: 0.2306, 4400: 0.2268, 4500: 0.223, 4600: 0.2192, 4700: 0.2154, 4800: 0.21159999999999998, 4900: 0.20779999999999998, 5000: 0.204, 5100: 0.2002, 5200: 0.1964, 5300: 0.1926, 5400: 0.1888, 5500: 0.185, 5600: 0.182, 5700: 0.179, 5800: 0.17600000000000002, 5900: 0.17300000000000001, 6000: 0.17, 6100: 0.16670000000000001, 6200: 0.16340000000000002, 6300: 0.16010000000000002, 6400: 0.15680000000000002, 6500: 0.15350000000000003, 6600: 0.1502, 6700: 0.1469, 6800: 0.1436, 6900: 0.1403, 7000: 0.137, 7100: 0.1342, 7200: 0.13140000000000002, 7300: 0.1286, 7400: 0.1258, 7500: 0.123, 7600: 0.1202, 7700: 0.1174, 7800: 0.11460000000000001, 7900: 0.1118, 8000: 0.109}
theoryLabel = {'B3' : "HVT model B (g_{V}=3)", 'A1' : "HVT model A (g_{V}=1)", "SSM" : "SSM Z'"}
theoryLineColor = {'B3' : 616-3, 'A1' : 629, "SSM" : 602}
theoryFillColor = {'B3' : 616-7, 'A1' : 625, 'SSM' : 856}
theoryFillStyle = {'B3' : 3002, 'A1' : 3013, 'SSM' : 3359}
def fillValues(filename):
val = {}
mass = []
for i, s in enumerate(SIGNALS):
try:
file = open(filename % s, 'r')
if file==None:
print "Signal", filename % s, "does not exist"
continue
val[s] = file.read().splitlines()
if len(val[s]) <= 1:
#signals.remove(s)
print "Signal", filename % s, "has no values"
continue
for i, f in enumerate(val[s]): val[s][i] = float(val[s][i])
if 'fullCls' in filename: val[1:5]=sorted(val[1:5])
if not s in mass: mass.append(s)
except:
print "File", filename % s, "does not exist"
pass
return mass, val
def limit():
method = ''
channel = "bb"
#if INCLUDEACC:
# particleP = "X"
#else:
# particleP = "Z'"
particleP = "Z'"
particle = 'b#bar{b}'
multF = ZPTOBB
THEORY = ['SSM', 'A1', 'B3']
#THEORY = ['A1', 'B3']
#if INCLUDEACC: THEORY.append('SSM')
suffix = "_"+BTAGGING
if ISMC: suffix += "_MC"
if SY: suffix += "_comb"
#if method=="cls": suffix="_CLs"
if INCLUDEACC:
suffix+="_acc"
elif INCLUDEEFF:
suffix+="_eff"
if SY:
filename = MAIN_DIR+"combine/limits/" + BTAGGING + "/combined_run2/"+ YEAR + "_M%d.txt"
else:
filename = MAIN_DIR+"/combine/limits/" + BTAGGING + "/"+ YEAR + "_M%d.txt"
if CATEGORY!="":
if SY:
if CATEGORY=='bb_bq':
filename = filename.replace(BTAGGING + "/combined_run2/", BTAGGING + "/combined_run2/"+CATEGORY+"_combined_")
else:
filename = filename.replace(BTAGGING + "/combined_run2/", BTAGGING + "/single_category/combined_run2/"+CATEGORY+"_")
else:
filename = filename.replace(BTAGGING + "/", BTAGGING + "/single_category/"+CATEGORY+"_")
suffix += "_"+CATEGORY
if ISMC: filename = filename.replace(".txt", "_MC.txt")
mass, val = fillValues(filename)
#print "mass =",mass
#print "val =", val
Obs0s = TGraph()
Exp0s = TGraph()
Exp1s = TGraphAsymmErrors()
Exp2s = TGraphAsymmErrors()
Sign = TGraph()
pVal = TGraph()
Best = TGraphAsymmErrors()
Theory = {}
json_output = {"obs":{}, "exp":{}, "exp_1up":{}, "exp_1down":{}, "exp_2up":{}, "exp_2down":{}, "theory_values": {}, "theory_uncert_up": {}, "theory_uncert_down": {}}
for i, m in enumerate(mass):
if not m in val:
print "Key Error:", m, "not in value map"
continue
if INCLUDEACC:
acc_factor = ACCEPTANCE[m]
elif INCLUDEEFF:
acc_factor = EFFICIENCY[m]
else:
acc_factor = 1.
n = Exp0s.GetN()
Obs0s.SetPoint(n, m, val[m][0]*multF*acc_factor)
Exp0s.SetPoint(n, m, val[m][3]*multF*acc_factor)
Exp1s.SetPoint(n, m, val[m][3]*multF*acc_factor)
Exp1s.SetPointError(n, 0., 0., (val[m][3]-val[m][2])*multF*acc_factor, (val[m][4]-val[m][3])*multF*acc_factor)
Exp2s.SetPoint(n, m, val[m][3]*multF*acc_factor)
Exp2s.SetPointError(n, 0., 0., (val[m][3]-val[m][1])*multF*acc_factor, (val[m][5]-val[m][3])*multF*acc_factor)
if len(val[m]) > 6: Sign.SetPoint(n, m, val[m][6])
if len(val[m]) > 7: pVal.SetPoint(n, m, val[m][7])
if len(val[m]) > 8: Best.SetPoint(n, m, val[m][8])
if len(val[m]) > 10: Best.SetPointError(n, 0., 0., abs(val[m][9]), val[m][10])
#print "m =", m, " --> Xsec*Br =", val[m][3]
json_output["obs"][m] = val[m][0]*multF*acc_factor
json_output["exp"][m] = val[m][3]*multF*acc_factor
json_output["exp_1up"][m] = val[m][4]*multF*acc_factor
json_output["exp_1down"][m] = val[m][2]*multF*acc_factor
json_output["exp_2up"][m] = val[m][5]*multF*acc_factor
json_output["exp_2down"][m] = val[m][1]*multF*acc_factor
for t in THEORY:
json_output["theory_values"][t] = {}
json_output["theory_uncert_down"][t] = {}
json_output["theory_uncert_up"][t] = {}
Theory[t] = TGraphAsymmErrors()
#Theory[t] = TGraph()
Xs_dict = HVT[t]['Z']['XS'] if t!='SSM' else SSM['Z']
for m in sorted(Xs_dict.keys()):
if m<1800: continue
if m>8000: continue
if INCLUDEACC and t!='SSM':
acc_factor = ACCEPTANCE[m]
elif INCLUDEEFF and t!='SSM':
acc_factor = EFFICIENCY[m]
else:
if not INCLUDEACC and t=='SSM':
acc_factor = 1./ACCEPTANCE[m]
else:
acc_factor = 1.
if INCLUDEEFF and t=='SSM':
acc_factor *= EFFICIENCY[m]
if m < SIGNALS[0] or m > SIGNALS[-1]: continue
#if m < mass[0] or m > mass[-1]: continue
#if t!= 'SSM' and m>4500: continue ## I don't have the higher mass xs
if m>4500: continue
if NO_BR:
br_factor = 1.
else:
br_factor = SSM["BrZ"][m]
XsZ, XsZ_Up, XsZ_Down = 0., 0., 0.
if t!='SSM':
XsZ = 1000.*HVT[t]['Z']['XS'][m]*br_factor#assuming the same BR as the SSM Z' one
XsZ_Up = XsZ*(1.+math.hypot(HVT[t]['Z']['QCD'][m][0]-1., HVT[t]['Z']['PDF'][m][0]-1.))
XsZ_Down = XsZ*(1.-math.hypot(1.-HVT[t]['Z']['QCD'][m][0], 1.-HVT[t]['Z']['PDF'][m][0]))
else:
XsZ = 1000.*SSM['Z'][m]*br_factor
XsZ_Up = XsZ*(1.+math.hypot(HVT['A1']['Z']['QCD'][m][0]-1., HVT['A1']['Z']['PDF'][m][0]-1.))
XsZ_Down = XsZ*(1.-math.hypot(1.-HVT['A1']['Z']['QCD'][m][0], 1.-HVT['A1']['Z']['PDF'][m][0]))
json_output["theory_values"][t][int(m)] = XsZ*acc_factor
json_output["theory_uncert_down"][t][int(m)] = XsZ_Down*acc_factor
json_output["theory_uncert_up"][t][int(m)] = XsZ_Up*acc_factor
n = Theory[t].GetN()
Theory[t].SetPoint(n, m, XsZ*acc_factor)
Theory[t].SetPointError(n, 0., 0., (XsZ-XsZ_Down)*acc_factor, (XsZ_Up-XsZ)*acc_factor)
Theory[t].SetLineColor(theoryLineColor[t])
Theory[t].SetFillColor(theoryFillColor[t])
Theory[t].SetFillStyle(theoryFillStyle[t])
Theory[t].SetLineWidth(2)
#Theory[t].SetLineStyle(7)
with open(MAIN_DIR+"combine/plotsLimit/ExclusionLimits/"+YEAR+suffix+".json", "w") as fp:
json.dump(json_output, fp)
Exp2s.SetLineWidth(2)
Exp2s.SetLineStyle(1)
Obs0s.SetLineWidth(3)
Obs0s.SetMarkerStyle(8)
Obs0s.SetMarkerSize(0.75)
Obs0s.SetLineColor(1)
Exp0s.SetLineStyle(2)
Exp0s.SetLineWidth(3)
Exp1s.SetFillColor(417) #kGreen+1
Exp1s.SetLineColor(417) #kGreen+1
Exp2s.SetFillColor(800) #kOrange
Exp2s.SetLineColor(800) #kOrange
#Exp2s.GetXaxis().SetTitle("m_{"+particleP+"} (GeV)")
Exp2s.GetXaxis().SetTitle(particleP+" mass (GeV)")
Exp2s.GetXaxis().SetTitleSize(Exp2s.GetXaxis().GetTitleSize()*1.25)
Exp2s.GetXaxis().SetNoExponent(True)
Exp2s.GetXaxis().SetMoreLogLabels(True)
#Exp2s.GetYaxis().SetTitle("#sigma("+particleP+") #bf{#it{#Beta}}("+particleP+" #rightarrow "+particle+"){} (fb)".format(" #times #Alpha" if INCLUDEACC else ""))
if NO_BR:
Exp2s.GetYaxis().SetTitle("#sigma("+particleP+"){} (fb)".format(" #Alpha" if INCLUDEACC else ""))
else:
Exp2s.GetYaxis().SetTitle("#sigma("+particleP+") #bf{#it{#Beta}}("+particleP+" #rightarrow "+particle+"){}{} (fb)".format(" #Alpha" if INCLUDEACC else "", " #Alpha #Epsilon" if INCLUDEEFF else ""))
Exp2s.GetYaxis().SetTitleOffset(1.5)
Exp2s.GetYaxis().SetNoExponent(True)
Exp2s.GetYaxis().SetMoreLogLabels()
Sign.SetLineWidth(2)
Sign.SetLineColor(629)
#Sign.GetXaxis().SetTitle("m_{"+particleP+"} (GeV)")
Sign.GetXaxis().SetTitle(particleP+" mass (GeV)")
Sign.GetXaxis().SetTitleSize(Sign.GetXaxis().GetTitleSize()*1.1)
Sign.GetYaxis().SetTitle("Significance")
pVal.SetLineWidth(2)
pVal.SetLineColor(629)
#pVal.GetXaxis().SetTitle("m_{"+particleP+"} (GeV)")
pVal.GetXaxis().SetTitle(particleP+" mass (GeV)")
pVal.GetXaxis().SetTitleSize(pVal.GetXaxis().GetTitleSize()*1.1)
pVal.GetYaxis().SetTitle("local p-Value")
Best.SetLineWidth(2)
Best.SetLineColor(629)
Best.SetFillColor(629)
Best.SetFillStyle(3003)
#Best.GetXaxis().SetTitle("m_{"+particleP+"} (GeV)")
Best.GetXaxis().SetTitle(particleP+" mass (GeV)")
Best.GetXaxis().SetTitleSize(Best.GetXaxis().GetTitleSize()*1.1)
Best.GetYaxis().SetTitle("Best Fit (pb)")
c1 = TCanvas("c1", "Exclusion Limits", 800, 600)
c1.cd()
#SetPad(c1.GetPad(0))
c1.GetPad(0).SetTopMargin(0.06)
c1.GetPad(0).SetRightMargin(0.05)
c1.GetPad(0).SetLeftMargin(0.12)
c1.GetPad(0).SetTicks(1, 1)
#c1.GetPad(0).SetGridx()
#c1.GetPad(0).SetGridy()
c1.GetPad(0).SetLogy()
Exp2s.Draw("A3")
Exp1s.Draw("SAME, 3")
for t in THEORY:
Theory[t].Draw("SAME, L3")
#Theory[t].Draw("SAME, L3X0Y0")
Exp0s.Draw("SAME, L")
if not options.blind: Obs0s.Draw("SAME, PL")
#setHistStyle(Exp2s)
Exp2s.GetXaxis().SetTitleSize(0.050)
Exp2s.GetYaxis().SetTitleSize(0.050)
Exp2s.GetXaxis().SetLabelSize(0.045)
Exp2s.GetYaxis().SetLabelSize(0.045)
Exp2s.GetXaxis().SetTitleOffset(0.90)
Exp2s.GetYaxis().SetTitleOffset(1.25)
Exp2s.GetYaxis().SetMoreLogLabels(True)
Exp2s.GetYaxis().SetNoExponent(True)
if INCLUDEACC:
Exp2s.GetYaxis().SetRangeUser(0.05, 5.e3)
elif INCLUDEEFF:
Exp2s.GetYaxis().SetRangeUser(0.015, 1.5e3)
else:
Exp2s.GetYaxis().SetRangeUser(0.1, 5.e3)
#else: Exp2s.GetYaxis().SetRangeUser(0.1, 1.e2)
#Exp2s.GetXaxis().SetRangeUser(mass[0], min(mass[-1], MAXIMUM[channel] if channel in MAXIMUM else 1.e6))
Exp2s.GetXaxis().SetRangeUser(SIGNALS[0], SIGNALS[-1])
#drawAnalysis(channel)
drawAnalysis("")
#drawRegion(channel, True)
drawRegion("", True)
#drawCMS(LUMI, "Simulation Preliminary") #Preliminary
if CATEGORY=="":
drawCMS(LUMI, "", suppress_year=True, CMS_pos=0.17)
#drawCMS(LUMI, "Internal", suppress_year=True)
#drawCMS(LUMI, "Preliminary", suppress_year=True)
#drawCMS(LUMI, "Work in Progress", suppressCMS=True)
#drawCMS(LUMI, "Preliminary")
#drawCMS(LUMI, "", suppressCMS=True)
else:
drawCMS(LUMI, CAT_LABELS[CATEGORY], suppress_year=True, CMS_pos=0.17)
#drawCMS(LUMI, "Work in Progress, "+CAT_LABELS[CATEGORY], suppressCMS=True)
#drawCMS(LUMI, "Preliminary "+CAT_LABELS[CATEGORY])
#drawCMS(LUMI, CAT_LABELS[CATEGORY], suppressCMS=True)
# legend
top = 0.9
nitems = 4 + len(THEORY)
leg = TLegend(0.53, top-nitems*0.3/5., 0.96, top)
#leg = TLegend(0.45, top-nitems*0.3/5., 0.98, top)
leg.SetBorderSize(0)
leg.SetFillStyle(0) #1001
leg.SetFillColor(0)
leg.SetHeader("95% CL upper limits")
leg.AddEntry(Obs0s, "Observed", "Pl")
leg.AddEntry(Exp0s, "Expected", "l")
leg.AddEntry(Exp1s, "#pm 1 std. deviation", "f")
leg.AddEntry(Exp2s, "#pm 2 std. deviation", "f")
for t in THEORY: leg.AddEntry(Theory[t], theoryLabel[t], "fl")
#for t in THEORY: leg.AddEntry(Theory[t], theoryLabel[t], "l")
leg.Draw()
latex = TLatex()
latex.SetNDC()
latex.SetTextSize(0.045)
latex.SetTextFont(42)
#latex.DrawLatex(0.66, leg.GetY1()-0.045, particleP+" #rightarrow "+particle+"h")
leg2 = TLegend(0.12, 0.225-2*0.25/5., 0.65, 0.225)
leg2.SetBorderSize(0)
leg2.SetFillStyle(0) #1001
leg2.SetFillColor(0)
c1.GetPad(0).RedrawAxis()
leg2.Draw()
if not options.blind: Obs0s.Draw("SAME, L")
c1.GetPad(0).Update()
if not gROOT.IsBatch(): raw_input("Press Enter to continue...")
if NO_BR:
c1.Print(MAIN_DIR+"combine/plotsLimit/ExclusionLimits/no_br_"+YEAR+suffix+".png")
c1.Print(MAIN_DIR+"combine/plotsLimit/ExclusionLimits/no_br_"+YEAR+suffix+".pdf")
else:
c1.Print(MAIN_DIR+"combine/plotsLimit/ExclusionLimits/"+YEAR+suffix+".png")
c1.Print(MAIN_DIR+"combine/plotsLimit/ExclusionLimits/"+YEAR+suffix+".pdf")
#if 'ah' in channel or 'sl' in channel:
# c1.Print("combine/plotsLimit/ExclusionLimits/"+YEAR+suffix+".C")
# c1.Print("combine/plotsLimit/ExclusionLimits/"+YEAR+suffix+".root")
for t in THEORY:
print "Model", t, ":",
for m in range(mass[0], mass[-1], 1):
if not (Theory[t].Eval(m) > Obs0s.Eval(m)) == (Theory[t].Eval(m+1) > Obs0s.Eval(m+1)): print m, "(obs)",
if not (Theory[t].Eval(m) > Exp0s.Eval(m)) == (Theory[t].Eval(m+1) > Exp0s.Eval(m+1)): print m, "(exp)",
print ""
#return ## ENDING HERE ALREADY ##################################################################################
# ---------- Significance ----------
c2 = TCanvas("c2", "Significance", 800, 600)
c2.cd()
c2.GetPad(0).SetTopMargin(0.06)
c2.GetPad(0).SetRightMargin(0.05)
c2.GetPad(0).SetTicks(1, 1)
c2.GetPad(0).SetGridx()
c2.GetPad(0).SetGridy()
Sign.GetYaxis().SetRangeUser(0., 5.)
Sign.GetXaxis().SetRangeUser(SIGNALS[0], SIGNALS[-1])
Sign.Draw("AL3")
drawCMS(LUMI, "Preliminary")
#drawCMS(LUMI, "Work in Progress", suppressCMS=True)
drawAnalysis(channel[1:3])
c2.Print(MAIN_DIR+"combine/plotsLimit/Significance/"+YEAR+suffix+".png")
c2.Print(MAIN_DIR+"combine/plotsLimit/Significance/"+YEAR+suffix+".pdf")
# c2.Print("plotsLimit/Significance/"+YEAR+suffix+".root")
# c2.Print("plotsLimit/Significance/"+YEAR+suffix+".C")
return ## now ending here
# ---------- p-Value ----------
c3 = TCanvas("c3", "p-Value", 800, 600)
c3.cd()
c3.GetPad(0).SetTopMargin(0.06)
c3.GetPad(0).SetRightMargin(0.05)
c3.GetPad(0).SetTicks(1, 1)
c3.GetPad(0).SetGridx()
c3.GetPad(0).SetGridy()
c3.GetPad(0).SetLogy()
pVal.Draw("AL3")
pVal.GetYaxis().SetRangeUser(2.e-7, 0.5)
ci = [1., 0.317310508, 0.045500264, 0.002699796, 0.00006334, 0.000000573303, 0.000000001973]
line = TLine()
line.SetLineColor(922)
line.SetLineStyle(7)
text = TLatex()
text.SetTextColor(922)
text.SetTextSize(0.025)
text.SetTextAlign(12)
for i in range(1, len(ci)-1):
line.DrawLine(pVal.GetXaxis().GetXmin(), ci[i]/2, pVal.GetXaxis().GetXmax(), ci[i]/2);
text.DrawLatex(pVal.GetXaxis().GetXmax()*1.01, ci[i]/2, "%d #sigma" % i);
drawCMS(LUMI, "Preliminary")
#drawCMS(LUMI, "Work in Progress", suppressCMS=True)
drawAnalysis(channel[1:3])
c3.Print("combine/plotsLimit/pValue/"+YEAR+suffix+".png")
c3.Print("combine/plotsLimit/pValue/"+YEAR+suffix+".pdf")
# c3.Print("plotsLimit/pValue/"+YEAR+suffix+".root")
# c3.Print("plotsLimit/pValue/"+YEAR+suffix+".C")
# --------- Best Fit ----------
c4 = TCanvas("c4", "Best Fit", 800, 600)
c4.cd()
c4.GetPad(0).SetTopMargin(0.06)
c4.GetPad(0).SetRightMargin(0.05)
c4.GetPad(0).SetTicks(1, 1)
c4.GetPad(0).SetGridx()
c4.GetPad(0).SetGridy()
Best.Draw("AL3")
drawCMS(LUMI, "Preliminary")
#drawCMS(LUMI, "Work in Progress", suppressCMS=True)
drawAnalysis(channel[1:3])
c4.Print("combine/plotsLimit/BestFit/"+YEAR+suffix+".png")
c4.Print("combine/plotsLimit/BestFit/"+YEAR+suffix+".pdf")
# c4.Print("plotsLimit/BestFit/"+YEAR+suffix+".root")
# c4.Print("plotsLimit/BestFit/"+YEAR+suffix+".C")
if not gROOT.IsBatch(): raw_input("Press Enter to continue...")
if 'ah' in channel:
outFile = TFile("bands.root", "RECREATE")
outFile.cd()
pVal.Write("graph")
Best.Write("best")
outFile.Close()
def limit2HDM():
global signals
signals = range(800, 2000+1, 50)
multF = HTOBB
THEORY = ['T1', 'T2']
mass, val = fillValues("./combine/AZh/AZh_M%d.txt")
Obs0s = TGraph()
Exp0s = TGraph()
Exp1s = TGraphAsymmErrors()
Exp2s = TGraphAsymmErrors()
massB, valB = fillValues("./combine/BBAZh/BBAZh_M%d.txt")
Obs0sB = TGraph()
Exp0sB = TGraph()
Exp1sB = TGraphAsymmErrors()
Exp2sB = TGraphAsymmErrors()
for i, m in enumerate(mass):
if not m in val:
print "Key Error:", m, "not in value map"
continue
n = Exp0s.GetN()
Obs0s.SetPoint(n, m, val[m][0]*multF)
Exp0s.SetPoint(n, m, val[m][3]*multF)
Exp1s.SetPoint(n, m, val[m][3]*multF)
Exp1s.SetPointError(n, 0., 0., val[m][3]*multF-val[m][2]*multF, val[m][4]*multF-val[m][3]*multF)
Exp2s.SetPoint(n, m, val[m][3]*multF)
Exp2s.SetPointError(n, 0., 0., val[m][3]*multF-val[m][1]*multF, val[m][5]*multF-val[m][3]*multF)
Obs0sB.SetPoint(n, m, valB[m][0]*multF)
Exp0sB.SetPoint(n, m, valB[m][3]*multF)
Exp1sB.SetPoint(n, m, valB[m][3]*multF)
Exp1sB.SetPointError(n, 0., 0., valB[m][3]*multF-valB[m][2]*multF, valB[m][4]*multF-valB[m][3]*multF)
Exp2sB.SetPoint(n, m, valB[m][3]*multF)
Exp2sB.SetPointError(n, 0., 0., valB[m][3]*multF-valB[m][1]*multF, valB[m][5]*multF-valB[m][3]*multF)
col = 629
Exp2s.SetLineWidth(2)
Exp2s.SetLineStyle(1)
Obs0s.SetLineWidth(3)
Obs0s.SetMarkerStyle(0)
Obs0s.SetLineColor(1)
Exp0s.SetLineStyle(2)
Exp0s.SetLineWidth(3)
Exp0s.SetLineColor(1)
# Exp1s.SetFillColorAlpha(col, 0.4) #kGreen+1
# Exp1s.SetLineColorAlpha(col, 0.4)
# Exp2s.SetFillColorAlpha(col, 0.2) #kOrange
# Exp2s.SetLineColorAlpha(col, 0.2)
Exp1s.SetFillColor(417)
Exp1s.SetLineColor(417)
Exp2s.SetFillColor(800)
Exp2s.SetLineColor(800)
colB = 922
Exp2sB.SetLineWidth(2)
Obs0sB.SetLineStyle(9)
Obs0sB.SetLineWidth(3)
Obs0sB.SetMarkerStyle(0)
Obs0sB.SetLineColor(colB)
Exp0sB.SetLineStyle(8)
Exp0sB.SetLineWidth(3)
Exp0sB.SetLineColor(colB)
Exp1sB.SetFillColorAlpha(colB, 0.4) #kGreen+1
Exp1sB.SetLineColorAlpha(colB, 0.4)
Exp2sB.SetFillColorAlpha(colB, 0.2) #kOrange
Exp2sB.SetLineColorAlpha(colB, 0.2)
Exp2s.GetXaxis().SetTitle("m_{A} (GeV)")
Exp2s.GetXaxis().SetTitleSize(Exp2s.GetXaxis().GetTitleSize()*1.25)
Exp2s.GetXaxis().SetNoExponent(True)
Exp2s.GetXaxis().SetMoreLogLabels(True)
Exp2s.GetYaxis().SetTitle("#sigma(A) #bf{#it{#Beta}}(A #rightarrow Zh) #bf{#it{#Beta}}(h #rightarrow bb) (fb)")
Exp2s.GetYaxis().SetTitleOffset(1.5)
Exp2s.GetYaxis().SetNoExponent(True)
Exp2s.GetYaxis().SetMoreLogLabels()
Theory = {}
#for t in THEORY:
# Theory[t] = TGraphAsymmErrors()
# for m in sorted(THDM[t]['ggA'].keys()):
# if m < mass[0] or m > mass[-1]: continue
# Xs, Xs_Up, Xs_Down = 0., 0., 0.
# Xs = THDM[t]['ggA'][m]
# Xs_Up = Xs*(1.+math.sqrt((THDM['PDF']['ggA'][m][0]-1.)**2 + (THDM['QCD']['ggA'][m][0]-1.)**2))
# Xs_Down = Xs*(1.-math.sqrt((1.-THDM['PDF']['ggA'][m][1])**2 + (1.-THDM['QCD']['ggA'][m][1])**2))
# n = Theory[t].GetN()
# Theory[t].SetPoint(n, m, Xs)
# Theory[t].SetPointError(n, 0., 0., (Xs-Xs_Down), (Xs_Up-Xs))
# Theory[t].SetLineColor(theoryLineColor[t])
# Theory[t].SetFillColor(theoryFillColor[t])
# Theory[t].SetFillStyle(theoryFillStyle[t])
# Theory[t].SetLineWidth(2)
# #Theory[t].SetLineStyle(7)
c1 = TCanvas("c1", "Exclusion Limits", 800, 600)
c1.cd()
#SetPad(c1.GetPad(0))
c1.GetPad(0).SetTopMargin(0.06)
c1.GetPad(0).SetRightMargin(0.05)
c1.GetPad(0).SetLeftMargin(0.12)
c1.GetPad(0).SetTicks(1, 1)
c1.GetPad(0).SetLogy()
Exp2s.Draw("A3")
Exp1s.Draw("SAME, 3")
Exp0s.Draw("SAME, L")
# Exp2sB.Draw("SAME, 3")
# Exp1sB.Draw("SAME, 3")
Exp0sB.Draw("SAME, L")
if not options.blind:
Obs0s.Draw("SAME, L")
Obs0sB.Draw("SAME, L")
for t in THEORY:
Theory[t].Draw("SAME, L3")
Theory[t].Draw("SAME, L3X0Y0")
#setHistStyle(Exp2s)
# Exp2s.GetXaxis().SetTitleSize(0.045)
# Exp2s.GetYaxis().SetTitleSize(0.04)
# Exp2s.GetXaxis().SetLabelSize(0.04)
# Exp2s.GetYaxis().SetLabelSize(0.04)
# Exp2s.GetXaxis().SetTitleOffset(1)
# Exp2s.GetYaxis().SetTitleOffset(1.25)
Exp2s.GetXaxis().SetTitleSize(0.050)
Exp2s.GetYaxis().SetTitleSize(0.050)
Exp2s.GetXaxis().SetLabelSize(0.045)
Exp2s.GetYaxis().SetLabelSize(0.045)
Exp2s.GetXaxis().SetTitleOffset(0.90)
Exp2s.GetYaxis().SetTitleOffset(1.25)
Exp2s.GetYaxis().SetMoreLogLabels(True)
Exp2s.GetYaxis().SetNoExponent(True)
Exp2s.GetYaxis().SetRangeUser(0.5, 1.e3)
Exp2s.GetXaxis().SetRangeUser(mass[0], mass[-1])
drawAnalysis('AZh')
drawRegion('AZHsl', True)
drawCMS(LUMI, "") #Preliminary
#drawCMS(LUMI, "Work in Progress", suppressCMS=True)
# legend
leg = TLegend(0.6, 0.90, 0.99, 0.90)
leg.SetBorderSize(0)
leg.SetFillStyle(0) #1001
leg.SetFillColor(0)
leg.SetHeader("95% CL upper limits")
leg.AddEntry(None, "gg #rightarrow A #rightarrow Zh", "") #"95% CL upper limits"
leg.AddEntry(Obs0s, "Observed", "l")
leg.AddEntry(Exp0s, "Expected", "l")
leg.AddEntry(Exp1s, "#pm 1 std. deviation", "f")
leg.AddEntry(Exp2s, "#pm 2 std. deviation", "f")
leg.AddEntry(None, "", "")
leg.AddEntry(None, "bbA #rightarrow Zh", "")
leg.AddEntry(Obs0sB, "Observed", "l")
leg.AddEntry(Exp0sB, "Expected", "l")
leg.SetY1(leg.GetY2()-leg.GetNRows()*0.045)
leg.Draw()
# latex = TLatex()
# latex.SetNDC()
# latex.SetTextSize(0.040)
# latex.SetTextFont(42)
# latex.DrawLatex(0.65, leg.GetY1()-0.045, "cos(#beta-#alpha)=0.25, tan(#beta)=1")
# legB = TLegend(0.12, 0.4-4*0.3/5., 0.65, 0.4)
legB = TLegend(0.15, 0.27, 0.68, 0.27)
legB.SetBorderSize(0)
legB.SetFillStyle(0) #1001
legB.SetFillColor(0)
for t in THEORY: legB.AddEntry(Theory[t], theoryLabel[t], "fl")
legB.AddEntry(None, "cos(#beta-#alpha)=0.25, tan(#beta)=1", "")
legB.SetY1(legB.GetY2()-legB.GetNRows()*0.045)
legB.Draw()
c1.GetPad(0).RedrawAxis()
leg.Draw()
c1.Update()
if not gROOT.IsBatch(): raw_input("Press Enter to continue...")
c1.Print("plotsLimit/Exclusion/THDM.png")
c1.Print("plotsLimit/Exclusion/THDM.pdf")
def limitCompare(method):
signal, particle, particleP = "XVH", "V", "V'"
channels = ["ah", "wrhpbb", "wrhpb", "wrlpbb", "wrlpb", "zrhpbb", "zrhpb", "zrlpbb", "zrlpb"]
colors = [1, 610+4, 632, 800+7, 800, 416+1, 860+10, 600, 616, 921, 922]
masses, vals, graphs = {}, {}, {}
for j, c in enumerate(channels):
masses[c], vals[c] = fillValues("./combine/" + method + "/"+signal+c+"_M%d.txt")
graphs[c] = TGraph()
n = 0
#print vals[c]
for i, m in enumerate(masses[c]):
#if not signals[i] >= 1000: continue
graphs[c].SetPoint(n, m, vals[c][m][3])
n = n + 1
graphs[c].SetLineColor(colors[j])
graphs[c].SetLineWidth(3)
graphs[c].Draw("SAME, L")
c1 = TCanvas("c1", "Exclusion Limits", 800, 600)
c1.cd()
#SetPad(c1.GetPad(0))
c1.GetPad(0).SetTopMargin(0.06)
c1.GetPad(0).SetRightMargin(0.05)
c1.GetPad(0).SetTicks(1, 1)
c1.GetPad(0).SetLogy()
for c in channels:
graphs[c].Draw("AL" if 'ah' in c else "SAME, L")
graphs[channels[0]].GetXaxis().SetRangeUser(SIGNALS[0], SIGNALS[-1])
graphs[channels[0]].GetYaxis().SetRangeUser(0.25, 2.5e4)
graphs[channels[0]].GetXaxis().SetTitle("m_{"+particleP+"} (GeV)")
graphs[channels[0]].GetYaxis().SetTitle("#sigma("+particleP+") #bf{#it{#Beta}}("+particleP+" #rightarrow "+particle+"H) #bf{#it{#Beta}}(H #rightarrow bb) (fb)")
drawAnalysis(signal)
#drawRegion(signal, True)
drawCMS(LUMI, "Preliminary")
#drawCMS(LUMI, "Work in Progress", suppressCMS=True)
# legend
top = 0.9
leg = TLegend(0.4, top-len(channels)*0.2/5., 0.99, top)
leg.SetBorderSize(0)
leg.SetFillStyle(0) #1001
leg.SetFillColor(0)
leg.SetHeader("95% CL expected limits")
for c in channels:
leg.AddEntry(graphs[c], getChannel(c), "l")
leg.Draw()
c1.Update()
c1.Print("plotsLimit/Multi.png")
c1.Print("plotsLimit/Multi.pdf")
if __name__ == "__main__":
limit()