pads=[pad1,pad2]
pads[1].cd()

bfit = plot.bestFit(tree, "r_ggH", "r_bbH", "")
#Note the binning of the TH2D for the interpolation should ~ match the initial input grid
#Could in future implement variable binning here
h2d = plot.treeToHist2D(tree, "r_ggH", "r_bbH", "h2d", "", ggH_list[0], ggH_list[-1], bbH_list[0], bbH_list[-1], ggH_bins-1, bbH_bins-1)
#h2d = plot.makeVarBinHist2D("h2d", ggH_list, bbH_list)
#plot.fillTH2(h2d, graph)
#h2d.SaveAs("heatmap.root")
for i in xrange(1):
    h2d = plot.rebin(h2d) # Additional smoothing of the curves
#h2d.SaveAs("heatmap2.root")
axis.Draw()

cont_1sigma = plot.contourFromTH2(h2d, 2.30, 20) #0.68
cont_2sigma = plot.contourFromTH2(h2d, 5.99, 20) #0.95

for i, p in enumerate(cont_2sigma):
    p.SetLineStyle(1)
    p.SetLineWidth(2)
    p.SetLineColor(ROOT.kBlack)
    p.SetFillColor(ROOT.kBlue-10)
    p.SetFillStyle(1001)
    pads[1].cd()
    p.Draw("F SAME")
    p.Draw("CONT SAME")

for i, p in enumerate(cont_1sigma):
    p.SetLineStyle(1)
    p.SetLineWidth(2)
Пример #2
0
    outfile.WriteTObject(bestfits[scan])

    #hists[scan] = plot.TH2FromTGraph2D(graphs[scan], method='BinCenterAligned')
    #plot.fillTH2(hists[scan], graphs[scan])

    hists[scan] = makeHist(scan+'_hist', 40 * args.multi, graphs[scan])
    fillTH2(hists[scan], graphs[scan])

    outfile.WriteTObject(hists[scan], hists[scan].GetName() + '_input')
    fixZeros(hists[scan])
    outfile.WriteTObject(hists[scan], hists[scan].GetName() + '_processed')
    #conts68[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(1-0.683, 2))
    #conts95[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(1-0.9545, 2))
    #conts68[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(
    #    1 - 0.683, 2), frameValue=10)
    conts95[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(1-0.9545, 2))
    conts68[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(
        1 - 0.683, 2), frameValue=10)

    if scan in ['cms']:
        conts95[scan] = plot.contourFromTH2(
            hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.9545, 2))
    for i, c in enumerate(conts68[scan]):
        c.SetName('graph68_%s_%i' % (scan, i))
        if args.thin > 1:
            newgr = ROOT.TGraph(c.GetN() / args.thin)
            needLast = True
            for a, p in enumerate(range(0, c.GetN(), args.thin)):
                if p == c.GetN() - 1:
                    needLast = False
                newgr.SetPoint(a, c.GetX()[p], c.GetY()[p])
    plot.RemoveGraphXDuplicates(best_sm)
hists.SetMaximum(6)
hists.SetMinimum(0)
hists.SetContour(255)
# c2=ROOT.TCanvas()
# hists.Draw("COLZ")
# c2.SaveAs("heatmap.png")

axis = ROOT.TH2D(hists.GetName(),hists.GetName(),hists.GetXaxis().GetNbins(),0,hists.GetXaxis().GetXmax(),hists.GetYaxis().GetNbins(),0,hists.GetYaxis().GetXmax())
axis.Reset()
axis.GetXaxis().SetTitle(args.x_title)
axis.GetXaxis().SetLabelSize(0.025)
axis.GetYaxis().SetLabelSize(0.025)
axis.GetYaxis().SetTitle(args.y_title)

cont_1sigma = plot.contourFromTH2(hists, ROOT.Math.chisquared_quantile_c(1 - 0.68, 2), 10, frameValue=20)
cont_2sigma = plot.contourFromTH2(hists, ROOT.Math.chisquared_quantile_c(1 - 0.95, 2), 10, frameValue=20)

