def setPlotStyle(): gStyle.SetPadGridX(1) gStyle.SetPadGridY(1) gStyle.SetOptStat(1110) gStyle.SetLineWidth(2) gStyle.SetHistLineWidth(3) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetTextFont(62) gStyle.SetLabelFont(62) gStyle.SetTitleFont(62) gStyle.SetLegendBorderSize(1) gStyle.SetLegendFont(62)
def set_root_env(): from ROOT import gStyle, gROOT gROOT.Reset() gROOT.SetStyle('Plain') gStyle.SetCanvasColor(10) gStyle.SetStatBorderSize(1) gStyle.SetFillColor(10) gStyle.SetOptStat(1) gStyle.SetStatX(0.46) gStyle.SetStatY(0.9) gStyle.SetTitleYOffset(1.4) gStyle.SetPalette(45) gStyle.SetMarkerSize(0.8) gStyle.SetLineColor(1) gStyle.SetLineWidth(1)
def rootStyle(batchMode=True): from ROOT import gROOT, gStyle, kWhite, kBlack # No info messages gROOT.ProcessLine("gErrorIgnoreLevel = kWarning;") # Batch mode (no TCanvas) gROOT.SetBatch(batchMode) # Start from a plain default gROOT.SetStyle("Plain") lhcbMarkerType = 8 lhcbMarkerSize = 0.8 lhcbFont = 62 lhcbStatFontSize = 0.02 lhcbStatBoxWidth = 0.12 lhcbStatBoxHeight = 0.12 lhcbWidth = 1 lhcbTextSize = 0.05 lhcbLabelSize = 0.035 lhcbAxisLabelSize = 0.035 lhcbForeColour = kBlack gStyle.SetFrameBorderMode(0) gStyle.SetPadBorderMode(0) # canvas options gStyle.SetCanvasBorderSize(0) gStyle.SetCanvasBorderMode(0) # fonts gStyle.SetTextFont(lhcbFont) gStyle.SetTextSize(lhcbTextSize) gStyle.SetLabelFont(lhcbFont, "x") gStyle.SetLabelFont(lhcbFont, "y") gStyle.SetLabelFont(lhcbFont, "z") gStyle.SetLabelSize(lhcbLabelSize, "x") gStyle.SetLabelSize(lhcbLabelSize, "y") gStyle.SetLabelSize(lhcbLabelSize, "z") gStyle.SetTitleFont(lhcbFont) gStyle.SetTitleSize(lhcbAxisLabelSize, "x") gStyle.SetTitleSize(lhcbAxisLabelSize, "y") gStyle.SetTitleSize(lhcbAxisLabelSize, "z") gStyle.SetTitleColor(kWhite) gStyle.SetTitleFillColor(kWhite) gStyle.SetTitleColor(kBlack) gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(kBlack) # set title position gStyle.SetTitleX(0.15) gStyle.SetTitleY(0.97) # turn off Title box gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(lhcbForeColour) gStyle.SetTitleColor(lhcbForeColour) # use bold lines and markers gStyle.SetLineWidth(lhcbWidth) gStyle.SetFrameLineWidth(lhcbWidth) gStyle.SetHistLineWidth(lhcbWidth) gStyle.SetFuncWidth(lhcbWidth) gStyle.SetGridWidth(lhcbWidth) gStyle.SetLineStyleString(2, "[12 12]") gStyle.SetMarkerStyle(lhcbMarkerType) gStyle.SetMarkerSize(lhcbMarkerSize) # label offsets gStyle.SetLabelOffset(0.015) # by default, do not display histogram decorations: gStyle.SetOptStat(1111) # show probability, parameters and errors gStyle.SetOptFit(1011) # look of the statistics box: gStyle.SetStatBorderSize(1) gStyle.SetStatFont(lhcbFont) gStyle.SetStatFontSize(lhcbStatFontSize) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatW(lhcbStatBoxWidth) gStyle.SetStatH(lhcbStatBoxHeight) # put tick marks on top and RHS of plots gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) # histogram divisions gStyle.SetNdivisions(505, "x") gStyle.SetNdivisions(510, "y") # Force the style gROOT.ForceStyle()
def DrawOverlap(histList, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1], cat='2b'): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") #gStyle.SetTitleOffset(1.9,"X"); gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) gStyle.SetTickLength(0.0, "x") i = 0 # histList_=[] # histList=[] # histList1=[] # maximum=[] ## Legend leg = TLegend(0.2, 0.80, 0.89, 0.89) #,NULL,"brNDC"); leg.SetBorderSize(0) leg.SetNColumns(3) # leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) # leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.05) c = TCanvas("c1", "c1", 0, 0, 500, 500) c.SetBottomMargin(0.15) c.SetLeftMargin(0.15) c.SetLogy(logstatus[1]) c.SetLogx(logstatus[0]) # print ("you have provided "+str(len(fileVec))+" files and "+str(len(histVec))+" histograms to make a overlapping plot" ) # print "opening rootfiles" c.cd() print "provided hists", histList for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: histList[ih].SetMaximum(1.5) #1.4 for log histList[ih].SetMinimum(0.1) #1.4 for log if logstatus[1] is 0: maxi = histList[ih].GetMaximum() histList[ih].SetMaximum(maxi * 2) #1.4 for log histList[ih].SetMinimum(0) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("APL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("PE2 ") if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("PL same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("PE0 same") if tt is TGraphAsymmErrors: histList[ih].SetMaximum(100) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(0) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): print "setting style for hist" print "color code", colors[ih] # histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetFillColor(colors[ih]) histList[ih].SetMarkerStyle(20) histList[ih].SetMarkerSize(1.0) histList[ih].SetLineWidth(1) #invert legend between first and second if ih == 0: leg.AddEntry(histList[ih + 1], legendtext[ih + 1], "PEL") #"f") if ih == 1: leg.AddEntry(histList[ih - 1], legendtext[ih - 1], 'f') #"PEL") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.052) histList[ih].GetYaxis().SetTitleOffset(1.4) histList[ih].GetYaxis().SetTitleFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelSize(.052) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) # histList[ih].GetXaxis().SetLabelSize(0.0000); histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) #histList[ih].GetXaxis().SetTitleOffset(1.14) histList[ih].GetXaxis().SetTitleFont(42) histList[ih].GetXaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetXaxis().SetNdivisions(507) #histList[ih].GetXaxis().SetMoreLogLabels(); #histList[ih].GetXaxis().SetNoExponent(); #histList[ih].GetTGaxis().SetMaxDigits(3); # histList[ih].GetXaxis().SetTickSize(0.00) i = i + 1 pt = TPaveText(0.01, 0.92, 0.95, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.046) #text = pt.AddText(0.12,0.35,"CMS Internal 36 fb^{-1} (2016) ") text = pt.AddText(0.12, 0.35, "CMS Internal 41.5 fb^{-1} (2017) ") #text = pt.AddText(0.12,0.35,"CMS Internal 59.6 fb^{-1} (2018) ") #text = pt.AddText(0.6,0.5,"41.5 fb^{-1} (2017) ") cattxt = TLatex(0.20, 0.75, cat + ' ' + "category") cattxt.SetTextSize(0.06) cattxt.SetTextAlign(12) cattxt.SetNDC(1) cattxt.SetTextFont(42) pt.Draw() cattxt.Draw() leg.Draw() outputdirname = 'TFplots/' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')
def set_root_env(): #//TStyle* genieStyle = new TStyle("genieStyle", "GENIE Style") #//set the background color to white gStyle.SetFillColor(10) gStyle.SetFrameFillColor(10) gStyle.SetCanvasColor(10) gStyle.SetPadColor(10) gStyle.SetTitleFillColor(0) gStyle.SetStatColor(10) #dont put a colored frame around the plots gStyle.SetFrameBorderMode(0) gStyle.SetCanvasBorderMode(0) gStyle.SetPadBorderMode(0) gStyle.SetLegendBorderSize(3) #use the primary color palette #gStyle.SetPalette(1,0) #set the default line color for a histogram to be black gStyle.SetHistLineColor(ROOT.kBlack) #set the default line color for a fit function to be red gStyle.SetFuncColor(ROOT.kRed) #make the axis labels black gStyle.SetLabelColor(ROOT.kBlack, "xyz") #set the default title color to be black gStyle.SetTitleColor(ROOT.kBlack) #set the margins gStyle.SetPadBottomMargin(0.18) gStyle.SetPadTopMargin(0.08) gStyle.SetPadRightMargin(0.08) gStyle.SetPadLeftMargin(0.17) #set axis label and title text sizes gStyle.SetLabelFont(42, "xyz") gStyle.SetLabelSize(0.04, "xyz") gStyle.SetLabelOffset(0.015, "xyz") gStyle.SetTitleFont(42, "xyz") gStyle.SetTitleSize(0.04, "xyz") gStyle.SetTitleOffset(1.4, "y") gStyle.SetTitleOffset(1.3, "x") gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.07) gStyle.SetTitleBorderSize(1) gStyle.SetStatBorderSize(0) gStyle.SetTextFont(42) gStyle.SetTitleW(0.5) gStyle.SetTitleH(0.1) #set line widths gStyle.SetFrameLineWidth(2) gStyle.SetFuncWidth(2) gStyle.SetHistLineWidth(2) #set the number of divisions to show gStyle.SetNdivisions(506, "xy") #gStyle.SetPadTickX(-50202) #turn off xy grids gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) #set the tick mark style gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) #turn off stats gStyle.SetOptStat(0) gStyle.SetOptFit(0) #marker/line settings #gStyle.SetMarkerStyle(20) gStyle.SetMarkerSize(.95) #0.7 gStyle.SetLineWidth(2) gStyle.SetErrorX(0) gStyle.SetHistLineStyle(0) #It was 3 for a dotted line #done gStyle.cd() gROOT.ForceStyle()
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") gStyle.SetTitleOffset(0.9, "X") gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] ## Legend leg = TLegend(0.4, 0.70, 0.939, 0.89) #,NULL,"brNDC"); legendtitle = legendtext[-1] leg.SetHeader(legendtitle) leg.SetBorderSize(0) leg.SetNColumns(2) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(22) leg.SetTextSize(0.045) c = TCanvas("c1", "c1", 0, 0, 500, 500) #c.SetBottomMargin(0.15) #c.SetLeftMargin(0.15) #c.SetLogy(0) #c.SetLogx(0) c1_2 = TPad("c1_2", "newpad", 0.04, 0.05, 1, 0.994) c1_2.Draw() print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() #c1_2.SetBottomMargin(0.13) c1_2.SetLogy(logstatus[1]) c1_2.SetLogx(logstatus[0]) c1_2.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) print histList[ii].Integral() #histList[ii].Rebin(xRange[2]) type_obj = type(histList[ii]) if (type_obj is TH1D) or (type_obj is TH1F) or ( type_obj is TH1) or (type_obj is TH1I): histList[ii].Rebin(1) histList[ii].Scale(1.0 / histList[ii].Integral()) maximum.append(histList[ii].GetMaximum()) maximum.sort() ii = ii + 1 print histList for ih in range(len(histList)): tt = type(histList[ih]) # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if (tt is TGraphAsymmErrors) | (tt is TGraph): histList[ih].Draw("A3P") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("HIST") if ih > 0: #histList[ih].SetLineWidth(2) if (tt is TGraphAsymmErrors) | (tt is TGraph): histList[ih].Draw("3P same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("HISTsame") if (tt is TGraphAsymmErrors) | (tt is TGraph): # histList[ih].SetMaximum(0.06) # histList[ih].SetMinimum(0.02) # histList[ih].SetMaximum(maximum+0.3) histList[ih].SetMinimum(0.02) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "P") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) histList[ih].SetMaximum(maximum[0] + 0.3) histList[ih].SetMinimum(0) leg.AddEntry(histList[ih], legendtext[ih], "L") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.045) histList[ih].GetYaxis().SetTitleOffset(1.1000998) histList[ih].GetYaxis().SetTitleFont(22) histList[ih].GetYaxis().SetLabelFont(22) histList[ih].GetYaxis().SetLabelSize(.045) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) histList[ih].GetXaxis().SetLabelSize(0.0000) histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) histList[ih].GetXaxis().SetTitleOffset(1.04) histList[ih].GetXaxis().SetTitleFont(22) histList[ih].GetXaxis().SetTickLength(0.07) histList[ih].GetXaxis().SetLabelFont(22) histList[ih].GetYaxis().SetLabelFont(22) # histList[ih].GetXaxis().SetNdivisions(508) # i = i + 1 pt = TPaveText(0.0877181, 0.9, 0.9580537, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(22) pt.SetTextSize(0.046) text = pt.AddText(0.05, 0.5, "CMS Preliminary") #text = pt.AddText(0.5,0.5,"12.9 fb^{-1} (13 TeV)") # text = pt.AddText(0.8,0.5," (13 TeV)") # text = pt.AddText(0.65,0.5," AK8") pt.Draw() # t2a = TPaveText(0.0877181,0.81,0.9580537,0.89,"brNDC") # t2a.SetBorderSize(0) # t2a.SetFillStyle(0) # t2a.SetTextSize(0.040) # t2a.SetTextAlign(12) # t2a.SetTextFont(62) # histolabel1= str(fileVec[(len(fileVec)-1)]) # text1 = t2a.AddText(0.06,0.5,"CMS Internal") # t2a.Draw() leg.Draw() # # c.cd() outputdirname = 'HGCAL/' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')
## this will search for files in the previous directory sys.path.append('../') ## this will search for files in '../Helpers' sys.path.append('../Helpers') import fileutils ######################################### # # Set Weights for each sample # ######################################### gStyle.SetOptStat(0) gStyle.SetOptTitle(0) gStyle.SetFrameLineWidth(3) gStyle.SetLineWidth(1) debug_ = False processes = ['qcd', 'vh', 'dibosons', 'stop', 'ttbar', 'zll', 'wjets', 'zvv'] processesLegend = ['QCD', 'SM H', 'VV', 'ST', 'TT', 'Zll', 'WJ', 'Z#nu#nu'] region = [ 'tt(e)', 'tt(e) fail', 'tt(#mu)', 'tt(#mu) fail', 'W(e)', 'W(e) fail', 'W(#mu)', 'W(#mu) fail', 'Zee', 'Zee fail', 'Z#mu#mu', 'Z#mu#mu fail', 'Sig' ] fin = fileutils.OpenRootFile('summaryHisto.root') bkgStack = THStack("bkgStack", "bkgStack")
def log10_Q2_rto(): #reconstructed and generated log_10(Q^2) #full range in Q^2 lqbin = 0.04 #lqmin = -8 lqmin = -7 #lqmax = -1.5 lqmax = -1 #minimal Q^2 for ratio plot #lrmin = -5 lrmin = -5.2 #can = ut.box_canvas() can = TCanvas("can", "can", 768, 768) gStyle.SetOptStat("") gStyle.SetPalette(1) gStyle.SetLineWidth(2) gStyle.SetPadTickY(1) hLog10Q2rec = ut.prepare_TH1D("hLog10Q2rec", lqbin, lqmin, lqmax) hLog10Q2gen = ut.prepare_TH1D("hLog10Q2gen", lqbin, lqmin, lqmax) #distributions for ratio plot hRecRto = ut.prepare_TH1D("hRecRto", lqbin, lrmin, lqmax) hGenRto = ut.prepare_TH1D("hGenRto", lqbin, lrmin, lqmax) hRtoPlot = ut.prepare_TH1D("hRtoPlot", lqbin, lrmin, lqmax) tree.Draw("rec_lq >> hLog10Q2rec") tree.Draw("true_lq >> hLog10Q2gen") #tree.Draw("lq2_rec >> hRecRto", "lq2_rec>"+str(lrmin)) #tree.Draw("lq2_gen >> hGenRto", "lq2_rec>"+str(lrmin)) #tree.Draw("lq2_rec >> hRecRto", "lq2_rec>"+str(lrmin)+" && lq2_gen>"+str(lrmin)) #tree.Draw("lq2_gen >> hGenRto", "lq2_rec>"+str(lrmin)+" && lq2_gen>"+str(lrmin)) tree.Draw("rec_lq >> hRecRto") tree.Draw("true_lq >> hGenRto") ut.line_h1(hLog10Q2gen, rt.kBlue) hLog10Q2gen.SetLineWidth(3) hLog10Q2rec.SetLineColor(rt.kRed) hLog10Q2rec.SetMarkerColor(rt.kRed) pdiv = 0.4 pad1 = TPad("p1", "p1", 0., pdiv, 1., 1.) # upper pad2 = TPad("p2", "p2", 0., 0., 1., pdiv) # lower pad1.Draw() pad2.Draw() #upper plot pad1.cd() #frame1 = gPad.DrawFrame(lqmin, 1e-3, lqmax, 8e3) frame1 = gPad.DrawFrame(lqmin, 1e-3, lqmax, 6e3) #frame1 = gPad.DrawFrame(lqmin, 1e-3, lqmax, 1.4e3) siz = 0.045 ut.set_H1_text_size(frame1, siz) frame1.Draw() frame1.SetYTitle("Events / {0:.3f}".format(lqbin)) frame1.SetTitleOffset(1.4, "Y") hLog10Q2gen.Draw("same") hLog10Q2rec.Draw("e1same") lmg = 0.12 rmg = 0.01 ut.set_margin_lbtr(gPad, lmg, 0, 0.04, rmg) #leg = ut.prepare_leg(0.5, 0.75, 0.2, 0.15, siz) leg = ut.prepare_leg(0.2, 0.75, 0.2, 0.15, siz) leg.AddEntry(hLog10Q2gen, "Pythia6 generated events", "l") leg.AddEntry(hLog10Q2rec, "Reconstruction in low #it{Q}^{2} tagger", "lp") leg.Draw("same") ut.invert_col(rt.gPad) #lower plot pad2.cd() frame2 = gPad.DrawFrame(lqmin, 0.5, lqmax, 1.5 - 1e-5) siz2 = siz * (1. + (1. - pdiv)) ut.set_H1_text_size(frame2, siz2) frame2.Draw() ut.put_yx_tit(frame2, "Reconstructed / generated", "log_{10}(Q^{2}) (GeV)", 0.85, 1.3) #line at one unity = TLine(lqmin, 1., lqmax, 1.) unity.SetLineColor(rt.kBlack) unity.SetLineWidth(1) unity.Draw() #ratio rec/gen hRto = hRecRto.Clone() hRto.Sumw2() hRto.Divide(hGenRto) for i in xrange(1, hRtoPlot.GetNbinsX() + 1): if hRtoPlot.GetBinLowEdge(i) < lrmin: continue hRtoPlot.SetBinContent(i, hRto.GetBinContent(i)) hRtoPlot.SetBinError(i, hRto.GetBinError(i)) #hRto.Draw("same") hRtoPlot.Draw("same") ut.set_margin_lbtr(gPad, lmg, 0.22, 0, rmg) leg2 = ut.prepare_leg(0.12, 0.83, 0.2, 0.1, siz2) leg2.AddEntry(hRto, "Ratio rec / gen", "lp") leg2.Draw("same") ut.invert_col(rt.gPad) can.SaveAs("01fig.pdf")
def CLICdpStyle(): gROOT.SetStyle("Plain") gStyle.SetCanvasColor(root.kWhite) gStyle.SetFrameFillColor(root.kWhite) gStyle.SetStatColor(root.kWhite) gStyle.SetPadColor(root.kWhite) gStyle.SetFillColor(10) gStyle.SetTitleFillColor(root.kWhite) gStyle.SetPaperSize(20, 26) gStyle.SetDrawBorder(0) gStyle.SetCanvasBorderMode(0) gStyle.SetPadBorderMode(0) gStyle.SetFrameBorderMode(0) gStyle.SetLegendBorderSize(0) gStyle.SetTextSize(0.05) gStyle.SetTitleSize(0.06, "xyz") gStyle.SetLabelSize(0.06, "xyz") gStyle.SetLabelOffset(0.015, "xyz") gStyle.SetTitleOffset(1.2, "yz") gStyle.SetTitleOffset(1.17, "x") font = 42 gStyle.SetTitleFont(font) gStyle.SetTitleFontSize(0.06) gStyle.SetStatFont(font) gStyle.SetStatFontSize(0.07) gStyle.SetTextFont(font) gStyle.SetLabelFont(font, "xyz") gStyle.SetTitleFont(font, "xyz") gStyle.SetTitleBorderSize(0) gStyle.SetStatBorderSize(1) gStyle.SetMarkerStyle(1) gStyle.SetLineWidth(2) gStyle.SetMarkerSize(1.2) gStyle.SetPalette(1) gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetOptFit(0) gStyle.SetEndErrorSize(5) gStyle.SetHistLineWidth(2) gStyle.SetFrameLineWidth(2) gStyle.SetFuncWidth(2) gStyle.SetHistLineColor(root.kBlack) gStyle.SetFuncColor(root.kBlack) gStyle.SetLabelColor(root.kBlack, "xyz") gStyle.SetPadBottomMargin(0.18) gStyle.SetPadTopMargin(0.11) gStyle.SetPadRightMargin(0.08) gStyle.SetPadLeftMargin(0.17) gStyle.SetNdivisions(506, "xy") gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetCanvasDefW(800) gStyle.SetCanvasDefH(700) gROOT.ForceStyle()
def initStyle(): gROOT.SetStyle("Plain") # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(700) #Height of canvas gStyle.SetCanvasDefW(700) #Width of canvas gStyle.SetCanvasDefX(0) #Position on screen gStyle.SetCanvasDefY(0) # For the line: gStyle.SetLineWidth(2) # For the Pad: gStyle.SetPadBorderMode(0) # gStyle.SetPadBorderSize(Width_t size = 1) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(True) gStyle.SetPadGridY(True) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: # gStyle.SetHistFillColor(1) # gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(2) # gStyle.SetLegoInnerR(Float_t rad = 0.5) # gStyle.SetNumberContours(Int_t number = 20) gStyle.SetEndErrorSize(2) #gStyle.SetErrorMarker(20) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(8) gStyle.SetMarkerSize(1) #For the fit/function: gStyle.SetOptFit(0) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) #For the date: gStyle.SetOptDate(0) # gStyle.SetDateX(Float_t x = 0.01) # gStyle.SetDateY(Float_t y = 0.01) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # gStyle.SetStatStyle(Style_t style = 1001) # gStyle.SetStatX(Float_t x = 0) # gStyle.SetStatY(Float_t y = 0) # Margins: gStyle.SetPadTopMargin(0.11) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.17) gStyle.SetPadRightMargin(0.07) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.04) # gStyle.SetTitleH(0) # Set the height of the title box # gStyle.SetTitleW(0) # Set the width of the title box #gStyle.SetTitleX(0.35) # Set the position of the title box #gStyle.SetTitleY(0.986) # Set the position of the title box # gStyle.SetTitleStyle(Style_t style = 1001) #gStyle.SetTitleBorderSize(0) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.05, "XYZ") # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size? # gStyle.SetTitleYSize(Float_t size = 0.02) gStyle.SetTitleXOffset(1.) gStyle.SetTitleYOffset(1.3) #gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.035, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX( 1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPalette(1) #(1,0) # another top group addition gStyle.SetHatchesSpacing(1.0) # Postscript options: gStyle.SetPaperSize(20., 20.) #gStyle.SetPaperSize(TStyle.kA4) #gStyle.SetPaperSize(27., 29.7) #TGaxis.SetMaxDigits(3) # gStyle.SetLineScalePS(Float_t scale = 3) # gStyle.SetLineStyleString(Int_t i, const char* text) # gStyle.SetHeaderPS(const char* header) # gStyle.SetTitlePS(const char* pstitle) #gStyle.SetColorModelPS(1) # gStyle.SetBarOffset(Float_t baroff = 0.5) # gStyle.SetBarWidth(Float_t barwidth = 0.5) # gStyle.SetPaintTextFormat(const char* format = "g") # gStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0) # gStyle.SetTimeOffset(Double_t toffset) # gStyle.SetHistMinimumZero(kTRUE) #gStyle.cd() print "TDR Style initialized"
def initialization(batch=True, font=default_font): '''-- ROOT initialization --''' print "Initializing ROOT ..." # general gROOT.Reset() gROOT.SetBatch(batch) gROOT.SetStyle("Plain") # gStyle gStyle.SetFillColor(0) gStyle.SetCanvasColor(10) gStyle.SetLineWidth(1) gStyle.SetPalette(8) gStyle.SetTextFont(font) #gStyle.SetTextSize(30) # Frame gStyle.SetFrameBorderMode(0) gStyle.SetFrameFillColor(0) # Pad gStyle.SetPadBorderMode(0) gStyle.SetPadColor(0) gStyle.SetPadBottomMargin(0.1) gStyle.SetPadTopMargin(0.01) gStyle.SetPadLeftMargin(0.1) gStyle.SetPadRightMargin(0.01) gStyle.SetPadTickX(1) # make ticks be on all 4 sides. gStyle.SetPadTickY(1) gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) # histogram gStyle.SetHistFillStyle(0) gStyle.SetOptTitle(0) gStyle.SetTitleSize(0.22) gStyle.SetTitleFontSize(10) gStyle.SetTitleFont(font) gStyle.SetTitleFont(font, "xyz") gStyle.SetTitleYOffset(1.0) gStyle.SetTitleXOffset(1.0) gStyle.SetTitleXSize(0.04) gStyle.SetTitleYSize(0.04) gStyle.SetTitleX(.15) gStyle.SetTitleY(.98) gStyle.SetTitleW(.70) gStyle.SetTitleH(.05) # statistics box gStyle.SetOptStat(0) gStyle.SetStatFont(font) gStyle.SetStatFontSize(10) gStyle.SetStatX(.91) gStyle.SetStatY(.90) gStyle.SetStatW(.15) gStyle.SetStatH(.15) # axis labels gStyle.SetLabelFont(font) gStyle.SetLabelFont(font, "xyz") gStyle.SetLabelSize(10, "xyz") # gStyle.SetGridColor(1) gStyle.SetLegendBorderSize(1)
def tdrstyle(): gROOT.SetStyle("Plain") gStyle.SetAxisColor(1, "XYZ") gStyle.SetCanvasColor(0) #gStyle.SetCanvasBorderSize(10) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasDefH(700) gStyle.SetCanvasDefW(700) gStyle.SetCanvasDefX(0) gStyle.SetCanvasDefY(0) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillStyle(0) gStyle.SetFrameFillColor(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) # 0? gStyle.SetFrameLineWidth(1) # 1? gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) #gStyle.SetHistFillColor(1) #gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42,"XYZ") gStyle.SetLabelOffset(0.007,"XYZ") # 0.010? gStyle.SetLabelSize(0.05,"XYZ") # 0.04? gStyle.SetLegendBorderSize(0) gStyle.SetLegendFillColor(0) gStyle.SetLegendFont(42) gStyle.SetMarkerSize(1.0) gStyle.SetMarkerStyle(20) gStyle.SetLineColor(1) gStyle.SetLineWidth(2) #gStyle.SetLineScalePS(2) gStyle.SetOptDate(0) gStyle.SetOptFile(0) gStyle.SetOptFit(1) gStyle.SetOptStat(0) gStyle.SetOptTitle(0) #gStyle.SetOptLogx(0) #gStyle.SetOptLogy(0) #gStyle.SetOptLogz(0) gStyle.SetPadColor(0) gStyle.SetPadBorderMode(0) gStyle.SetPadBorderSize(10) gStyle.SetPadTopMargin(0.05) # 0.08? gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.03) # 0.05? gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetStatColor(0) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) #gStyle.SetStatX(0) #gStyle.SetStatY(0) #gStyle.SetTextSize(0.055) gStyle.SetTextFont(42) gStyle.SetTitleBorderSize(0) gStyle.SetTitleColor(1) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1,"XYZ") gStyle.SetTitleFont(42,"XYZ") gStyle.SetTitleSize(0.06,"XYZ") # 0.05? #gStyle.SetTitleOffset(1.4,"XYZ") gStyle.SetTitleOffset(0.9,"X") gStyle.SetTitleOffset(1.20,"Y") gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) gStyle.SetTitleTextColor(1) #gStyle.SetTitleH(0) #gStyle.SetTitleW(0) #gStyle.SetTitleX(0) #gStyle.SetTitleY(0.985) #gStyle.SetTitleStyle(1001) gStyle.SetPalette(1) #gStyle.SetNdivisions(510, "XYZ") # 505? gStyle.SetNdivisions(505, "XYZ") gStyle.SetEndErrorSize(2) # 2? #gStyle.SetErrorMarker(20) #gStyle.SetErrorX(0.) #gStyle.SetPaperSize(20.,20.) gStyle.SetStripDecimals(1) gStyle.SetTickLength(0.03, "XYZ") return 1
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") gStyle.SetTitleOffset(0.9, "X") gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] ## Legend leg = TLegend(0.65, 0.650, 0.89, 0.85) #,NULL,"brNDC"); leg.SetBorderSize(0) # leg.SetNColumns(3) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(22) leg.SetTextSize(0.045) c = TCanvas("c1", "c1", 0, 0, 500, 500) #c.SetBottomMargin(0.15) #c.SetLeftMargin(0.15) #c.SetLogy(0) #c.SetLogx(0) c1_2 = TPad("c1_2", "newpad", 0., 0.30, 1, 0.994) c1_2.Draw() c1_1 = TPad("c1_1", "newpad1", 0, 0.02, 1, 0.30) c1_1.Draw() print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() c1_2.SetBottomMargin(0.013) c1_2.SetLogy(logstatus[1]) c1_2.SetLogx(logstatus[0]) c1_2.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) print histList[ii].Integral() histList[ii].Rebin(xRange[2]) print('after', histList[ii].Integral(0, -1)) histList[ii].Scale(1.0 / histList[ii].Integral(0, -1)) maximum.append(histList[ii].GetMaximum()) maximum.sort() ii = ii + 1 print histList for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: histList[ih].SetMaximum(maximum[(len(maximum) - 1)] * 25) #1.4 for log histList[ih].SetMinimum(0.001) #1.4 for log if logstatus[1] is 0: histList[ih].SetMaximum(maximum[(len(maximum) - 1)] * 1.2) #1.4 for log histList[ih].SetMinimum(0) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("AP") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("hist") if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("P same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("hist same") if tt is TGraphAsymmErrors: histList[ih].SetMaximum(1.4) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) leg.AddEntry(histList[ih], legendtext[ih], "L") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.062) histList[ih].GetYaxis().SetTitleOffset(0.78) histList[ih].GetYaxis().SetTitleFont(22) histList[ih].GetYaxis().SetLabelFont(22) histList[ih].GetYaxis().SetLabelSize(.062) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) histList[ih].GetXaxis().SetLabelSize(0.0000) histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) histList[ih].GetXaxis().SetTitleOffset(1.04) histList[ih].GetXaxis().SetTitleFont(22) histList[ih].GetXaxis().SetTickLength(0.07) histList[ih].GetXaxis().SetLabelFont(22) histList[ih].GetYaxis().SetLabelFont(22) # histList[ih].GetXaxis().SetNdivisions(508) # i = i + 1 pt = TPaveText(0.0877181, 0.91, 0.9580537, 0.95, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(22) pt.SetTextSize(0.046) # text = pt.AddText(0.05,0.5,"ATLAS Internal ") text = pt.AddText(0.65, 1.0, "#sqrt{s} = 13 TeV (36fb^{-1})") pt.Draw() t2a = TPaveText(0.277181, 0.81, 0.6780537, 0.89, "brNDC") t2a.SetBorderSize(0) t2a.SetFillStyle(0) t2a.SetTextSize(0.046) t2a.SetTextAlign(12) t2a.SetTextFont(22) histolabel1 = str(fileVec[(len(fileVec) - 1)]) text1 = t2a.AddText(0.065, 0.5, "ATLAS Internal") t2a.Draw() leg.Draw() # c.cd() h_inc = histList1[0].Clone() h_vbs = histList1[1].Clone() h_qcd = histList1[2].Clone() h_int = histList1[3].Clone() h_inc.Add(h_vbs, -1) h_inc.Add(h_qcd, -1) ## ratio plot hdivide_1 = h_int.Clone() hdivide_1.Divide(h_vbs) # hdivide_1.GetYaxis().SetTitle(str(legendtext[(len(legendtext)-1)])) hdivide_1.GetYaxis().SetTitleSize(0.11) hdivide_1.GetYaxis().SetTitle("ratio") hdivide_1.GetYaxis().SetTitleOffset(0.43) hdivide_1.GetYaxis().SetTitleFont(22) hdivide_1.GetYaxis().SetLabelSize(0.13) hdivide_1.GetYaxis().CenterTitle() hdivide_1.GetXaxis().SetTitleSize(0.14) hdivide_1.GetXaxis().SetTitleOffset(0.89) hdivide_1.GetXaxis().SetTitleFont(22) hdivide_1.GetXaxis().SetLabelSize(0.14) hdivide_1.GetYaxis().SetLabelFont(22) c.cd() c1_1.cd() # c1_1.Range(-7.862408,-629.6193,53.07125,486.5489) c1_1.SetFillColor(0) c1_1.SetTicky(1) c1_1.SetTopMargin(0.0510) c1_1.SetBottomMargin(0.3006666678814) c1_1.SetFrameFillStyle(0) c1_1.SetFrameBorderMode(0) c1_1.SetFrameFillStyle(0) c1_1.SetFrameBorderMode(0) c1_1.SetLogy(0) hdivide_1.GetXaxis().SetRangeUser(xRange[0], xRange[1]) hdivide_1.GetYaxis().SetNdivisions(505) c1_1.Draw() c1_1.SetGridy() hdivide_1.SetMarkerStyle(20) hdivide_1.SetMarkerColor(2) hdivide_1.SetMarkerSize(1) hdivide_1.Draw("P") hdivide_2 = h_int.Clone() hdivide_2.Divide(h_qcd) hdivide_2.SetMarkerStyle(21) hdivide_2.SetMarkerColor(4) hdivide_2.SetMarkerSize(1) hdivide_2.Draw("Psame") hdivide_3 = h_int.Clone() hdivide_3.Divide(h_inc) hdivide_3.SetMarkerStyle(22) hdivide_3.SetMarkerColor(1) hdivide_3.SetMarkerSize(1) hdivide_3.Draw("Psame") hdivide_1.SetMinimum(-1.01) hdivide_1.SetMaximum(3.20) c.cd() outputdirname = 'plots/' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf') c.SaveAs(histname + '.root') c.SaveAs(histname + '.C')
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) gStyle.SetTitleOffset(1.1, "Y") #gStyle.SetTitleOffset(1.9,"X"); gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] minimum = [] ## Legend leg = TLegend(0.1, 0.80, 0.89, 0.89) #,NULL,"brNDC"); leg.SetBorderSize(0) leg.SetNColumns(3) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.05) c = TCanvas("c1", "c1", 0, 0, 500, 500) c.SetBottomMargin(0.15) c.SetLogy(logstatus[1]) c.SetLogx(logstatus[0]) print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) #print histList[ii].Integral() #histList[ii].Rebin(xRange[2]) #histList[ii].Scale(1.0/histList[ii].Integral()) maximum.append(histList[ii].GetMaximum()) minimum.append(histList[ii].GetMinimum()) maximum.sort() ii = ii + 1 print histList print maximum, " ", max(maximum) print minimum, " ", min(minimum) for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: histList[ih].SetMaximum(1.5) #1.4 for log histList[ih].SetMinimum(0.1) #1.4 for log if logstatus[1] is 0: maxi = max(maximum) mini = min(minimum) if maxi == 0.0: maxi = 0.001 if mini == 0.0: mini = -0.001 histList[ih].SetMaximum(maxi * 3) #1.4 for log histList[ih].SetMinimum(mini * 3) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("APL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("P hist") if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("PL same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("P hist same") if tt is TGraphAsymmErrors: histList[ih].SetMaximum(100) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(2) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetMarkerStyle(20) histList[ih].SetMarkerSize(1.0) histList[ih].SetLineWidth(3) leg.AddEntry(histList[ih], legendtext[ih], "P") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.052) histList[ih].GetYaxis().SetTitleOffset(0.98) histList[ih].GetYaxis().SetTitleFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelSize(.052) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) # histList[ih].GetXaxis().SetLabelSize(0.0000); histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) #histList[ih].GetXaxis().SetTitleOffset(1.14) histList[ih].GetXaxis().SetTitleFont(42) histList[ih].GetXaxis().SetLabelFont(42) histList[ih].GetYaxis().SetLabelFont(42) histList[ih].GetXaxis().SetNdivisions(507) #histList[ih].GetXaxis().SetMoreLogLabels(); #histList[ih].GetXaxis().SetNoExponent(); #histList[ih].GetTGaxis().SetMaxDigits(3); i = i + 1 pt = TPaveText(0.01, 0.92, 0.95, 0.96, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.046) #text = pt.AddText(0.12,0.35,"CMS Internal 36 fb^{-1} (2016) ") text = pt.AddText(0.12, 0.35, "CMS Internal 41.5 fb^{-1} (2017) ") #text = pt.AddText(0.12,0.35,"CMS Internal 59.6 fb^{-1} (2018) ") #text = pt.AddText(0.6,0.5,"41.5 fb^{-1} (2017) ") pt.Draw() leg.Draw() outputdirname = 'UncPlots/' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')
def plot_mlt(mat): can = TCanvas("can", "can", 768, 768) gStyle.SetOptStat("") gStyle.SetPalette(1) gStyle.SetLineWidth(2) gStyle.SetPadTickY(1) nx = 3 ny = 4 #nx = 2 #ny = 2 theta_min = 1.9 theta_max = 3.5 #theta_max = 5.2 #theta_max = 7 #theta_min = 2+1e-3 #theta_max = 4.5-1e-3 #theta_max = 4-1e-3 lmgg = 0.17 rmgg = 0.21 bmgg = 0.17 tmgg = 0.03 tsiz = 0.07 ytit = "Vertical #it{y} (mm)" yofs = 1.2 xtit = "Horizontal #it{x} (mm)" xofs = 1.2 ztit = "Mean polar angle as -log_{10}(#pi-#it{#theta}_{e})" zofs = 1.1 ijmap = {} ii = 1 dx = 1. / nx dy = 1. / ny pads = [] for i in range(ny): for j in range(nx): ijmap[ii] = (i, j) print(ii, i, j) pnam = "pad_" + str(ii) pads.append( TPad(pnam, pnam, j * dx, 1 - (i + 1) * dy, (j + 1) * dx, 1 - i * dy)) pads[len(pads) - 1].Draw() ii += 1 for i in range(1, nx * ny + 1): pads[i - 1].cd() hx = mat.tjks[i].hTjk hx.SetTitle("") ut.set_H1_text_size(hx, tsiz) hx.SetTitleSize(tsiz, "Z") hx.SetLabelSize(tsiz, "Z") hx.SetMinimum(theta_min) hx.SetMaximum(theta_max) lmg = lmgg bmg = bmgg tmg = tmgg rmg = rmgg ip = ijmap[i][1] jp = ijmap[i][0] if ip < nx - 1: hx.GetZaxis().SetTickLength(0) if ip == 0 and jp == 0: hx.SetYTitle(ytit) hx.SetTitleOffset(yofs, "Y") if jp == ny - 1 and ip == nx - 1: hx.SetXTitle(xtit) hx.SetTitleOffset(xofs, "X") if ip == nx - 1 and jp == 0: hx.SetZTitle(ztit) hx.SetTitleOffset(zofs, "Z") if ip == 0: rmg = 0 if ip > 0 and ip < nx - 1: lmg = 0 rmg = 0 if ip == nx - 1: lmg = 0 if jp == 0: bmg = 0 if jp == ny - 1: tmg = 0 if jp > 0 and jp < ny - 1: bmg = 0 tmg = 0 ut.set_margin_lbtr(gPad, lmg, bmg, tmg, rmg) #gPad.SetLogz() gPad.SetGrid() hx.SetContour(300) #hx.SetContour(100) hx.Draw("colz") #energy label hEn = mat.hEi emin = hEn.GetBinLowEdge(i) emax = hEn.GetBinLowEdge(i) + hEn.GetBinWidth(i) eminf = "{0:.2f}".format(emin) emaxf = "{0:.2f}".format(emax) desc = TLatex() desc.SetTextSize(0.075) # tsiz etit = "#it{i}: " + str( i) + ", " + eminf + " < #it{E}_{e} < " + emaxf + " GeV" etit = "#color[2]{" + etit + "}" #desc.DrawLatex(380, 80, etit) #desc.DrawLatex(-180, 150, etit) desc.DrawLatex(-100, 85, etit) #ut.invert_col(gPad) can.SaveAs("01fig.pdf")
def applyRootStyle(): from ROOT import gROOT, gStyle, kWhite, kBlack, TColor # Start from a plain default gROOT.SetStyle("Plain") lhcbMarkerType = 8 lhcbMarkerSize = 0.8 lhcbFont = 62 lhcbStatFontSize = 0.02 lhcbStatBoxWidth = 0.12 lhcbStatBoxHeight = 0.12 lhcbWidth = 1 lhcbTextSize = 0.05 lhcbLabelSize = 0.035 lhcbAxisLabelSize = 0.035 lhcbForeColour = kBlack gStyle.SetFrameBorderMode(0) gStyle.SetPadBorderMode(0) # canvas options gStyle.SetCanvasBorderSize(0) gStyle.SetCanvasBorderMode(0) # fonts gStyle.SetTextFont(lhcbFont) gStyle.SetTextSize(lhcbTextSize) gStyle.SetLabelFont(lhcbFont, "x") gStyle.SetLabelFont(lhcbFont, "y") gStyle.SetLabelFont(lhcbFont, "z") gStyle.SetLabelSize(lhcbLabelSize, "x") gStyle.SetLabelSize(lhcbLabelSize, "y") gStyle.SetLabelSize(lhcbLabelSize, "z") gStyle.SetTitleFont(lhcbFont) gStyle.SetTitleSize(lhcbAxisLabelSize, "x") gStyle.SetTitleSize(lhcbAxisLabelSize, "y") gStyle.SetTitleSize(lhcbAxisLabelSize, "z") gStyle.SetTitleColor(kWhite) gStyle.SetTitleFillColor(kWhite) gStyle.SetTitleColor(kBlack) gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(kBlack) # set title position gStyle.SetTitleX(0.15) gStyle.SetTitleY(0.97) # turn off Title box gStyle.SetTitleBorderSize(0) gStyle.SetTitleTextColor(lhcbForeColour) gStyle.SetTitleColor(lhcbForeColour) # use bold lines and markers gStyle.SetLineWidth(lhcbWidth) gStyle.SetFrameLineWidth(lhcbWidth) gStyle.SetHistLineWidth(lhcbWidth) gStyle.SetFuncWidth(lhcbWidth) gStyle.SetGridWidth(lhcbWidth) gStyle.SetLineStyleString(2, "[12 12]") gStyle.SetMarkerStyle(lhcbMarkerType) gStyle.SetMarkerSize(lhcbMarkerSize) # Grid # gStyle.SetGridStyle(3) # label offsets gStyle.SetLabelOffset(0.015) # by default, do not display histogram decorations: gStyle.SetOptStat(1111) # show probability, parameters and errors gStyle.SetOptFit(1011) # look of the statistics box: gStyle.SetStatBorderSize(1) gStyle.SetStatFont(lhcbFont) gStyle.SetStatFontSize(lhcbStatFontSize) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatW(lhcbStatBoxWidth) gStyle.SetStatH(lhcbStatBoxHeight) # put tick marks on top and RHS of plots gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) # histogram divisions gStyle.SetNdivisions(505, "x") gStyle.SetNdivisions(510, "y") # Style for 2D zcol plots NRGBs = 5 NCont = 255 from array import array stops = array('d', [0.00, 0.34, 0.61, 0.84, 1.00]) red = array('d', [0.00, 0.00, 0.87, 1.00, 0.51]) green = array('d', [0.00, 0.81, 1.00, 0.20, 0.00]) blue = array('d', [0.51, 1.00, 0.12, 0.00, 0.00]) TColor().CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont) gStyle.SetNumberContours(NCont) # Force the style gROOT.ForceStyle()
def rocPlotMacro(): # load TDR-style plotting macro gROOT.LoadMacro("$CMSSW_BASE/src/TauAnalysisTools/TauAnalysisTools/macros/tdrstyle.C") ROOT.setTDRStyle() gStyle.SetFrameLineWidth(3) gStyle.SetLineWidth(3) gStyle.SetPadGridX(True) gStyle.SetPadGridY(True) gStyle.SetPadTopMargin(0.08) gStyle.SetPadBottomMargin(0.15) gStyle.SetPadLeftMargin(0.18) gStyle.SetPadRightMargin(0.05) gStyle.SetTitleFontSize(0.055) gStyle.SetTitleSize(0.055, "XYZ") gStyle.SetTitleXOffset(1.25) gStyle.SetTitleYOffset(1.60) gStyle.SetLabelSize(0.04, "XYZ") gStyle.SetLabelOffset(0.013, "XYZ") # list of trainings reference53X = { 'folder' : 'forFabio', 'color' : ROOT.kGreen, 'text' : '53X' } reference74X = { 'folder' : 'antiElectronDiscr74X_onlyZWTTjetsHiggsWZprimeSUSY_FullSkim', 'color' : ROOT.kMagenta, 'text' : '74X (Complete skim)' } inputFilePath = '/nfs/dust/cms/user/fcolombo/HiggsToTauTau/TauPOG/antiElectronDiscrMVATraining' trainingList = [] trainingList.append(reference53X) trainingList.append(reference74X) # list of plots to produce roc_linear = { 'file' : 'showROCcurvesAntiElectronDiscrMVA_all_linear.root', 'name' : 'roc_linear', 'y_range' : [0.4, 1.], 'y_log' : False, 'leg_loc' : [0.2, 0.2, 0.8, 0.35] } roc_log = { 'file' : 'showROCcurvesAntiElectronDiscrMVA_all_log.root', 'name' : 'roc_log', 'y_range' : [0.001, 1.], 'y_log' : True, 'leg_loc' : [0.2, 0.75, 0.8, 0.9] } plotList = [] plotList.append(roc_linear) plotList.append(roc_log) pTbinsList = ['','tauPtLt50_','tauPt50to100_','tauPt100to200_','tauPt200to400_','tauPt400to600_','tauPt600to900_','tauPt900to1200_','tauPtGt1200_'] for iPlot, plotDict in enumerate(plotList): for ptBin in pTbinsList: filename = 'showROCcurvesAntiElectronDiscrMVA_all_'+ptBin+('log' if plotDict['y_log'] else 'linear') c1 = TCanvas() c1.SetTitle(plotDict['name']) legend = TLegend(plotDict['leg_loc'][0], plotDict['leg_loc'][1], plotDict['leg_loc'][2], plotDict['leg_loc'][3]) legend.SetShadowColor(0) legend.SetFillColor(0) for iTrain, trainDict in enumerate(trainingList): file = TFile.Open(os.path.join(inputFilePath, trainDict['folder'], filename+'.root')) canvas = file.Get("canvas") histo = canvas.GetPrimitive("dummyHistogram") graph = canvas.GetPrimitive("mvaAntiElectronDiscr5_TestTree_"+ptBin+"cloned") legend.AddEntry(graph, trainDict['text'], 'l') c1.cd() if (iTrain == 0): histo.GetYaxis().SetRangeUser(plotDict['y_range'][0], plotDict['y_range'][1]) histo.GetYaxis().SetTitleOffset(1.6) histo.Draw() graph.SetMarkerColor(trainDict['color']) graph.SetLineColor(trainDict['color']) graph.SetLineWidth(2) graph.Draw("LP SAME") if (plotDict['y_log'] == True): c1.SetLogy() legend.Draw() if 'plots' not in os.listdir(inputFilePath): os.mkdir(os.path.join(inputFilePath, 'plots')) c1.SaveAs(os.path.join(inputFilePath, 'plots', plotDict['name']+'_'+(ptBin[:-1] if ptBin != '' else 'all')+'.png'))
def setStyle(): gStyle.SetCanvasColor(0) gStyle.SetCanvasBorderSize(10) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasDefH(700) gStyle.SetCanvasDefW(700) gStyle.SetPadColor(0) gStyle.SetPadBorderSize(10) gStyle.SetPadBorderMode(0) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadTopMargin(0.08) gStyle.SetPadLeftMargin(0.15) gStyle.SetPadRightMargin(0.05) gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetFrameFillStyle(0) gStyle.SetFrameFillColor(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(0) gStyle.SetFrameLineWidth(1) gStyle.SetFrameBorderSize(10) gStyle.SetFrameBorderMode(0) gStyle.SetNdivisions(505) gStyle.SetLineWidth(2) gStyle.SetHistLineWidth(2) gStyle.SetFrameLineWidth(2) gStyle.SetLegendFillColor(root.kWhite) gStyle.SetLegendFont(42) gStyle.SetMarkerSize(1.2) gStyle.SetMarkerStyle(20) gStyle.SetLabelSize(0.040, "X") gStyle.SetLabelSize(0.040, "Y") gStyle.SetLabelOffset(0.010, "X") gStyle.SetLabelOffset(0.010, "Y") gStyle.SetLabelFont(42, "X") gStyle.SetLabelFont(42, "Y") gStyle.SetTitleBorderSize(0) gStyle.SetTitleFont(42) gStyle.SetTitleFont(42, "X") gStyle.SetTitleFont(42, "Y") gStyle.SetTitleSize(0.045, "X") gStyle.SetTitleSize(0.045, "Y") gStyle.SetTitleOffset(1.4, "X") gStyle.SetTitleOffset(1.4, "Y") gStyle.SetTextSize(0.055) gStyle.SetTextFont(42) gStyle.SetOptStat(0)
def fit(): #fit to log_10(pT^2) with components and plot of plain pT^2 #range in log_10(pT^2) ptbin = 0.12 ptmin = -5. ptmax = 0.99 # 1.01 #range in pT^2 ptsq_bin = 0.03 ptsq_min = 1e-5 ptsq_max = 1 mmin = 2.8 mmax = 3.2 #range for incoherent fit fitran = [-0.9, 0.1] #number of gamma-gamma events ngg = 131 #number of psi' events npsiP = 20 #input data pT = RooRealVar("jRecPt", "pT", 0, 10) m = RooRealVar("jRecM", "mass", 0, 10) data_all = RooDataSet("data", "data", tree, RooArgSet(pT, m)) #select for mass range strsel = "jRecM>{0:.3f} && jRecM<{1:.3f}".format(mmin, mmax) data = data_all.reduce(strsel) #create log(pT^2) from pT ptsq_draw = "jRecPt*jRecPt" # will be used for pT^2 logPtSq_draw = "TMath::Log10(" + ptsq_draw + ")" logPtSq_form = RooFormulaVar("logPtSq", "logPtSq", logPtSq_draw, RooArgList(pT)) logPtSq = data.addColumn(logPtSq_form) logPtSq.setRange("fitran", fitran[0], fitran[1]) #bins and range for the plot nbins, ptmax = ut.get_nbins(ptbin, ptmin, ptmax) logPtSq.setMin(ptmin) logPtSq.setMax(ptmax) logPtSq.setRange("plotran", ptmin, ptmax) #range for pT^2 ptsq_nbins, ptsq_max = ut.get_nbins(ptsq_bin, ptsq_min, ptsq_max) #incoherent parametrization bval = RooRealVar("bval", "bval", 3.3, 0, 10) inc_form = "log(10.)*pow(10.,logPtSq)*exp(-bval*pow(10.,logPtSq))" incpdf = RooGenericPdf("incpdf", inc_form, RooArgList(logPtSq, bval)) #make the incoherent fit res = incpdf.fitTo(data, rf.Range("fitran"), rf.Save()) #get incoherent norm to the number of events lset = RooArgSet(logPtSq) iinc = incpdf.createIntegral(lset, rf.NormSet(lset), rf.Range("fitran")) inc_nevt = data.sumEntries("logPtSq", "fitran") incpdf.setNormRange("fitran") aval = RooRealVar("aval", "aval", inc_nevt / incpdf.getNorm(lset)) #print "A =", aval.getVal() #print "b =", bval.getVal() #incoherent distribution from log_10(pT^2) function for the sum with gamma-gamma hIncPdf = ut.prepare_TH1D_n("hGG", nbins, ptmin, ptmax) func_incoh_logPt2 = TF1("func_incoh_logPt2", "[0]*log(10.)*pow(10.,x)*exp(-[1]*pow(10.,x))", -10., 10.) func_incoh_logPt2.SetNpx(1000) func_incoh_logPt2.SetLineColor(rt.kMagenta) func_incoh_logPt2.SetParameters( aval.getVal(), bval.getVal()) # 4.9 from incoherent mc, 3.3 from data fit ut.fill_h1_tf(hIncPdf, func_incoh_logPt2, rt.kMagenta) #gamma-gamma contribution hGG = ut.prepare_TH1D_n("hGG", nbins, ptmin, ptmax) tree_gg.Draw(logPtSq_draw + " >> hGG", strsel) ut.norm_to_num(hGG, ngg, rt.kGreen + 1) #sum of incoherent distribution and gamma-gamma hSumIncGG = ut.prepare_TH1D_n("hSumIncGG", nbins, ptmin, ptmax) hSumIncGG.Add(hIncPdf) hSumIncGG.Add(hGG) ut.line_h1(hSumIncGG, rt.kMagenta) #gamma-gamma in pT^2 hGG_ptsq = ut.prepare_TH1D_n("hGG_ptsq", ptsq_nbins, ptsq_min, ptsq_max) tree_gg.Draw(ptsq_draw + " >> hGG_ptsq", strsel) ut.norm_to_num(hGG_ptsq, ngg, rt.kGreen + 1) #psi' contribution psiP_file = TFile.Open(basedir_mc + "/ana_slight14e4x1_s6_sel5z.root") psiP_tree = psiP_file.Get("jRecTree") hPsiP = ut.prepare_TH1D_n("hPsiP", nbins, ptmin, ptmax) psiP_tree.Draw(logPtSq_draw + " >> hPsiP", strsel) ut.norm_to_num(hPsiP, npsiP, rt.kViolet) #psi' in pT^2 hPsiP_ptsq = ut.prepare_TH1D_n("hPsiP_ptsq", ptsq_nbins, ptsq_min, ptsq_max) psiP_tree.Draw(ptsq_draw + " >> hPsiP_ptsq", strsel) ut.norm_to_num(hPsiP_ptsq, npsiP, rt.kViolet) #create canvas frame gStyle.SetPadTickY(1) can = ut.box_canvas(1086, 543) # square area is still 768^2 can.SetMargin(0, 0, 0, 0) can.Divide(2, 1, 0, 0) gStyle.SetLineWidth(1) can.cd(1) ut.set_margin_lbtr(gPad, 0.11, 0.1, 0.01, 0) frame = logPtSq.frame(rf.Bins(nbins)) frame.SetTitle("") frame.SetMaximum(80) frame.SetYTitle("Events / ({0:.3f}".format(ptbin) + " GeV^{2})") frame.SetXTitle("log_{10}( #it{p}_{T}^{2} ) (GeV^{2})") frame.GetXaxis().SetTitleOffset(1.2) frame.GetYaxis().SetTitleOffset(1.6) #plot the data data.plotOn(frame, rf.Name("data"), rf.LineWidth(2)) #incoherent parametrization incpdf.plotOn(frame, rf.Range("fitran"), rf.LineColor(rt.kRed), rf.Name("incpdf"), rf.LineWidth(2)) incpdf.plotOn(frame, rf.Range("plotran"), rf.LineColor(rt.kRed), rf.Name("incpdf_full"), rf.LineStyle(rt.kDashed), rf.LineWidth(2)) frame.Draw() #add gamma-gamma contribution hGG.Draw("same") #sum of incoherent distribution and gamma-gamma #hSumIncGG.Draw("same") #add psi' #hPsiP.Draw("same") #legend for log_10(pT^2) leg = ut.prepare_leg(0.15, 0.77, 0.28, 0.19, 0.035) hxl = ut.prepare_TH1D("hxl", 1, 0, 1) hxl.Draw("same") ilin = ut.col_lin(rt.kRed, 2) ilin2 = ut.col_lin(rt.kRed, 2) ilin2.SetLineStyle(rt.kDashed) leg.AddEntry(ilin, "Incoherent parametrization, fit region", "l") leg.AddEntry(ilin2, "Incoherent parametrization, extrapolation region", "l") leg.AddEntry(hGG, "#gamma#gamma#rightarrow e^{+}e^{-}", "l") #leg.AddEntry(hxl, "Data", "lp") leg.AddEntry(hxl, "Data, log_{10}( #it{p}_{T}^{2} )", "lp") leg.Draw("same") #----- plot pT^2 on the right ----- #pT^2 variable from pT ptsq_form = RooFormulaVar("ptsq", "ptsq", ptsq_draw, RooArgList(pT)) ptsq = data.addColumn(ptsq_form) #range for pT^2 plot ptsq.setMin(ptsq_min) ptsq.setMax(ptsq_max) #make the pT^2 plot can.cd(2) gPad.SetLogy() #gPad.SetLineWidth(3) #gPad.SetFrameLineWidth(1) ut.set_margin_lbtr(gPad, 0, 0.1, 0.01, 0.15) ptsq_frame = ptsq.frame(rf.Bins(ptsq_nbins), rf.Title("")) #print type(ptsq_frame), type(ptsq) ptsq_frame.SetTitle("") ptsq_frame.SetXTitle("#it{p}_{T}^{2} (GeV^{2})") ptsq_frame.GetXaxis().SetTitleOffset(1.2) data.plotOn(ptsq_frame, rf.Name("data"), rf.LineWidth(2)) ptsq_frame.SetMaximum(9e2) ptsq_frame.SetMinimum(0.8) # 0.101 ptsq_frame.Draw() #incoherent parametrization in pT^2 over the fit region, scaled to the plot inc_ptsq = TF1("inc_ptsq", "[0]*exp(-[1]*x)", 10**fitran[0], 10**fitran[1]) inc_ptsq.SetParameters(aval.getVal() * ptsq_bin, bval.getVal()) #incoherent parametrization in the extrapolation region, below and above the fit region inc_ptsq_ext1 = TF1("inc_ptsq_ext1", "[0]*exp(-[1]*x)", 0., 10**fitran[0]) inc_ptsq_ext2 = TF1("inc_ptsq_ext2", "[0]*exp(-[1]*x)", 10**fitran[1], 10) inc_ptsq_ext1.SetParameters(aval.getVal() * ptsq_bin, bval.getVal()) inc_ptsq_ext1.SetLineStyle(rt.kDashed) inc_ptsq_ext2.SetParameters(aval.getVal() * ptsq_bin, bval.getVal()) inc_ptsq_ext2.SetLineStyle(rt.kDashed) inc_ptsq.Draw("same") inc_ptsq_ext1.Draw("same") inc_ptsq_ext2.Draw("same") #add gamma-gamma in pT^2 hGG_ptsq.Draw("same") #add psi' in pT^2 #hPsiP_ptsq.Draw("same") #redraw the frame #ptsq_frame.Draw("same") ptsq_frame.GetXaxis().SetLimits(-9e-3, ptsq_frame.GetXaxis().GetXmax()) #vertical axis for pT^2 plot xpos = ptsq_frame.GetXaxis().GetXmax() ypos = ptsq_frame.GetMaximum() ymin = ptsq_frame.GetMinimum() ptsq_axis = TGaxis(xpos, 0, xpos, ypos, ymin, ypos, 510, "+GL") ut.set_axis(ptsq_axis) ptsq_axis.SetMoreLogLabels() ptsq_axis.SetTitle("Events / ({0:.3f}".format(ptsq_bin) + " GeV^{2})") ptsq_axis.SetTitleOffset(2.2) ptsq_axis.Draw() #legend for input data #dleg = ut.prepare_leg(0.4, 0.77, 0.14, 0.18, 0.035) dleg = ut.prepare_leg(0.4, 0.71, 0.16, 0.24, 0.035) dleg.AddEntry(None, "#bf{|#kern[0.3]{#it{y}}| < 1}", "") ut.add_leg_mass(dleg, mmin, mmax) dleg.AddEntry(None, "AuAu@200 GeV", "") dleg.AddEntry(None, "UPC sample", "") dleg.AddEntry(hxl, "Data, #it{p}_{T}^{2}", "lp") dleg.Draw("same") #ut.invert_col_can(can) can.SaveAs("01fig.pdf")
def DrawOverlap(fileVec, histVec, titleVec, legendtext, pngname, logstatus=[0, 0], xRange=[-99999, 99999, 1], text_="", x_=0.5, y_=0.5, legendloc=[0.53, 0.13, 0.93, 0.39]): gStyle.SetOptTitle(0) gStyle.SetOptStat(0) #gStyle.SetTitleOffset(1.1,"Y"); #gStyle.SetTitleOffset(0.9,"X"); gStyle.SetLineWidth(3) gStyle.SetFrameLineWidth(3) i = 0 histList_ = [] histList = [] histList1 = [] maximum = [] ## Legend legpos = legendloc leg = TLegend(legpos[0], legpos[1], legpos[2], legpos[3]) leg.SetBorderSize(0) leg.SetNColumns(2) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) leg.SetTextSize(0.049) from PlotTemplates import myCanvas1D c = myCanvas1D() c.SetLogy(logstatus[1]) c.SetLogx(logstatus[0]) #c.SetBottomMargin(0.15) #c.SetLeftMargin(0.15) #c1_2 = TPad("c1_2","newpad",0.04,0.13,1,0.994) #c1_2.Draw() print("you have provided " + str(len(fileVec)) + " files and " + str(len(histVec)) + " histograms to make a overlapping plot") print "opening rootfiles" c.cd() #c1_2.SetBottomMargin(0.013) #c1_2.SetLogy(logstatus[1]) #c1_2.SetLogx(logstatus[0]) #c1_2.cd() ii = 0 inputfile = {} print str(fileVec[(len(fileVec) - 1)]) for ifile_ in range(len(fileVec)): print("opening file " + fileVec[ifile_]) inputfile[ifile_] = TFile(fileVec[ifile_]) print "fetching histograms" for ihisto_ in range(len(histVec)): print("printing histo " + str(histVec[ihisto_])) histo = inputfile[ifile_].Get(histVec[ihisto_]) #status_ = type(histo) is TGraphAsymmErrors histList.append(histo) # for ratio plot as they should nt be normalize histList1.append(histo) #print histList[ii].Integral() #histList[ii].Rebin(xRange[2]) #histList[ii].Scale(1.0/histList[ii].Integral()) maximum.append(histList[ii].GetMaximum()) maximum.sort() ii = ii + 1 print histList for ih in range(len(histList)): tt = type(histList[ih]) if logstatus[1] is 1: histList[ih].SetMaximum(100) #1.4 for log histList[ih].SetMinimum(0.00001) #1.4 for log if logstatus[1] is 0: histList[ih].SetMaximum(1.4) #1.4 for log histList[ih].SetMinimum(0.001) #1.4 for log # print "graph_status =" ,(tt is TGraphAsymmErrors) # print "hist status =", (tt is TH1D) or (tt is TH1F) if ih == 0: if tt is TGraphAsymmErrors: histList[ih].Draw("APL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("hist") if ih > 0: #histList[ih].SetLineWidth(2) if tt is TGraphAsymmErrors: histList[ih].Draw("PL same") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].Draw("hist same") if tt is TGraphAsymmErrors: histList[ih].SetMaximum(10) histList[ih].SetMarkerColor(colors[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetMarkerStyle(markerStyle[ih]) histList[ih].SetMarkerSize(1) leg.AddEntry(histList[ih], legendtext[ih], "PL") if (tt is TH1D) or (tt is TH1F) or (tt is TH1) or (tt is TH1I): histList[ih].SetLineStyle(linestyle[ih]) histList[ih].SetLineColor(colors[ih]) histList[ih].SetLineWidth(3) leg.AddEntry(histList[ih], legendtext[ih], "L") histList[ih].GetYaxis().SetTitle(titleVec[1]) histList[ih].GetYaxis().SetTitleSize(0.052) histList[ih].GetYaxis().SetTitleOffset(1.08) histList[ih].GetYaxis().SetLabelSize(.052) histList[ih].GetXaxis().SetRangeUser(xRange[0], xRange[1]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitle(titleVec[0]) histList[ih].GetXaxis().SetLabelSize(0.052) histList[ih].GetXaxis().SetTitleSize(0.052) histList[ih].GetXaxis().SetTitleOffset(1.14) #histList[ih].GetXaxis().SetTickLength(0.07) histList[ih].GetXaxis().SetNdivisions(508) from PlotTemplates import SetCMSAxis histList[ih] = SetCMSAxis(histList[ih], 1.0, 1.15) #histList[ih].GetXaxis().SetMoreLogLabels(); #histList[ih].GetXaxis().SetNoExponent(); #histList[ih].GetTGaxis().SetMaxDigits(3); i = i + 1 ''' pt = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(22) pt.SetTextSize(0.046) text = pt.AddText(0.2,0.5,"CMS Internal") ''' from PlotTemplates import drawenergy1D pt_ = drawenergy1D(False) for ipt in pt_: ipt.Draw() ''' if len(text_) >0: ltx = TLatex() ltx.SetTextFont(42) ltx.SetTextSize(0.049) #text_f = "#font[42]{Phase Scan}" ltx.DrawTextNDC(x_,y_,text_) ''' from PlotTemplates import ExtraText text_ex = ExtraText(text_, x_, y_) text_ex.Draw() ExtraText("ECAL Endcaps", 0.4, 0.85) ltx_ = TLatex() ltx_.SetTextFont(42) ltx_.SetTextSize(0.049) ltx_.DrawLatexNDC(0.32, 0.81, "L1 e-#gamma object p_{T} > 10 GeV") #text_ex.Draw() #pt = TPaveText(0.0877181,0.9,0.9580537,0.96,"brNDC") #text = pt.AddText(0.65,0.5,"Phase Scan data #sqrt{s} = 13 TeV (2018)") #pt.Draw() # t2a = TPaveText(0.0877181,0.81,0.9580537,0.89,"brNDC") # t2a.SetBorderSize(0) # t2a.SetFillStyle(0) # t2a.SetTextSize(0.040) # t2a.SetTextAlign(12) # t2a.SetTextFont(62) # histolabel1= str(fileVec[(len(fileVec)-1)]) # text1 = t2a.AddText(0.06,0.5,"CMS Internal") # t2a.Draw() leg.SetHeader("Matched TP energy") leg.Draw() # # c.cd() outputdirname = './' histname = outputdirname + pngname c.SaveAs(histname + '.png') c.SaveAs(histname + '.pdf')
def cebefo_style(): #TStyle *gStyle = new TStyle("gStyle","gStyle"); gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetLineWidth(2) gStyle.SetFuncWidth(2) gStyle.SetHistLineWidth(3) gStyle.SetMarkerStyle(1) gStyle.SetTextSize(0.065) gStyle.SetOptFit(1111) # axis gStyle.SetTitleSize(.05, "X") #.055 gStyle.SetTitleOffset(1.1, "X") #1.2,0.9 #gStyle.SetLabelOffset(0.003,"X"); gStyle.SetLabelSize(.05, "X") #gStyle.SetLabelFont(42,"X"); gStyle.SetTitleSize(.05, "Y") #.055 gStyle.SetTitleOffset(1.5, "Y") #gStyle.SetLabelOffset(0.008,"Y"); gStyle.SetLabelSize(.05, "Y") #gStyle.SetLabelFont(42,"Y"); gStyle.SetTitleSize(.05, "Z") gStyle.SetTitleOffset(1.8, "Z") #gStyle.SetLabelOffset(0.008,"Z"); gStyle.SetLabelSize(0.05, "Z") #gStyle.SetLabelFont(42,"Z"); rt.TGaxis.SetMaxDigits(4) # Legend # gStyle.SetLegendTextSize(0.04); #gStyle.SetStatFontSize(0.2); #histograms properties gStyle.SetOptStat(112210) #gStyle.SetStripDecimals(False) #gStyle.SetLineStyleString(11,"20 10") # canvas #gStyle.SetCanvasColor(0); #gStyle.SetCanvasBorderSize(10); #gStyle.SetCanvasBorderMode(0); #gStyle.SetCanvasDefW(600); #gStyle.SetCanvasDefH(600); # pads # gStyle.SetPadColor(0); # gStyle.SetPadBorderSize(10); # gStyle.SetPadBorderMode(0); gStyle.SetPadLeftMargin(.14) gStyle.SetPadRightMargin(.02) gStyle.SetPadBottomMargin(.12) gStyle.SetPadTopMargin(.05) gStyle.SetPadGridX(1) gStyle.SetPadGridY(1)