Exemplo n.º 1
0
    def __init__(self, name, title, lumi, energy, simOnly):
        super(CanvasRatio, self).__init__(name, title)

        self.lumi = lumi
        self.energy = energy
        self.simOnly = simOnly

        bm_ = gStyle.GetPadBottomMargin()  
        tm_ = gStyle.GetPadTopMargin()
        lm_ = gStyle.GetPadLeftMargin()
        rm_ = gStyle.GetPadRightMargin()
  
        self.splitPad = 0.34
        self.cd()
        self.main = TPad("pMain","pMain",
                         0., self.splitPad ,1.,1.)
        
        self.ratio  = TPad("pRatio","pRatio",
                           0., 0. ,1.,self.splitPad)

        self.main.SetLeftMargin(lm_)
        self.main.SetRightMargin(rm_)
        self.main.SetTopMargin(tm_/(1-self.splitPad) )
        self.main.SetBottomMargin(0.02/(1-self.splitPad) )
        
        self.ratio.SetLeftMargin(lm_)
        self.ratio.SetRightMargin(rm_)
        self.ratio.SetTopMargin(0.01/self.splitPad)
        self.ratio.SetBottomMargin(bm_/self.splitPad)
        self.main.Draw()
        # cmsPrel(25000., 8., True, self.splitPad)
        self.ratio.Draw()
Exemplo n.º 2
0
def cmsPrel(lumi,  energy,  simOnly,  onLeft=True,  sp=0, textScale=1.):
    latex = TLatex()
  
    t = gStyle.GetPadTopMargin()/(1-sp)
    tmpTextSize=0.75*t
    latex.SetTextSize(tmpTextSize)
    latex.SetNDC()
    textSize=latex.GetTextSize()
    textSize*=textScale

    latex.SetName("lumiText")
    latex.SetTextFont(42)

    lumyloc = 0.965
    cmsyloc = 0.893
    simyloc = 0.858
    if sp!=0:
        lumyloc = 0.945
        cmsyloc = 0.85
        simyloc = 0.8
    cmsalign = 31
    cmsxloc = 0.924
    if onLeft:
        cmsalign = 11
        cmsxloc = 0.204
    xlumi = 1-gStyle.GetPadRightMargin()
    if (lumi > 0.):
        latex.SetTextAlign(31) # align left, right=31
        latex.SetTextSize(textSize*0.6/0.75)
        if(lumi > 1000. ):
            latex.DrawLatex(xlumi,lumyloc,
                            " {lumi} fb^{{-1}} ({energy} TeV)".format(
                                lumi=lumi/1000.,
                                energy=energy
                            ))
        else:
            latex.DrawLatex(xlumi,lumyloc,
                            " {lumi} pb^{{-1}} ({energy} TeV)".format(
                                lumi=lumi,
                                energy=energy
                            ))
  
    else:
        latex.SetTextAlign(31) # align right=31
        latex.SetTextSize(textSize*0.6/0.75)
        latex.DrawLatex(xlumi,lumyloc," {energy} TeV".format(energy=energy))
  
 
    latex.SetTextAlign(cmsalign) # align left / right
    latex.SetTextFont(61)
    latex.SetTextSize(textSize)
    latex.DrawLatex(cmsxloc, cmsyloc,"CMS")
  
    latex.SetTextFont(52)
    latex.SetTextSize(textSize*0.76)
    
    if(simOnly):
        latex.DrawLatex(cmsxloc, simyloc,"Simulation")