if debug is not None:
    debug.WriteTObject(hists, 'hist')
    for i, cont in enumerate(cont_1sigma):
        debug.WriteTObject(cont, 'cont_1sigma_%i' % i)
    for i, cont in enumerate(cont_2sigma):
        debug.WriteTObject(cont, 'cont_2sigma_%i' % i)

if args.sm_exp or args.bg_exp:
    legend = plot.PositionedLegend(0.5, 0.25, 3, 0.015)
else:
    legend = plot.PositionedLegend(0.3, 0.2, 3, 0.015)

pads[0].cd()
Пример #4
0
for scan in order:
    if scan not in infiles:
        continue
    graphs[scan], bestfits[scan] = read(scan, SETTINGS[scan]["xvar"], SETTINGS[scan]["yvar"], infiles[scan])
    outfile.WriteTObject(graphs[scan], scan + "_graph")
    outfile.WriteTObject(bestfits[scan])
    # hists[scan] = makeHist(
    #     scan + '_hist', 40 * SETTINGS[scan]['multi'] * args.multi, graph_test)
    hists[scan] = plot.TH2FromTGraph2D(graphs[scan], method="BinCenterAligned")
    plot.fillTH2(hists[scan], graphs[scan])
    # fillTH2(hists[scan], graphs[scan])
    outfile.WriteTObject(hists[scan], hists[scan].GetName() + "_input")
    fixZeros(hists[scan])
    outfile.WriteTObject(hists[scan], hists[scan].GetName() + "_processed")
    conts68[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.68, 2), frameValue=10)
    if scan in ["cms", "atlas", "comb"]:
        conts95[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.95, 2))
    for i, c in enumerate(conts68[scan]):
        c.SetName("graph68_%s_%i" % (scan, i))
        if args.thin > 1:
            newgr = ROOT.TGraph(c.GetN() / args.thin)
            needLast = True
            for a, p in enumerate(range(0, c.GetN(), args.thin)):
                if p == c.GetN() - 1:
                    needLast = False
                newgr.SetPoint(a, c.GetX()[p], c.GetY()[p])
            if needLast:
                newgr.SetPoint(newgr.GetN(), c.GetX()[c.GetN() - 1], c.GetY()[c.GetN() - 1])
            conts68[scan][i] = newgr
            c = conts68[scan][i]
Пример #5
0
# c2=ROOT.TCanvas()
# hists.Draw("COLZ")
# c2.SaveAs("heatmap.png")

#axis = ROOT.TH2D(hists[0].GetName(),hists[0].GetName(),hists[0].GetXaxis().GetNbins(),0,hists[0].GetXaxis().GetXmax(),hists[0].GetYaxis().GetNbins(),0,hists[0].GetYaxis().GetXmax())
axis = ROOT.TH2D(hists.GetName(), hists.GetName(),
                 hists.GetXaxis().GetNbins(), 0, 2,
                 hists.GetYaxis().GetNbins(), 0, 2)
axis.Reset()
axis.GetXaxis().SetTitle(args.x_title)
axis.GetXaxis().SetLabelSize(0.025)
axis.GetYaxis().SetLabelSize(0.025)
axis.GetYaxis().SetTitle(args.y_title)

cont_1sigma = plot.contourFromTH2(hists,
                                  ROOT.Math.chisquared_quantile_c(1 - 0.68, 2),
                                  10,
                                  frameValue=20)
cont_2sigma = plot.contourFromTH2(hists,
                                  ROOT.Math.chisquared_quantile_c(1 - 0.95, 2),
                                  10,
                                  frameValue=20)
print cont_1sigma
for item in cont_1sigma:
    print item
print cont_2sigma
for item in cont_2sigma:
    print item

