Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:42:21

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