def draw_canvas_histo(nchannels, xmin, xmax, title, cat_names, channelID):
    c = TCanvas("c", "Canvas", 800, 600)
    c.Draw()

    h = TH2F("h", "", 10, xmin, xmax, 3 * nchannels, 0, 3 * nchannels)
    h.Draw()
    h.SetStats(0)
    h.SetXTitle(title)

    yaxis = h.GetYaxis()
    yaxis.SetLabelSize(0.05)

    for ibin in range(0, nchannels):
        yaxis.SetBinLabel(3 * nchannels - 1 - 3 * ibin, cat_names[ibin])

    pub = TLatex()
    pub.SetNDC()
    pub.SetTextFont(42)
    pub.SetTextSize(0.045)
    pub.SetTextAlign(11)
    pub.DrawLatex(gStyle.GetPadLeftMargin(), 0.92,
                  "#scale[1.2]{#bf{CMS}} #it{Preliminary}")

    lumi = TLatex()
    lumi.SetNDC()
    lumi.SetTextFont(42)
    lumi.SetTextSize(0.035)
    lumi.SetTextAlign(31)
    if channelID is "DL":
        lumi.DrawLatex(1 - gStyle.GetPadRightMargin(), 0.92,
                       "11.4 - 12.9 fb^{-1} (13 TeV)")
    elif channelID is "SL":
        lumi.DrawLatex(1 - gStyle.GetPadRightMargin(), 0.92,
                       "12.9 fb^{-1} (13 TeV)")

    return c, h
Exemplo n.º 4
0
    hist_new_nom.Add(list_nom_ewk[i], -1)
    hist_new_denom = list_denom_dy[i].Clone("new_dy_denom")
    hist_new_denom.Add(list_denom_ewk[i])
    hist_new_nom.Divide(hist_new_denom)
    list_new_dy_ewk.append(hist_new_nom)

    hist_new_nom = list_denom_dy[i].Clone("new_dy_nom")
    hist_new_nom.Add(list_nom_dy[i], -1)
    hist_new_nom.Add(list_denom_ewk_herwig[i])
    hist_new_nom.Add(list_nom_ewk_herwig[i], -1)
    hist_new_denom = list_denom_dy[i].Clone("new_dy_denom")
    hist_new_denom.Add(list_denom_ewk_herwig[i])
    hist_new_nom.Divide(hist_new_denom)
    list_new_dy_ewk_herwig.append(hist_new_nom)

right, top = gStyle.GetPadRightMargin(), gStyle.GetPadTopMargin()
left, bottom = gStyle.GetPadLeftMargin(), gStyle.GetPadBottomMargin()
pCMS1 = ROOT.TPaveText(left, 1. - top, 0.4, 1., "NDC")
pCMS1.SetTextFont(62)
pCMS1.SetTextSize(top * 0.75)
pCMS1.SetTextAlign(12)
pCMS1.SetFillStyle(-1)
pCMS1.SetBorderSize(0)
pCMS1.AddText("CMS")

pCMS12 = ROOT.TPaveText(left, 1. - top * 3.5, 0.57, 1., "NDC")
pCMS12.SetTextFont(52)
pCMS12.SetTextSize(0.02)
pCMS12.SetTextAlign(12)
pCMS12.SetFillStyle(-1)
pCMS12.SetBorderSize(0)
Exemplo n.º 5
0
  list_hist.append(hist)
  list_hist_notrigger.append(hist_notrig)
  hist.Divide(hist_notrig)
  list_ratio.append(hist)



list_ratio_data_mc = []
for i in range(0,len(hist_names)):	
  hist_mc=list_ratio_mc[i]
  hist_data=list_ratio[i].Clone("New_data")
  hist_data.Divide(hist_mc)
  list_ratio_data_mc.append(hist_data)


right = gStyle.GetPadRightMargin()
top = gStyle.GetPadTopMargin()
left = gStyle.GetPadLeftMargin()
bottom =  gStyle.GetPadBottomMargin()

pCMS1 = ROOT.TPaveText(left,1.-top,0.4,1.,"NDC")
pCMS1.SetTextFont(62)
pCMS1.SetTextSize(top*0.75)
pCMS1.SetTextAlign(12)
pCMS1.SetFillStyle(-1)
pCMS1.SetBorderSize(0)
pCMS1.AddText("CMS")