old1 = ROOT.TFile('hig-16-043_1sigma.root', 'r')
cont_1sigma2 = old1.Get('Graph')
old2 = ROOT.TFile('hig-16-043_2sigma.root', 'r')
Пример #6
0
        extra_contours.append(extra_contours_per_index)
else:
    extra_contours = None

# Create the debug output file if requested
if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

# Fill TH2s by interpolating the TGraph2Ds, then extract contours
for c in types:
    print 'Filling histo for %s' % c
    hists[c] = h_proto.Clone(c)
    plot.fillTH2(hists[c], graphs[c])
    contours[c] = plot.contourFromTH2(hists[c], CL, 5, frameValue=1)
    if debug is not None:
        debug.WriteTObject(hists[c], 'hist_%s' % c)
        for i, cont in enumerate(contours[c]):
            debug.WriteTObject(cont, 'cont_%s_%i' % (c, i))

#Extract mh contours if mh histogram exists:
if h_mh is not None:
  h_mh_inverted = h_mh.Clone("mhInverted")
  for i in range(1,h_mh.GetNbinsX()+1):
     for j in range(1, h_mh.GetNbinsY()+1):
         h_mh_inverted.SetBinContent(i,j,1-(1./h_mh.GetBinContent(i,j)))
  mh122_contours = plot.contourFromTH2(h_mh_inverted, (1-1./122), 5, frameValue=1)
  mh128_contours = plot.contourFromTH2(h_mh, 128, 5, frameValue=1)
else : 
  mh122_contours = None
Пример #7
0
 graphs[scan], bestfits[scan] = read(scan, args.x_axis, args.y_axis, infile)
 outfile.WriteTObject(graphs[scan], scan + '_graph')
 outfile.WriteTObject(bestfits[scan])
 hists[scan] = axis.Clone(scan + '_hist')
 plot.fillTH2(hists[scan], graphs[scan])
 outfile.WriteTObject(hists[scan], hists[scan].GetName() + '_input')
 fixZeros(hists[scan])
 hists[scan].GetZaxis().SetTitle('-2 #Delta ln #Lambda(%s,%s)' %
                                 (x_axis, y_axis))
 # hists[scan].GetZaxis().SetTitleOffset(0)
 hists[scan].SetContour(255)
 hists[scan].Draw('COLZSAME')
 hists[scan].SetMinimum(0)
 hists[scan].SetMaximum(20)
 outfile.WriteTObject(hists[scan], hists[scan].GetName() + '_processed')
 conts68[scan] = plot.contourFromTH2(
     hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.68, 2))
 conts95[scan] = plot.contourFromTH2(
     hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.95, 2))
 for i, c in enumerate(conts68[scan]):
     if args.thin > 1:
         newgr = ROOT.TGraph(c.GetN() / args.thin)
         needLast = True
         for a, p in enumerate(range(0, c.GetN(), args.thin)):
             if p == c.GetN() - 1: needLast = False
             newgr.SetPoint(a, c.GetX()[p], c.GetY()[p])
         if needLast:
             newgr.SetPoint(newgr.GetN(),
                            c.GetX()[c.GetN() - 1],
                            c.GetY()[c.GetN() - 1])
         conts68[scan][i] = newgr
         c = conts68[scan][i]
Пример #8
0
axis.Reset()

# axis = None
axis.GetXaxis().SetTitle('m_{A} (GeV)')
axis.GetYaxis().SetTitle('tan#beta')

canv = ROOT.TCanvas('asymptotic_grid', 'asymptotic_grid')
pads = plot.OnePad()
pads[0].SetGridx(False)
pads[0].SetGridy(False)
pads[0].Draw()
axis.Draw()

hist.Draw('COLSAME')

conts = plot.contourFromTH2(hist, 0.05, mult=4)
for i, c in enumerate(conts):
    c.SetFillColor(ROOT.kBlue)
    c.SetLineColor(ROOT.kBlack)
    c.SetLineWidth(3)
    pads[0].cd()
    # c.Draw('F SAME')
    c.Draw('L SAME')
    # c.Draw('P SAME')

