File indexing completed on 2025-05-29 03:17:17
0001 import ROOT
0002
0003 def drawHisto(histo,yaxis_title,ymin,ymax,option="HISTOP",draw=True):
0004 ROOT.gStyle.SetPadRightMargin(0.02)
0005 ROOT.gStyle.SetPadLeftMargin(0.07)
0006
0007 histo.SetStats(0)
0008 histo.SetLineWidth(3)
0009 histo.SetMarkerStyle(20)
0010 histo.SetMarkerSize(0.9)
0011 histo.GetYaxis().SetRangeUser(ymin,ymax)
0012 histo.GetYaxis().SetTitleOffset(1.)
0013 histo.GetYaxis().SetDecimals(1)
0014 histo.GetYaxis().SetMaxDigits(4)
0015 histo.GetYaxis().SetTitle(yaxis_title)
0016 histo.GetXaxis().SetLabelSize(0.04)
0017 histo.GetXaxis().SetTickLength(0.)
0018 histo.LabelsOption("d","X")
0019
0020 fillColor = 0
0021 canvas = None
0022 if draw:
0023 canvas = ROOT.TCanvas("c_" + histo.GetName(), "Default Canvas", 1000, 500)
0024 canvas.SetGridy()
0025 canvas.SetFillColor(fillColor)
0026 histo.Draw(option)
0027
0028
0029 linesWh = {}
0030 linesSt = {}
0031 labels = {}
0032 for idx_st in range(1,5):
0033 nSectors = 12
0034 if idx_st == 4: nSectors = 14
0035 for idx_wh in range(-1,3):
0036 xline = (idx_st - 1)*60 + (idx_wh + 2)*nSectors
0037 if xline >= histo.GetNbinsX(): continue
0038
0039 linesWh[(idx_st,idx_wh)] = ROOT.TLine(xline,ymin,xline,ymax)
0040 linesWh[(idx_st,idx_wh)].SetLineStyle(2)
0041 if draw: linesWh[(idx_st,idx_wh)].Draw("SAME")
0042
0043 for idx in range(1,4):
0044 xline = idx*60
0045 if xline >= histo.GetNbinsX(): continue
0046
0047 linesSt[idx] = ROOT.TLine(xline,ymin,xline,ymax)
0048 linesSt[idx].SetLineStyle(2)
0049 linesSt[idx].SetLineWidth(2)
0050 if draw: linesSt[idx].Draw("SAME")
0051
0052 for idx in range(1,5):
0053 xlabel = (idx - 1)*60 + 20
0054 ylabel = ymin + 0.75*(ymax -ymin)
0055 if xlabel >= histo.GetNbinsX(): continue
0056
0057 strSt = "MB%d" % idx
0058 labels[idx] = ROOT.TPaveLabel(xlabel,ylabel,(xlabel+20),(ylabel + 0.10*(ymax -ymin)),strSt)
0059 labels[idx].SetTextSize(0.5)
0060 labels[idx].SetFillColor(fillColor)
0061 if draw: labels[idx].Draw("SAME")
0062
0063 objects = []
0064 objects.append(linesWh)
0065 objects.append(linesSt)
0066 objects.append(labels)
0067
0068 return (canvas,histo,objects)