-
Notifications
You must be signed in to change notification settings - Fork 0
/
limit_plots_MonoHgg.py
executable file
·628 lines (511 loc) · 27.8 KB
/
limit_plots_MonoHgg.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
#!/bin/env python
from diphotons.Utils.pyrapp import *
from optparse import OptionParser, make_option
from copy import deepcopy as copy
import os, sys, glob, json
from auto_plotter import getObjects
def guessLabel(name):
if "EBEB" in name: return "EBEB"
elif "EBEE" in name: return "EBEE"
else: return "Combined"
def scaleGraph(graph,scale):
graph = graph.Clone()
graph.GetListOfFunctions().Clear()
## graph.Print()
xvals = graph.GetX()
yvals = graph.GetY()
yerrl = graph.GetEYlow()
yerrh = graph.GetEYhigh()
for ip in xrange(graph.GetN()):
scl = scale(xvals[ip])
## print scl
graph.SetPoint( ip, xvals[ip], yvals[ip]*scl )
try:
graph.SetPointEYlow( ip, yerrl[ip]*scl )
graph.SetPointEYhigh( ip, yerrh[ip]*scl )
except:
pass
def scaleGraphLivia(graph,scl):
graph = graph.Clone()
graph.GetListOfFunctions().Clear()
## graph.Print()
xvals = graph.GetX()
yvals = graph.GetY()
yerrl = graph.GetEYlow()
yerrh = graph.GetEYhigh()
for ip in xrange(graph.GetN()):
# scl = scale(xvals[ip])
print scl
graph.SetPoint( ip, xvals[ip], yvals[ip]*scl )
try:
graph.SetPointEYlow( ip, yerrl[ip]*scl )
graph.SetPointEYhigh( ip, yerrh[ip]*scl )
except:
pass
graph.Print()
return graph
def fitFunc(graph,func):
## func = func.Clone()
graph.Fit(func)
return func.Clone()
def addCmsLumi(canv,period,pos,extraText=None):
if extraText:
ROOT.writeExtraText = True
if type(extraText) == str and extraText != "":
ROOT.extraText = extraText
ROOT.CMS_lumi(canv,period,pos)
# -----------------------------------------------------------------------------------------------------------
class LimitPlot(PlotApp):
def __init__(self):
super(LimitPlot,self).__init__(option_list=[
make_option("--mA0",action="store", dest="mA0",
default=300),
make_option("--do-limits",action="store_true", dest="do_limits",
default=False),
make_option("--do-pvalues",action="store_true", dest="do_pvalues",
default=False),
make_option("--do-comparison",action="store_true", dest="do_comparison",
default=False),
make_option("--compare-expected",action="store_true", dest="compare_expected",
default=False),
make_option("--compare-file","--compare-files",dest="compare_files",action="callback",type="string", callback=optpars_utils.ScratchAppend(str),
default=[]),
make_option("--compare-label","--compare-labels",dest="compare_labels",action="callback",type="string", callback=optpars_utils.ScratchAppend(str),
default=[]),
make_option("--asimov-expected",action="store_true", dest="asimov_expected",
default=True),
make_option("--toys-expected",action="store_false", dest="asimov_expected",
),
make_option("-n","--label",action="store", dest="label",
default=""),
make_option("--suffix","--suffix",action="store", dest="suffix",
default=""),
make_option("-M","--method",action="store", dest="method",
default="Asymptotic"),
make_option("-U","--unblind",action="store_true", dest="unblind",
default=False),
make_option("-B","--blind",action="store_false", dest="unblind",
),
make_option("-k","--couplings",action="callback", dest="couplings", type="string", callback=optpars_utils.ScratchAppend(str),
default=[]),
make_option("-x","--x-sections",action="callback", dest="x_sections", type="string", callback=optpars_utils.Load(),
default={}),
make_option("--fixed-x-section",action="store", dest="fixed_x_section", type="float",
default=None),
make_option("--use-fb",dest="use_fb", action="store_true",
default=False),
])
global ROOT, style_utils, RooFit
import ROOT
from ROOT import RooFit
from ROOT import RooAbsData
import diphotons.Utils.pyrapp.style_utils as style_utils
def __call__(self,options,args):
self.loadRootStyle()
# ROOT.gSystem.AddIncludePath( "$ROOTSYS/include" )
ROOT.gROOT.LoadMacro( "$CMSSW_BASE/src/HiggsAnalysis/CombinedLimit/test/plotting/bandUtils.cxx+" )
self.loadXsections(options.x_sections)
if options.do_comparison:
if len(options.compare_labels) > 0: assert( len(options.compare_labels) == len(options.compare_files) )
else: options.compare_labels = map(guessLabel, options.compare_files)
self.compare = map(lambda x: (getObjects([self.open(x[0])]),x[1]), zip(options.compare_files,options.compare_labels) )
self.plotComparisons(options)
return
if options.compare_expected:
self.compareExpectedLivia(options) #orig
#self.compareExpectedLivia(options, False, False) #boost
return
print options.couplings
#if len(options.couplings) == 0:
# flist = glob.glob("%s/higgsCombine%s*.%s.root" % (options.input_dir, options.label, options.method) )
#else:
flist = [ "%s/higgsCombineMonoHgg%s_mA0%s.Combined.%s.2HDM.root" % (options.input_dir,options.suffix,options.mA0, options.method)]
# flist = [ "%s/higgsCombineMonoHgg_sig_ZpBaryonicCombined.%s.ZpBaryonic_mZP500.root" % (options.input_dir, options.method)]
print options.input_dir, flist
tflist = {}
for fname in flist:
bname = os.path.basename(fname)
# coup = bname.split("_",1)
# print coup
#coup = coup[1].split(".")
# print coup
# coup = coup[0].replace("k","")
# print coup
coup = "001"
tfin = self.open(fname)
if not tfin:
print ("unable to open %s" % fname)
sys.exit(-1)
tree = tfin.Get("limit")
if not tree:
print ("unable to find limit tree in %s" % fname)
sys.exit(-1)
tflist[coup] = tfin
self.graphs = []
for coup,tfile in tflist.iteritems():
if options.do_limits:
print coup, tfile
self.plotLimit(options,coup,tfile)
if options.do_pvalues:
self.plotPval(options,coup,tfile)
self.autosave()
if len(options.couplings) == 0:
graphs = self.open("%s/graphs_%s_mA0%s.root" % (options.input_dir,options.method, options.mA0),"recreate")
else:
graphs = self.open("%s/graphs_%s_%s_mA0%s.root" % (options.input_dir,"_".join(options.couplings),options.method, options.mA0),"recreate")
graphs.cd()
for gr in self.graphs: gr.Write()
graphs.Close()
def compareExpectedLivia(self,options):
#original selection
# tfile_1cat=self.open("ntuples4fit_vtx0_OptSel1_80X_METCAT_mZ_600_cic_default_shapes_lumi_20_1CAT/graphs_Asymptotic.root")
#tfile_2cat=self.open("ntuples4fit_vtx0_OptSel1_80X_METCAT_mZ_600_cic_default_shapes_lumi_20_2CAT/graphs_Asymptotic.root")
#gr_1cat=tfile_1cat.Get("expected_001")
#gr_2cat=tfile_2cat.Get("expected_001")
tfile_cc2015=self.open("../Approval-Nominal/HybridNewCL/2HDM_A0300_SinglePoint_m600Sel/graphs_HybridNew.root")
tfile_cc105=self.open("Datacards_ABCD_v80X_v5/cutncount_105/graphs_Asymptotic_mA0300.root")
tfile_cc130=self.open("Datacards_ABCD_v80X_v5/cutncount_130/graphs_Asymptotic_mA0300.root")
tfile_fit130=self.open("ntuples4fit_pho_met130_NEW_cic_default_shapes_lumi_34.7/graphs_Asymptotic_mA0300.root")
tfile_fit105=self.open("ntuples4fit_pho_met105_cic_default_shapes_lumi_34.7/graphs_Asymptotic_mA0300.root")
tfile_fit150=self.open("ntuples4fit_pho_met150_cic_default_shapes_lumi_34.7/graphs_Asymptotic_mA0300.root")
tfile_fit130LV=self.open("ntuples4fit_pho_met130_STD_cic_default_shapes_lumi_34.7/graphs_Asymptotic_mA0300.root")
tfile_fit130LV_PI=self.open("ntuples4fit_pho_met130_HYB_cic_default_shapes_lumi_34.7/graphs_Asymptotic_mA0300.root")
# tfile_cc=self.open("ntuples4fit_vtx0_OptSel1_80X_METCAT_mZ_600_cic_default_shapes_lumi_35/graphs_Asymptotic.root")
tfile_fit120=self.open("ntuples4fit_pho_met130_NEW_cic_default_shapes_lumi_34.7/graphs_Asymptotic_mA0300.root")
# tfile_fit130=self.open("ntuples4fit_pho_met130_cic_default_shapes_lumi_34.7/graphs_Asymptotic.root")
tfile_lowmet40=self.open("ntuples4fit_pho_met40_met130_cic_default_shapes_lumi_35.8/graphs_Asymptotic_mA0300.root")
tfile_lowmet30=self.open("ntuples4fit_pho_met30_met130_cic_default_shapes_lumi_35.8/graphs_Asymptotic_mA0300.root")
gr_cc2015=tfile_cc2015.Get("expected_001")
gr_cc105=tfile_cc105.Get("expected_001")
gr_cc130=tfile_cc130.Get("expected_001")
gr_fit105=tfile_fit105.Get("expected_001")
gr_fit120=tfile_fit120.Get("expected_001")
gr_fit130=tfile_fit130.Get("expected_001")
gr_fit150=tfile_fit150.Get("expected_001")
gr_fit130LV=tfile_fit130LV.Get("expected_001")
gr_fit130LV_PI=tfile_fit130LV_PI.Get("expected_001")
gr_fitlm40=tfile_lowmet40.Get("expected_001")
gr_fitlm30=tfile_lowmet30.Get("expected_001")
unit = "fb" if options.use_fb else "pb"
basicStyle = [["SetMarkerSize",0.6],["SetLineWidth",3],
["SetTitle",";M_{Z`} (GeV);95%% C.L. #sigma(pp#rightarrow Z`#rightarrowA_{0}H #rightarrow#chi#chi#gamma#gamma ) (%s)" % unit]]
expectedStyle = [["SetMarkerSize",0]]+basicStyle
# style_utils.apply( gr_1cat, [["colors",ROOT.kRed],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
#style_utils.apply( gr_2cat, [["colors",ROOT.kBlue],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_cc2015, [["colors",ROOT.kOrange],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_cc105, [["colors",ROOT.kAzure+10],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_cc130, [["colors",ROOT.kMagenta-9],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fit105, [["colors",ROOT.kBlue],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fit120, [["colors",ROOT.kViolet+5],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fit130, [["colors",ROOT.kViolet],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fit130LV, [["colors",ROOT.kOrange],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fit130LV_PI, [["colors",ROOT.kRed],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fit150, [["colors",ROOT.kMagenta+3],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fitlm40, [["colors",ROOT.kMagenta],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
style_utils.apply( gr_fitlm30, [["colors",ROOT.kAzure+10],["SetLineStyle",7],["SetName","gr_pho"]]+expectedStyle )
title=ROOT.TString()
title="Comparison_LowMetThresholds_MA300"
isNewSel=False
legend = ROOT.TLegend(0.39,0.7,0.89,0.9)
#legend.AddEntry(gr_1cat,"1 CAT","l")
#legend.AddEntry(gr_2cat,"2 CAT","l")
# legend.AddEntry(gr_cc2015,"CC MET> 105 GeV - 2015","l")
# legend.AddEntry(gr_fit105,"Fit MET > 105 GeV","l")
# legend.AddEntry(gr_cc105,"CC MET> 105 GeV -2016","l")
# legend.AddEntry(gr_fit120,"Fit MET > 120 GeV","l")
# legend.AddEntry(gr_fit130,"Loose Lepton Veto","l")
# legend.AddEntry(gr_fit130LV,"Standard Analysis","l")
# legend.AddEntry(gr_fit130LV_PI,"Hybrid Analysis","l")
legend.AddEntry(gr_fitlm30,"MET> 30 GeV","l")
legend.AddEntry(gr_fitlm40,"MET> 40 GeV","l")
# legend.AddEntry(gr_cc130,"CC MET > 130 GeV - 2016","l")
# legend.AddEntry(gr_fit150,"Fit MET > 150 GeV","l")
title+="limits_categories"
canv = ROOT.TCanvas(title,title)
# canv.SetLogx()
#gr_1cat.Draw("PLA")
#gr_2cat.Draw("PLA")
gr_fitlm30.GetYaxis().SetRangeUser(0.3,0.7)
# gr_fit130.Draw("PLA")
# gr_fit105.Draw("PLSAME")
# gr_cc2015.Draw("PLSAME")
# gr_cc105.Draw("PLSAME")
# gr_fit120.Draw("PLSAME")
# gr_fit150.Draw("PLSAME")
# gr_cc130.Draw("PLSAME")
gr_fitlm30.Draw("APL")
gr_fitlm40.Draw("PLSAME")
addCmsLumi(canv,4, 1, "Preliminary")
self.keep(legend,True)
#if not isH:
legend.Draw()
self.keep( [canv,gr_cc130] )
self.format(canv,options.postproc)
# self.format(canv, options)
def plotLimit(self,options,coup,tfile):
## TGraphAsymmErrors *theBand(TFile *file, int doSyst, int whichChannel, BandType type, double width=0.68) {
tfile_xsecTheo=self.open("Signal_crossSections.root")
tfile_gz08=self.open("gz08_fbU.root")
theo = tfile_xsecTheo.Get("xsec_2HDM")
gz08 = tfile_gz08.Get("xsec_2HDM")
if options.asimov_expected:
ROOT.use_precomputed_quantiles = True
bandType = ROOT.Median
else:
bandType = ROOT.Median
expected68Orig = ROOT.theBand( tfile, 1, 0, bandType, 0.68 )
expected95Orig = ROOT.theBand( tfile, 1, 0, bandType, 0.95 )
observedOrig = ROOT.theBand( tfile, 1, 0, ROOT.Observed, 0.95 )
print "-------------------------------------------------------",observedOrig.GetN()
# print expected68.GetN()
# print expected95.GetN()
observed=scaleGraphLivia(observedOrig,2)
expected68=scaleGraphLivia(expected68Orig,2)
expected95=scaleGraphLivia(expected95Orig,2)
unit = "fb" if options.use_fb else "pb"
basicStyle = [["SetMarkerSize",0.6],["SetLineWidth",3],
["SetTitle",";M_{Z`} (GeV);95%% C.L. #sigma(pp#rightarrow Z`#rightarrowA_{0}H #rightarrow#chi#chi#gamma#gamma ) (%s)" % unit]]
commonStyle = [[self.scaleByXsec,coup],"Sort"]+basicStyle
## expectedStyle = commonStyle+[["SetMarkerStyle",ROOT.kOpenCircle]]
expectedStyle = commonStyle+[["SetMarkerSize",0]]
observedStyle = commonStyle+[["SetMarkerStyle",ROOT.kFullCircle]]
theoStyle = [["SetMarkerSize",0]]+basicStyle
style_utils.apply( theo, [["colors",ROOT.kRed],["SetLineStyle",5],["SetName","theo"]]+theoStyle )
style_utils.apply( gz08, [["colors",ROOT.kBlue],["SetLineStyle",5],["SetName","theo"]]+theoStyle )
style_utils.apply( expected68, [["colors",ROOT.kYellow],["SetName","expected68_%s"%coup]]+expectedStyle )
style_utils.apply( expected95, [["colors",ROOT.kGreen],["SetName","expected95_%s"%coup]]+expectedStyle )
expected = ROOT.TGraph(expected68)
style_utils.apply( expected, [["colors",ROOT.kBlack],["SetLineStyle",7],["SetName","expected_%s"%coup]])
style_utils.apply(observed,[["SetName","observed_%s"%coup]]+observedStyle)
canvname=["limits_mA0%s" % (options.mA0)]
print canvname
canv = ROOT.TCanvas("limits_mA0%s" % (options.mA0), "limits_mA0%s" % (options.mA0))
canv.SetLogx()
canv.SetLogy()
canv.SetGridx()
canv.SetGridy()
legend = ROOT.TLegend(0.35,0.65,0.75,0.9)
expected95.Draw("APE3")
expected95.GetXaxis().SetRangeUser(600,2550)
expected95.GetYaxis().SetRangeUser(0.1,20)
expected95.GetXaxis().SetMoreLogLabels()
expected68.Draw("E3PL")
expected.Draw("PL")
# theo.Draw("PL")
if options.mA0==300:
gz08.Draw("PL")
#kappa = "0."+coup[1:]
#legend.AddEntry(None,"#tilde{#kappa} = %s" % kappa,"")
# legend.AddEntry(theo,"2HDM - g_{Z} constrained","l")
if options.mA0==300:
legend.AddEntry(gz08,"2HDM - g_{Z} = 0.8","l")
legend.AddEntry(expected,"Expected limit","l")
legend.AddEntry(expected68," \pm 1 \sigma","f")
legend.AddEntry(expected95," \pm 2 \sigma","f")
#if options.unblind:
#observed.Draw("PL")
observed.Draw("PL")
legend.AddEntry(observed,"Observed limit","l")
#if coup in self.xsections_:
# grav = self.xsections_[coup]
# style_utils.apply( grav, basicStyle+[["SetLineStyle",9],["colors",ROOT.myColorB2]] )
# grav.Draw("L")
# legend.AddEntry(grav,"Z`#rightarrowA_{0}H #rightarrow#chi#chi#gamma#gamma","l").SetLineStyle(0)
canv.RedrawAxis()
self.keep(legend,True)
legend.Draw()
self.graphs.extend([gz08,theo,observed,expected,expected68,expected95])
self.keep( [gz08,theo,canv,observed,expected,expected68,expected95] )
print "bbb"
self.format(canv,options.postproc)
def plotComparisons(self,options):
## if options.compare_expected:
#if options.compare_expected:
# observed = map(lambda x: (filter(lambda y: "expected" in y.GetName(), x[0]),x[1]), self.compare)
# coups = set(map(lambda x: x.GetName().replace("expected_",""), reduce(lambda x,y: x+y, map(lambda z: z[0], observed), [])))
# else:
observed = map(lambda x: (filter(lambda y: "observed" in y.GetName(), x[0]),x[1]), self.compare)
coups = set(map(lambda x: x.GetName().replace("observed_",""), reduce(lambda x,y: x+y, map(lambda z: z[0], observed), [])))
## observed = map(lambda x: (filter(lambda y: "expected" in y.GetName(), x[0]),x[1]), self.compare)
## coups = set(map(lambda x: x.GetName().replace("expected_",""), reduce(lambda x,y: x+y, map(lambda z: z[0], observed), [])))
coups = ["001"]
map(lambda x: self.plotComparison(options,x,observed), coups)
def plotComparison(self,options,coup,observed):
cobserved = map(lambda x: (filter(lambda y: y.GetName().ends, x[0])[0],x[1]), observed)
print cobserved
styles = [ [["colors",ROOT.kBlue]], [["colors",ROOT.kOrange]], [["colors",ROOT.kGreen+1]] ]
map(lambda x: style_utils.apply(x[0],[["SetMarkerSize",0.5],["SetLineWidth",1]]+styles.pop(0)), cobserved)
canv = ROOT.TCanvas("comparison_%s" % coup,"comparison_%s" % coup)
legend = ROOT.TLegend(0.55,0.51,0.85,0.76)
legend.SetFillStyle(0)
kappa = "0."+coup[1:]
legend.AddEntry(None,"#tilde{#kappa} = %s" % kappa,"")
g0 = cobserved[0][0]
g0.Draw("apl")
for gr,nam in cobserved:
legend.AddEntry(gr,nam,"l")
for gr,nam in reversed(cobserved):
gr.Draw("pl")
legend.Draw("same")
g0.GetXaxis().SetRangeUser(450,5000)
g0.GetXaxis().SetMoreLogLabels()
canv.SetLogx()
if options.do_pvalues:
canv.SetLogy()
g0.GetYaxis().SetRangeUser(1e-3,0.55)
self.drawLines(g0)
self.keep([canv,legend])
self.format(canv,options.postproc)
def drawLines(self,ref,xmin=450,xmax=5000):
spots = filter(lambda x: x>ref.GetYaxis().GetXmin(), map(lambda x: (x,ROOT.RooStats.SignificanceToPValue(x)), xrange(1,5) ) )
lines = map( lambda y: ROOT.TLine(xmin,y[1],xmax,y[1]), spots )
map( lambda x: style_utils.apply(x,[["SetLineColor",ROOT.kGray+3],["SetLineStyle",7]]), lines )
labels = map( lambda y: ROOT.TLatex(xmax*1.01,y[1]*0.9,"#color[%d]{%d #sigma}" % (ROOT.kGray+2,y[0])), spots )
map( lambda x: style_utils.apply(x,[["SetTextSize",0.05]]), labels )
map( lambda x: x.Draw("same"), lines+labels )
self.keep(lines+labels)
def plotPval(self,options,coup,tfile):
observed = ROOT.theBand( tfile, 1, 0, ROOT.Observed, 0.95 )
basicStyle = [["SetMarkerSize",0.6],["SetLineWidth",3],
["SetTitle",";M_{G} (GeV);p_{0}"]]
commonStyle = ["Sort"]+basicStyle
observedStyle = commonStyle+[["SetMarkerStyle",ROOT.kFullCircle],["colors",ROOT.kBlue]]
style_utils.apply(observed,[["SetName","observed_%s"%coup]]+observedStyle)
canv = ROOT.TCanvas("pvalues_k%s"%coup,"pvalues_k%s"%coup)
canv.SetLogy()
canv.SetLogx()
legend = ROOT.TLegend(0.5,0.6,0.8,0.75)
legend.SetFillStyle(0)
kappa = "0."+coup[1:]
observed.Draw("apl")
## observed.Draw("al")
## observed.GetYaxis().SetRangeUser(1e-5,0.55)
observed.GetYaxis().SetRangeUser(1e-3,0.55)
observed.GetXaxis().SetRangeUser(450,5000)
observed.GetXaxis().SetMoreLogLabels()
## xmin,xmax=observed.GetXaxis().GetXmin(),observed.GetXaxis().GetXmax()
xmin,xmax=450,5000
spots = filter(lambda x: x>observed.GetYaxis().GetXmin(), map(lambda x: (x,ROOT.RooStats.SignificanceToPValue(x)), xrange(1,5) ) )
lines = map( lambda y: ROOT.TLine(xmin,y[1],xmax,y[1]), spots )
map( lambda x: style_utils.apply(x,[["SetLineColor",ROOT.kGray+3],["SetLineStyle",7]]), lines )
labels = map( lambda y: ROOT.TLatex(xmax*1.01,y[1]*0.9,"#color[%d]{%d #sigma}" % (ROOT.kGray+2,y[0])), spots )
map( lambda x: style_utils.apply(x,[["SetTextSize",0.05]]), labels )
map( lambda x: x.Draw("same"), lines+labels )
self.keep(lines+labels)
legend.AddEntry(None,"#tilde{#kappa} = %s" % kappa,"")
legend.AddEntry(observed,"Observed p_{0}","l")
self.keep(legend,True)
legend.Draw()
self.graphs.extend([observed])
self.keep( [canv,observed] )
self.format(canv,options.postproc)
def scaleByXsec(self,graph,coup):
if self.options.fixed_x_section:
scale = self.options.fixed_x_section
if self.options.use_fb: scale *= 1e+3
xvals = graph.GetX()
yvals = graph.GetY()
yerrl = graph.GetEYlow()
yerrh = graph.GetEYhigh()
if not self.options.fixed_x_section:
if not coup in self.xsections_:
print("Cross section for k = %s not found" % coup)
xsec=1
#sys.exit(-1)
else:
xsec = self.xsections_[coup]
for ip in range(graph.GetN()):
if not self.options.fixed_x_section:
#scale = xsec.Eval(xvals[ip])
scale=1
graph.SetPoint( ip, xvals[ip], yvals[ip]*scale )
graph.SetPointEYlow( ip, yerrl[ip]*scale )
graph.SetPointEYhigh( ip, yerrh[ip]*scale )
def loadXsections(self,inmap):
self.xsections_ = {}
scl = 1e+3 if self.options.use_fb else 1.
for name,val in inmap.iteritems():
if name.startswith("RSGravToGG") or name.startswith("RSGravitonToGG"):
coup,mass = name.split("kMpl")[1].split("_Tune")[0].replace("_","").replace("-","").split("M")
mass = float(mass)
if not coup in self.xsections_:
self.xsections_[coup] = ROOT.TGraph()
self.xsections_[coup].SetPoint(self.xsections_[coup].GetN(),mass,val["xs"]*scl)
for name,val in self.xsections_.iteritems():
val.Sort()
def plotXsections(self):
coups = sorted( map( lambda x: (float("0."+x[0][1:]),x[1]), self.xsections_.iteritems() ), key=lambda x: x[0] )
## minc = min( map( lambda x: x[0], coups) )
refc = coups[-4]
print refc, coups
scaled = map( lambda x: (x[0],scaleGraph(x[1], lambda y: refc[0]*refc[0]/((x[0]*x[0])*refc[1].Eval(y)))), coups )
mypol = ROOT.TF1("mypol","[0]+[1]*(x-[2])**2")
fit = map( lambda x: (x[0],x[1],fitFunc(x[1],mypol)), scaled )
rescaled = map( lambda x: (x[0],scaleGraph(x[1], lambda y: 1./(x[2].Eval(y)) )), fit )
canv = ROOT.TCanvas("xsections","xsections")
scaled[0][1].Draw("apl")
# scaled[0].GetYaxis().SetRange(0,5)
for g in scaled[1:]: g[1].Draw("pl")
print scaled
self.keep( list(scaled) )
self.keep(canv)
recanv = ROOT.TCanvas("xsections_rescaled","xsections_rescaled")
rescaled[0][1].Draw("apl")
# scaled[0].GetYaxis().SetRange(0,5)
for g in rescaled[1:]: g[1].Draw("pl")
print rescaled
self.keep( list(rescaled) )
self.keep(recanv)
params = map( lambda x: (x[0], x[2].GetParameter(0), x[2].GetParameter(1), x[2].GetParameter(2)), fit )
param_graphs = ROOT.TGraph(), ROOT.TGraph(), ROOT.TGraph()
map( lambda x: (param_graphs[0].SetPoint(param_graphs[0].GetN(),x[0],x[1]),param_graphs[1].SetPoint(param_graphs[1].GetN(),x[0],x[2]),param_graphs[2].SetPoint(param_graphs[2].GetN(),x[0],x[3])), params )
for ip, gr in enumerate(param_graphs):
gr.Sort()
pcanv = ROOT.TCanvas("p%d"%ip,"p%d"%ip)
gr.Draw()
self.keep( [gr,pcanv] )
p0 = ROOT.TF1("p0","pol2")
p0.SetParameters(1.09141,-0.0977154,-0.670345)
p1 = ROOT.TF1("p1","pol2")
p1.SetParameters(-3.44266e-08,5.194e-08,2.02169e-07)
p2 = ROOT.TF1("p2","pol2")
p2.SetParameters(2718.59,69.1401,-772.539)
## refc[0] = 3
equalized = map( lambda x: (x[0],scaleGraph(x[1], lambda y: refc[0]*refc[0]/((x[0]*x[0])*(p0.Eval(x[0]) + p1.Eval(x[0])*(y-p2.Eval(x[0]))**2)) )), coups )
eqcanv = ROOT.TCanvas("xsections_equalized","xsections_equalized")
## equalized[0][1].Draw("apl")
## # scaled[0].GetYaxis().SetRange(0,5)
## for g in equalized[1:]: g[1].Draw("pl")
## self.keep( list(equalized) )
## self.keep(eqcanv)
sumg = {}
for gr in equalized:
gr = gr[1]
xvals = gr.GetX()
yvals = gr.GetY()
for ip in xrange(gr.GetN()):
x,y = xvals[ip],yvals[ip]
if not x in sumg: sumg[x] = [0.,0]
sumg[x][0] += y
sumg[x][1] += 1
averaged = ROOT.TGraph()
for x,y in sumg.iteritems():
averaged.SetPoint(averaged.GetN(),x,y[0]/y[1])
averaged.Sort()
averaged.Draw("apl")
self.keep(averaged)
self.keep(eqcanv)
xsec = {
"ref" : refc[0],
"p0" : [ p0.GetParameter(0), p0.GetParameter(1), p0.GetParameter(2) ],
"p1" : [ p1.GetParameter(0), p1.GetParameter(1), p1.GetParameter(2) ],
"p2" : [ p2.GetParameter(0), p2.GetParameter(1), p2.GetParameter(2) ],
"xsec" : [ (averaged.GetX()[i],averaged.GetY()[i]) for i in xrange(averaged.GetN()) ]
}
with open("xsecions.json","w+") as xsec_file:
xsec_file.write(json.dumps(xsec))
xsec_file.close()
# -----------------------------------------------------------------------------------------------------------
if __name__ == "__main__":
app = LimitPlot()
app.run()