# plot.DrawCMSLogo(pads[0], '#it{ATLAS}#bf{ and }CMS', '#it{LHC Run 1}', 11, 0.025, 0.035, 1.1, extraText2='#it{Preliminary}')
# plot.DrawCMSLogo(pads[0], '#it{ATLAS}#bf{+}CMS', '#it{LHC Run 1}', 11, 0.02, 0.035, 1.1, extraText2='#it{Internal}')
# pads[0].RedrawAxis()
canv.Print('.pdf')
canv.Print('.png')
axis.Reset()

# axis = None
axis.GetXaxis().SetTitle('m_{A} (GeV)')
axis.GetYaxis().SetTitle('tan#beta')

canv = ROOT.TCanvas('asymptotic_grid', 'asymptotic_grid')
pads = plot.OnePad()
pads[0].SetGridx(False)
pads[0].SetGridy(False)
pads[0].Draw()
axis.Draw()

hist.Draw('COLSAME')

conts = plot.contourFromTH2(hist, 0.05, mult = 4)
for i, c in enumerate(conts):
    c.SetFillColor(ROOT.kBlue)
    c.SetLineColor(ROOT.kBlack)
    c.SetLineWidth(3)
    pads[0].cd()
    # c.Draw('F SAME')
    c.Draw('L SAME')
    # c.Draw('P SAME')

# plot.DrawCMSLogo(pads[0], '#it{ATLAS}#bf{ and }CMS', '#it{LHC Run 1}', 11, 0.025, 0.035, 1.1, extraText2='#it{Preliminary}')
# plot.DrawCMSLogo(pads[0], '#it{ATLAS}#bf{+}CMS', '#it{LHC Run 1}', 11, 0.02, 0.035, 1.1, extraText2='#it{Internal}')
# pads[0].RedrawAxis()
canv.Print('.pdf')
canv.Print('.png')
Пример #10
0
contours95 = {}

h_proto = plot.TH2FromTGraph2D(graphs[types[0]], method=args.bin_method,
                               force_x_width=args.force_x_width,
                               force_y_width=args.force_y_width)
h_axis = h_proto
h_axis = plot.TH2FromTGraph2D(graphs[types[0]])



# Fill TH2s by interpolating the TGraph2Ds, then extract contours
for c in types:
    print 'Filling histo for %s' % c
    hists[c] = h_proto.Clone(c)
    plot.fillInvertedTH2(hists[c], graphs[c])
    contours68[c] = plot.contourFromTH2(hists[c], cl68, 5, frameValue=1)
    contours95[c] = plot.contourFromTH2(hists[c], cl95, 5, frameValue=1)


# Setup the canvas: we'll use a two pad split, with a small top pad to contain
# the CMS logo and the legend
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()
pads[0].cd()
h_axis.GetXaxis().SetTitle(args.x_title)
h_axis.GetYaxis().SetTitle(args.y_title)
h_axis.GetXaxis().SetLabelSize(0.025)
h_axis.GetYaxis().SetLabelSize(0.025)
if args.x_range is not None:
    h_axis.GetXaxis().SetRangeUser(float(args.x_range.split(',')[0]),float(args.x_range.split(',')[1]))
if args.y_range is not None:
Пример #11
0
contours68 = {}
contours95 = {}

h_proto = plot.TH2FromTGraph2D(graphs[types[0]],
                               method=args.bin_method,
                               force_x_width=args.force_x_width,
                               force_y_width=args.force_y_width)
h_axis = h_proto
h_axis = plot.TH2FromTGraph2D(graphs[types[0]])

# Fill TH2s by interpolating the TGraph2Ds, then extract contours
for c in types:
    print 'Filling histo for %s' % c
    hists[c] = h_proto.Clone(c)
    plot.fillInvertedTH2(hists[c], graphs[c])
    contours68[c] = plot.contourFromTH2(hists[c], cl68, 5, frameValue=1)
    contours95[c] = plot.contourFromTH2(hists[c], cl95, 5, frameValue=1)