pCMS12 = ROOT.TPaveText(left+0.1,1.-top*1.13,0.57,1.,"NDC")
pCMS12.SetTextFont(52)
pCMS12.SetTextSize(top*0.73)
Exemplo n.º 6
0
    l.AddEntry(bdt_ttbj, 'ttbj', 'F')
    l.AddEntry(bdt_ttcc, 'ttcc', 'F')
    l.AddEntry(bdt_ttLF, 'ttLF', 'F')
    l.AddEntry(bdt_singletop, 'ST', 'F')
    l.AddEntry(bdt_others, 'Others', 'F')
    if not gen:
        l.AddEntry(0, "", "")
    l.AddEntry(bdt_sig, "Sig", "F")
    if gen:
        l.AddEntry(bdt_sig_gen, "Gen", "F")
    l.AddEntry(bdt_data, 'Data', 'P')

    label = TPaveText()
    label.SetX1NDC(gStyle.GetPadLeftMargin())
    label.SetY1NDC(1.0 - gStyle.GetPadTopMargin())
    label.SetX2NDC(1.0 - gStyle.GetPadRightMargin() + 0.03)
    label.SetY2NDC(1.0)
    label.SetTextFont(62)
    label.AddText(
        "Work in Progress        CMS, 41.3 fb^{-1} at #sqrt{s} = 13 TeV")
    label.SetFillStyle(0)
    label.SetBorderSize(0)
    label.SetTextSize(0.05)
    label.SetTextAlign(32)

    ##########################################
    pad1.cd()
    bdt_data.SetTitle("")
    bdt_data.SetMarkerStyle(20)
    bdt_data.SetMarkerSize(0.5)
    bdt_data.SetStats(0)
Exemplo n.º 7
0
                    x = dataMasses[energy][ds][iMass]
                    y = dataUnc[energy][ds][iMass][cat]
                    yErr = dataStat[energy][ds][iMass][cat] * 100.
                    y = abs(y) * 100.
                    #print("x = %s, y = %s" % (x,y))
                    graph.SetPoint(iMass, x + shift, y)
                    graph.SetPointError(iMass, 0., yErr)
                graph.Draw("PEZ")
                #graph.Print()
                graphs.append(graph)
                leg.AddEntry(graph, label, "P")
            leg.Draw()
            tlatex.DrawLatex(gStyle.GetPadLeftMargin(), 0.96,
                             PRELIMINARYSTRING)
            tlatex.SetTextAlign(32)
            tlatex.DrawLatex(1.02 - gStyle.GetPadRightMargin(), 0.96, errorSet)
            tlatex.SetTextAlign(12)
            dsLabel = "GF"
            if ds == "vbfH":
                dsLabel = "VBF"
            captionStr = r"%s %s" % (dsLabel, energy.replace("TeV", " TeV"))
            tlatex.DrawLatex(0.04 + gStyle.GetPadLeftMargin(), 0.88,
                             captionStr)
            errorSetSaveName = errorSet.replace(" ", "")
            canvas.SaveAs(errorSetSaveName + "_" + ds + energy + ".png")
            canvas.SaveAs(errorSetSaveName + "_" + ds + energy + ".eps")
            canvas.SaveAs(errorSetSaveName + "_" + ds + energy + ".pdf")
            canvas.SaveAs(errorSetSaveName + "_" + ds + energy + ".root")

    # Now for a table
    tableStr = ""
Exemplo n.º 8
0
def setupCOLZFrame(pad, reset=False):
    if reset:
        pad.SetRightMargin(gStyle.GetPadRightMargin())
    else:
        pad.SetRightMargin(0.15)
        gStyle.SetOptStat(0)
