CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pyrootRender.py
Go to the documentation of this file.
1 import sys
2 import ROOT
3 from ROOT import TCanvas,TH1F,gROOT,TFile,gStyle,gDirectory,TDatime,TLegend
4 
5 batchonly=False
6 try:
7  import Tkinter as Tk
8  root=Tk.Tk()
9 except ImportError:
10  print 'unable to import GUI backend, switch to batch only mode'
11  batchonly=True
12 
13 def destroy(e) :
14  sys.exit()
15 
16 class interactiveRender(Tk.Frame):
17  def __init__(self):
18  Tk.Frame.__init__(self,master=root)
19  ROOT.gStyle.SetOptStat(0)
20  ROOT.gROOT.SetBatch(ROOT.kFALSE)
21  self.__canvas=TCanvas("Luminosity","",1)
22  self.__canvas.SetHighLightColor(2);
23  self.__canvas.Range(-125.6732,-0.1364721,1123.878,1.178117)
24  self.__canvas.SetFillColor(0)
25  self.__canvas.SetBorderMode(0)
26  self.__canvas.SetBorderSize(2)
27  self.__canvas.SetGridx()
28  self.__canvas.SetGridy()
29  self.__canvas.SetFrameFillColor(19)
30  self.__canvas.SetFrameBorderMode(0)
31  self.__canvas.SetFrameBorderMode(0)
32  def draw(self,rootobj):
33  rootobj.Draw()
34  self.pack()
35  button=Tk.Button(master=root,text='Quit',command=sys.exit)
36  button.pack(side=Tk.BOTTOM)
37  Tk.mainloop()
38 class batchRender():
39  def __init__(self,outputfilename):
40  ROOT.gStyle.SetOptStat(0)
41  ROOT.gROOT.SetBatch(ROOT.kTRUE)
42  self.__canvas=TCanvas("Luminosity","",1)
43  self.__canvas.SetHighLightColor(2);
44  self.__canvas.Range(-125.6732,-0.1364721,1123.878,1.178117)
45  self.__canvas.SetFillColor(0)
46  self.__canvas.SetBorderMode(0)
47  self.__canvas.SetBorderSize(2)
48  self.__canvas.SetGridx()
49  self.__canvas.SetGridy()
50  self.__canvas.SetFrameFillColor(19)
51  self.__canvas.SetFrameBorderMode(0)
52  self.__canvas.SetFrameBorderMode(0)
53  self.__outfile=outputfilename
54  def draw(self,rootobj):
55  rootobj.Draw()
56  self.__canvas.Modified()
57  self.__canvas.cd()
58  self.__canvas.SetSelected(rootobj)
59  self.__canvas.SaveAs(self.__outfile)
60 if __name__=='__main__':
61 
62  da = TDatime(2010,3,30,13,10,00)
63  h1f = TH1F("Luminposity","",1000,0.,1000)
64  h1f.GetXaxis().SetNdivisions(-503)
65  h1f.GetXaxis().SetTimeDisplay(1)
66  h1f.GetXaxis().SetTimeFormat("%d\/%m %H:%M")
67  h1f.GetXaxis().SetTimeOffset(da.Convert())
68  h1f.GetXaxis().SetLabelFont(32);
69  h1f.GetXaxis().SetLabelSize(0.03);
70  h1f.GetXaxis().SetTitleFont(32);
71  h1f.GetXaxis().SetTitle("Date");
72 
73  h1f.GetYaxis().SetLabelFont(32);
74  h1f.GetYaxis().SetLabelSize(0.03);
75  h1f.GetYaxis().SetTitleFont(32);
76  h1f.GetYaxis().SetTitle("L (#mub^{-1})");
77 
78  for i in range(0,1000):
79  #h1f.GetXaxis().FindBin() ## Ricordati di calcolare il bin corretto per il tuo tempo
80  h1f.SetBinContent(i,20.2+i)
81 
82  #m=interactiveRender()
83  #m.draw(h1f)
84  bat=batchRender('testroot.jpg')
85  bat.draw(h1f)