# Setup the canvas: we'll use a two pad split, with a small top pad to contain
# the CMS logo and the legend
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()
pads[0].cd()
h_axis.GetXaxis().SetTitle(args.x_title)
h_axis.GetYaxis().SetTitle(args.y_title)
h_axis.GetXaxis().SetLabelSize(0.025)
h_axis.GetYaxis().SetLabelSize(0.025)
if args.x_range is not None:
    h_axis.GetXaxis().SetRangeUser(float(args.x_range.split(',')[0]),
                                   float(args.x_range.split(',')[1]))
if args.y_range is not None:
Пример #12
0
    graphs[types[0]], method=args.bin_method, force_x_width=args.force_x_width, force_y_width=args.force_y_width
)
h_axis = h_proto
h_axis = plot.TH2FromTGraph2D(graphs[types[0]])
# Create the debug output file if requested
if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, "RECREATE")
else:
    debug = None

# Fill TH2s by interpolating the TGraph2Ds, then extract contours
for c in types:
    print "Filling histo for %s" % c
    hists[c] = h_proto.Clone(c)
    plot.fillTH2(hists[c], graphs[c])
    contours[c] = plot.contourFromTH2(hists[c], CL, 5, frameValue=1)
    if debug is not None:
        debug.WriteTObject(hists[c], "hist_%s" % c)
        for i, cont in enumerate(contours[c]):
            debug.WriteTObject(cont, "cont_%s_%i" % (c, i))

# Setup the canvas: we'll use a two pad split, with a small top pad to contain
# the CMS logo and the legend
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.TwoPadSplit(0.8, 0, 0)
pads[1].cd()
h_axis.GetXaxis().SetTitle(args.x_title)
h_axis.GetYaxis().SetTitle(args.y_title)
h_axis.Draw()

if args.hist is not None:
Пример #13
0
        extra_contours.append(extra_contours_per_index)
else:
    extra_contours = None

# Create the debug output file if requested
if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

# Fill TH2s by interpolating the TGraph2Ds, then extract contours
for c in types:
    print 'Filling histo for %s' % c
    hists[c] = h_proto.Clone(c)
    plot.fillTH2(hists[c], graphs[c])
    contours[c] = plot.contourFromTH2(hists[c], CL, 5, frameValue=1)
    if debug is not None:
        debug.WriteTObject(hists[c], 'hist_%s' % c)
        for i, cont in enumerate(contours[c]):
            debug.WriteTObject(cont, 'cont_%s_%i' % (c, i))

#Extract mh contours if mh histogram exists:
if h_mh is not None:
    h_mh_inverted = h_mh.Clone("mhInverted")
    for i in range(1, h_mh.GetNbinsX() + 1):
        for j in range(1, h_mh.GetNbinsY() + 1):
            if h_mh.GetBinContent(i, j) > 0:
                h_mh_inverted.SetBinContent(
                    i, j, 1 - (1. / h_mh.GetBinContent(i, j)))
            else:
                h_mh_inverted.SetBinContent(i, j, 0.)
Пример #14
0
bfit = plot.bestFit(tree, "r_ggH", "r_bbH", "")
#Note the binning of the TH2D for the interpolation should ~ match the initial input grid
#Could in future implement variable binning here
h2d = plot.treeToHist2D(tree, "r_ggH", "r_bbH", "h2d", "", ggH_list[0],
                        ggH_list[-1], bbH_list[0], bbH_list[-1], ggH_bins - 1,
                        bbH_bins - 1)
#h2d = plot.makeVarBinHist2D("h2d", ggH_list, bbH_list)
#plot.fillTH2(h2d, graph)
#h2d.SaveAs("heatmap.root")
for i in xrange(1):
    h2d = plot.rebin(h2d)  # Additional smoothing of the curves
#h2d.SaveAs("heatmap2.root")
axis.Draw()

