CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
drawHistoAllChambers.py
Go to the documentation of this file.
1 import ROOT
2 
3 def drawHisto(histo,title,ymin,ymax,option="HISTOP",draw=True):
4  histo.SetStats(0)
5  histo.SetLineWidth(3)
6  histo.SetMarkerStyle(20)
7  histo.SetMarkerSize(0.9)
8  histo.GetYaxis().SetRangeUser(ymin,ymax)
9  histo.GetYaxis().SetTitle(title)
10  histo.GetXaxis().SetLabelSize(0.04)
11  histo.GetXaxis().SetTickLength(0.)
12  histo.LabelsOption("d","X")
13 
14  fillColor = 0
15  canvas = None
16  if draw:
17  canvas = ROOT.TCanvas("c_" + histo.GetName())
18  canvas.SetGridy()
19  canvas.SetFillColor(fillColor)
20  if draw: histo.Draw(option)
21 
22  linesWh = {}
23  linesSt = {}
24  labels = {}
25  for idx_st in range(1,5):
26  nSectors = 12
27  if idx_st == 4: nSectors = 14
28  for idx_wh in range(-1,3):
29  xline = (idx_st - 1)*60 + (idx_wh + 2)*nSectors
30  if xline >= histo.GetNbinsX(): continue
31 
32  linesWh[(idx_st,idx_wh)] = ROOT.TLine(xline,ymin,xline,ymax)
33  linesWh[(idx_st,idx_wh)].SetLineStyle(2)
34  if draw: linesWh[(idx_st,idx_wh)].Draw("SAME")
35 
36  for idx in range(1,4):
37  xline = idx*60
38  if xline >= histo.GetNbinsX(): continue
39 
40  linesSt[idx] = ROOT.TLine(xline,ymin,xline,ymax)
41  linesSt[idx].SetLineStyle(2)
42  linesSt[idx].SetLineWidth(2)
43  if draw: linesSt[idx].Draw("SAME")
44 
45  for idx in range(1,5):
46  xlabel = (idx - 1)*60 + 20
47  ylabel = ymin + 0.75*(ymax -ymin)
48  if xlabel >= histo.GetNbinsX(): continue
49 
50  strSt = "MB%d" % idx
51  labels[idx] = ROOT.TPaveLabel(xlabel,ylabel,(xlabel+20),(ylabel + 0.10*(ymax -ymin)),strSt)
52  labels[idx].SetTextSize(0.5)
53  labels[idx].SetFillColor(fillColor)
54  if draw: labels[idx].Draw("SAME")
55 
56  objects = []
57  objects.append(linesWh)
58  objects.append(linesSt)
59  objects.append(labels)
60 
61  return (canvas,histo,objects)