Exemplo n.º 9
0
def fit_quantiles(X_region,names,style=True,n_bins=100,pol='Pol',outString=None):  
    if style==True:
        gROOT.SetBatch(True)
        gROOT.ProcessLineSync(".x /mnt/t3nfs01/data01/shome/nchernya/HHbbgg_ETH_devel/scripts/setTDRStyle.C")
        gROOT.ForceStyle()
        gStyle.SetPadTopMargin(0.06)
        gStyle.SetPadRightMargin(0.04)
        gStyle.SetPadLeftMargin(0.15)
    

    h_names = [ 'region'+str(t) for t in range(0,len(X_region))]

    c_min=0
    c_max=2.

    hist_list=[]
    func_list=[]
    max_list=[]
    datahists=[]
    graphs=[]
    func=[]
    colors=[ROOT.kBlue+1,ROOT.kAzure+5,ROOT.kCyan-1, ROOT.kGreen, ROOT.kSpring+8, ROOT.kOrange]
   # nqx=3
  #  taus = array('d',[0.25, 0.5, 0.75])
  #  nqx=5
  #  taus = array('d',[0.5-0.68/2,0.3, 0.5, 0.7, 0.5+0.68/2.])
 #   nqx=4
  #  taus = array('d',[0.5-0.68/2,0.3, 0.5, 0.8])
  #  nqx=4
  #  taus = array('d',[0.5-0.68/2,0.4, 0.5, 0.8])
 #   nqx=4
  #  taus = array('d',[0.10,0.16, 0.2, 0.7])
 #   nqx=4
  #  taus = array('d',[0.10,0.16, 0.4, 0.7])   
  #  nqx=5
   # taus = array('d',[0.10,0.16, 0.4, 0.6, 0.8])   
   # nqx=5
   # taus = array('d',[0.10,0.20, 0.4, 0.6, 0.8])   
    nqx=4
    taus = array('d',[0.10,0.20, 0.4, 0.7])    # the best
    taus_fit = array('d',[x-taus[0] for x in taus ])
    quantiles_pos=[]
    x0_hist=[]
    x0_CDFfit=[]
 
 
    for j in range(len(X_region)):
        h=h_names[j]
        data =((X_region[j]).as_matrix()).ravel()
      #  print len(data)
        h_rel_diff = TH1F("hrel_diff_%s"%h_names[j], "hrel_diff_%s"%h_names[j], n_bins, c_min, c_max)
        h_rel_diff.Sumw2(True)
        for i in range(len(data)): 
            h_rel_diff.Fill(data[i])
        h_rel_diff.Scale(1./h_rel_diff.Integral())
        h_rel_diff.SetLineColor(colors[j])
        h_rel_diff.SetMarkerColor(colors[j])
        h_rel_diff.SetLineWidth(2)
        h_rel_diff.SetLineStyle(1+j)
        h_rel_diff.SetMarkerStyle(20+j)
        datahists.append(h_rel_diff)
        quantiles_x = array('d', [0 for x in range(0, nqx)])
        h_rel_diff.GetQuantiles( nqx,quantiles_x, taus )
        quantiles_pos.append(quantiles_x)
        max_list.append(h_rel_diff.GetMaximum()*1.3)
        x0_hist.append(h_rel_diff.GetBinCenter(h_rel_diff.GetMaximumBin()))

        gr = TGraph(nqx,quantiles_x,taus_fit);
        gr.SetLineColor(colors[j])
        gr.SetMarkerColor(colors[j])
        gr.SetMarkerStyle(20+j)
        graphs.append(gr)

   #     fit_cdf = TF1("fit_%s"%h, myCDF, 0., 2., 4)   
       # fit_cdf = TF1("fit_%s"%h, myCDF,quantiles_x[0]*0.98,quantiles_x[4]*1.02,4) 
     #   fit_cdf = TF1("fit_%s"%h, myErFuncCdf,quantiles_x[0]*0.98,quantiles_x[3]*1.02,4) 
    #    fit_cdf = TF1("fit_%s"%h,"pol3",quantiles_x[0]*0.98,quantiles_x[nqx-1]*1.02)   #final with pol3
        fit_cdf = TF1("fit_%s"%h,"pol3",quantiles_x[0]*0.98,quantiles_x[nqx-1]*1.02)   #final with pol3
  #      fit_cdf.FixParameter(1,quantiles_x[0] )  #q1   
  #      fit_cdf.FixParameter(2,quantiles_x[2] )  #q3   
  #      fit_cdf.SetParameter(0,1. )  #x0   
  #      fit_cdf.SetParameter(4,3. )  #const 
  #      fit_cdf.SetParLimits(4,0.,10 )  #const 
  #      fit_cdf.SetParLimits(0, 0.5, 1.5)    
        fit_cdf.SetLineColor(colors[j])
        gr.Fit("fit_%s"%h,"R")
        func.append(fit_cdf)
        
   #     pol_coeff = [6*fit_cdf.GetParameter(4), 3*fit_cdf.GetParameter(3),fit_cdf.GetParameter(2)]  # for pol4 only
   #     pol_roots = np.roots(pol_coeff)
   #     pol_roots_diff = [x - x0_hist[j] for x in pol_roots]
    #    x0_CDFfit.append(pol_roots[min(xrange(len(pol_roots_diff)), key=pol_roots_diff.__getitem__)])

    #    x0_CDFfit.append(-1*fit_cdf.GetParameter(2)/3/fit_cdf.GetParameter(3))  #for pol3 only
        x0_CDFfit.append(fit_cdf.GetParameter(0))  #for erFunc

    c = TCanvas("canv","canv",1600,800)
    c.Divide(2,1)
    c.cd(1)
    frame = TH1F("hframe", "", n_bins, c_min, c_max)
    frame.SetStats(0)
    frame.GetXaxis().SetTitleOffset(0.91);
    frame.GetYaxis().SetTitle("Events")
    frame.GetXaxis().SetTitle("p_{T}^{gen}/p_{T}^{reco}")
    frame.GetYaxis().SetLabelSize(0.04)
    leg = ROOT.TLegend(0.12,0.75,0.6,0.9)
    leg.SetFillStyle(-1)
    leg.SetBorderSize(0)
    leg.SetTextFont(42)
    leg.SetTextSize(0.025)
    frame.GetYaxis().SetRangeUser(0.,max(max_list))
    frame.Draw()
    for j in range(len(X_region)):
        datahists[j].Draw("PEsame")
        leg.AddEntry(datahists[j],names[j] ,"PE")
    leg.Draw('same')

    c.cd(2)
    right,top   = gStyle.GetPadRightMargin(),gStyle.GetPadTopMargin()
    left,bottom = gStyle.GetPadLeftMargin(),gStyle.GetPadBottomMargin()
    ci = ROOT.TColor.GetColor("#ffffff")
 #   frame2 = TH1F("hframe2", "", n_bins, 0.9, 1.25)
    frame2 = TH1F("hframe2", "", n_bins, 0.7, 1.4)
    frame2.SetStats(0)
    frame2.GetXaxis().SetTitleOffset(0.91);
    frame2.GetYaxis().SetTitle("#tau - #tau_{1}")
    frame2.GetXaxis().SetTitle("Quantiles positions")
    frame2.GetYaxis().SetLabelSize(0.04)
    frame2.GetYaxis().SetRangeUser(-0.05,max(taus_fit)*1.1)
    frame2.Draw()
    paveText2 = ROOT.TPaveText(0.6,0.25,0.9,.4,"NDC")
    paveText2.SetTextFont(42)
    paveText2.SetTextSize(top*0.43)
    paveText2.SetFillStyle(-1)
    paveText2.SetBorderSize(0)
    for j in range(len(X_region)):
        graphs[j].Draw("PEsame")
        func[j].Draw("sameR")
        t = paveText2.AddText("x0 hist/fit : %.2f/%.2f"%(x0_hist[j],x0_CDFfit[j]))
        print("%.2f"%x0_CDFfit[j])
        t.SetTextColor(colors[j]);
    leg.Draw('same')

   # paveText = ROOT.TPaveText(0.7,0.85,0.9,.9,"NDC")
    paveText = ROOT.TPaveText(0.75,0.65,0.95,.9,"NDC")
    paveText.SetTextFont(42)
    paveText.SetTextColor(ROOT.kBlue)
    paveText.SetTextSize(top*0.43)
    paveText.SetFillStyle(-1)
    paveText.SetBorderSize(0)
    paveText.AddText("%s Fit"%pol)
    paveText.AddText("Quantiles : ")
    for x in taus :  paveText.AddText("%.2f"%x)
    paveText.Draw("same")
   
    paveText2.Draw("same")
   # print x0_hist, x0_CDFfit
   
 
    line = ROOT.TLine(x0_hist[0],frame2.GetMinimum() ,x0_hist[0],frame2.GetMaximum())
    line.SetLineStyle(9)
    line.SetLineWidth(2)
    line.SetLineColor(ROOT.kRed+1)
    line.Draw("Lsame")

    c.SaveAs(utils.IO.plotFolder+"quantiles_"+str(outString)+str(pol)+'.png')
    c.SaveAs(utils.IO.plotFolder+"quantiles_"+str(outString)+str(pol)+'.pdf')