cont_1sigma = plot.contourFromTH2(h2d, 2.30, 20)  #0.68
cont_2sigma = plot.contourFromTH2(h2d, 5.99, 20)  #0.95

for i, p in enumerate(cont_2sigma):
    p.SetLineStyle(1)
    p.SetLineWidth(2)
    p.SetLineColor(ROOT.kBlack)
    p.SetFillColor(ROOT.kBlue - 10)
    p.SetFillStyle(1001)
    pads[1].cd()
    p.Draw("F SAME")
    p.Draw("CONT SAME")

for i, p in enumerate(cont_1sigma):
    p.SetLineStyle(1)
    p.SetLineWidth(2)
Пример #15
0
outfile = ROOT.TFile(args.output + ".root", "RECREATE")

for scan in order:
    if scan not in infiles:
        continue
    graphs[scan], bestfits[scan] = read(scan, SETTINGS[scan]["xvar"], SETTINGS[scan]["yvar"], infiles[scan])
    outfile.WriteTObject(graphs[scan], scan + "_graph")
    outfile.WriteTObject(bestfits[scan])
    hists[scan] = makeHist(scan + "_hist", 40 * SETTINGS[scan]["multi"] * args.multi, graph_test)
    fillTH2(hists[scan], graphs[scan])
    outfile.WriteTObject(hists[scan], hists[scan].GetName() + "_input")
    fixZeros(hists[scan])
    outfile.WriteTObject(hists[scan], hists[scan].GetName() + "_processed")
    conts68[scan] = plot.contourFromTH2(
        hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.68, 2), mult=SETTINGS[scan]["multi"] * 4
    )
    if scan in ["cms", "atlas", "comb"]:
        conts95[scan] = plot.contourFromTH2(hists[scan], ROOT.Math.chisquared_quantile_c(1 - 0.95, 2))
    for i, c in enumerate(conts68[scan]):
        if args.thin > 1:
            newgr = ROOT.TGraph(c.GetN() / args.thin)
            needLast = True
            for a, p in enumerate(range(0, c.GetN(), args.thin)):
                if p == c.GetN() - 1:
                    needLast = False
                newgr.SetPoint(a, c.GetX()[p], c.GetY()[p])
            if needLast:
                newgr.SetPoint(newgr.GetN(), c.GetX()[c.GetN() - 1], c.GetY()[c.GetN() - 1])
            conts68[scan][i] = newgr
            c = conts68[scan][i]
Пример #16
0
h_plus2sigma = plot.makeHist2D("h_plus2sigma", mA_bins, tanb_bins,
                               graph_plus2sigma)
plot.fillTH2(h_exp, graph_exp)
plot.fillTH2(h_obs, graph_obs)
plot.fillTH2(h_minus1sigma, graph_minus1sigma)
plot.fillTH2(h_plus1sigma, graph_plus1sigma)
plot.fillTH2(h_minus2sigma, graph_minus2sigma)
plot.fillTH2(h_plus2sigma, graph_plus2sigma)
axis.Draw()
#Possibility to draw CLs heat map, would be a useful option, using e.g.
#h_exp.Draw("colzsame")

#Extract exclusion contours from the TH2Ds, use threshold 1.0 for limit and 0.05 for CLs
threshold = 0.05
#threshold=1
cont_exp = plot.contourFromTH2(h_exp, threshold, 20)
cont_obs = plot.contourFromTH2(h_obs, threshold, 5)
cont_minus1sigma = plot.contourFromTH2(h_minus1sigma, threshold, 20)
cont_plus1sigma = plot.contourFromTH2(h_plus1sigma, threshold, 20)
cont_minus2sigma = plot.contourFromTH2(h_minus2sigma, threshold, 20)
cont_plus2sigma = plot.contourFromTH2(h_plus2sigma, threshold, 20)

