list_hist = [] list_hist_notrigger = [] list_ratio = [] for i in range(0, len(hist_names)): hist = f.Get(hist_names[i]) hist_notrig = f.Get(hist_names_notrigger[i]) list_hist.append(hist) list_hist_notrigger.append(hist_notrig) hist.Divide(hist_notrig) list_ratio.append(hist) 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) pCMS12.SetTextAlign(12) pCMS12.SetFillStyle(-1)
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')
pCMS4.Draw() line2 = ROOT.TLine(xmin, 3.84159, xmax, 3.84159) line2.SetLineColor(1) line2.SetLineStyle(9) line2.SetLineWidth(1) line2.Draw() pCMS5 = ROOT.TPaveText(0.203, 0.3, .24, .32, "NDC") pCMS5.SetTextFont(42) pCMS5.SetTextSize(0.025) pCMS5.SetFillStyle(-1) pCMS5.SetBorderSize(0) pCMS5.AddText("68% CL") pCMS5.Draw() 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") pCMS1.Draw() pCMS12 = ROOT.TPaveText(left + 0.1, 1. - top * 1.13, 0.57, 1., "NDC") pCMS12.SetTextFont(52) pCMS12.SetTextSize(top * 0.73) pCMS12.SetTextAlign(12) pCMS12.SetFillStyle(-1) pCMS12.SetBorderSize(0)
l.SetFillColor(0) l.AddEntry(bdt_ttbb, 'ttbb', 'F') 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, 35.9 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)