#if args.scenario != "hMSSM" and "2HDM" not in args.scenario :
#    graph_higgshBand = plot.higgsConstraint(args.scenario, "h")
#    plane_higgshBand = plot.makeHist2D('plane_higgshBand', 36, 91, graph_higgshBand)
#    plot.fillTH2(plane_higgshBand, graph_higgshBand)
#    cont_higgshlow = plot.contourFromTH2(plane_higgshBand, 122, 5)
#    cont_higgshhigh = plot.contourFromTH2(plane_higgshBand, 128, 5)
#    cont_higgsh = plot.contourFromTH2(plane_higgshBand, 125, 5)

if int(args.verbosity) > 0:
Пример #17
0
                               force_x_width=args.force_x_width,
                               force_y_width=args.force_y_width)
h_axis = h_proto
h_axis = plot.TH2FromTGraph2D(graphs[types[0]])
# Create the debug output file if requested
if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

# Fill TH2s by interpolating the TGraph2Ds, then extract contours
for c in types:
    print 'Filling histo for %s' % c
    hists[c] = h_proto.Clone(c)
    plot.fillTH2(hists[c], graphs[c])
    contours[c] = plot.contourFromTH2(hists[c], CL, 5, frameValue=1)
    if debug is not None:
        debug.WriteTObject(hists[c], 'hist_%s' % c)
        for i, cont in enumerate(contours[c]):
            debug.WriteTObject(cont, 'cont_%s_%i' % (c, i))

# Setup the canvas: we'll use a two pad split, with a small top pad to contain
# the CMS logo and the legend
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.TwoPadSplit(0.8, 0, 0)
pads[1].cd()
h_axis.GetXaxis().SetTitle(args.x_title)
h_axis.GetYaxis().SetTitle(args.y_title)
h_axis.Draw()

if args.hist is not None:
h_minus2sigma = plot.makeHist2D("h_minus2sigma", mA_bins, tanb_bins, graph_minus2sigma)
h_plus2sigma = plot.makeHist2D("h_plus2sigma", mA_bins, tanb_bins, graph_plus2sigma)
plot.fillTH2(h_exp, graph_exp)
plot.fillTH2(h_obs, graph_obs)
plot.fillTH2(h_minus1sigma, graph_minus1sigma)
plot.fillTH2(h_plus1sigma, graph_plus1sigma)
plot.fillTH2(h_minus2sigma, graph_minus2sigma)
plot.fillTH2(h_plus2sigma, graph_plus2sigma)
axis.Draw()
#Possibility to draw CLs heat map, would be a useful option, using e.g.
#h_exp.Draw("colzsame")

#Extract exclusion contours from the TH2Ds, use threshold 1.0 for limit and 0.05 for CLs
threshold=0.05
#threshold=1
cont_exp = plot.contourFromTH2(h_exp, threshold, 20)
cont_obs = plot.contourFromTH2(h_obs, threshold, 5)
cont_minus1sigma = plot.contourFromTH2(h_minus1sigma, threshold, 20)
cont_plus1sigma = plot.contourFromTH2(h_plus1sigma, threshold, 20)
cont_minus2sigma = plot.contourFromTH2(h_minus2sigma, threshold, 20)
cont_plus2sigma = plot.contourFromTH2(h_plus2sigma, threshold, 20)

#if args.scenario != "hMSSM" and "2HDM" not in args.scenario :
#    graph_higgshBand = plot.higgsConstraint(args.scenario, "h")
#    plane_higgshBand = plot.makeHist2D('plane_higgshBand', 36, 91, graph_higgshBand)
#    plot.fillTH2(plane_higgshBand, graph_higgshBand)
#    cont_higgshlow = plot.contourFromTH2(plane_higgshBand, 122, 5)
#    cont_higgshhigh = plot.contourFromTH2(plane_higgshBand, 128, 5)
#    cont_higgsh = plot.contourFromTH2(plane_higgshBand, 125, 5)

if int(args.verbosity) > 0 : outf = ROOT.TFile('plotting_debug.root', 'RECREATE')