CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoLuminosity/LumiDB/python/pyrootRender.py

Go to the documentation of this file.
00001 import sys
00002 import ROOT
00003 from ROOT import TCanvas,TH1F,gROOT,TFile,gStyle,gDirectory,TDatime,TLegend
00004 
00005 batchonly=False
00006 try:
00007     import Tkinter as Tk
00008     root=Tk.Tk()
00009 except ImportError:
00010     print 'unable to import GUI backend, switch to batch only mode'
00011     batchonly=True
00012 
00013 def destroy(e) :
00014     sys.exit()
00015         
00016 class interactiveRender(Tk.Frame):
00017     def __init__(self):
00018         Tk.Frame.__init__(self,master=root)
00019         ROOT.gStyle.SetOptStat(0)
00020         ROOT.gROOT.SetBatch(ROOT.kFALSE)
00021         self.__canvas=TCanvas("Luminosity","",1)
00022         self.__canvas.SetHighLightColor(2);
00023         self.__canvas.Range(-125.6732,-0.1364721,1123.878,1.178117)
00024         self.__canvas.SetFillColor(0)
00025         self.__canvas.SetBorderMode(0)
00026         self.__canvas.SetBorderSize(2)
00027         self.__canvas.SetGridx()
00028         self.__canvas.SetGridy()
00029         self.__canvas.SetFrameFillColor(19)
00030         self.__canvas.SetFrameBorderMode(0)
00031         self.__canvas.SetFrameBorderMode(0)
00032     def draw(self,rootobj):
00033         rootobj.Draw()
00034         self.pack()
00035         button=Tk.Button(master=root,text='Quit',command=sys.exit)
00036         button.pack(side=Tk.BOTTOM)
00037         Tk.mainloop()
00038 class batchRender():
00039     def __init__(self,outputfilename):
00040         ROOT.gStyle.SetOptStat(0)
00041         ROOT.gROOT.SetBatch(ROOT.kTRUE)
00042         self.__canvas=TCanvas("Luminosity","",1)
00043         self.__canvas.SetHighLightColor(2);
00044         self.__canvas.Range(-125.6732,-0.1364721,1123.878,1.178117)
00045         self.__canvas.SetFillColor(0)
00046         self.__canvas.SetBorderMode(0)
00047         self.__canvas.SetBorderSize(2)
00048         self.__canvas.SetGridx()
00049         self.__canvas.SetGridy()
00050         self.__canvas.SetFrameFillColor(19)
00051         self.__canvas.SetFrameBorderMode(0)
00052         self.__canvas.SetFrameBorderMode(0)
00053         self.__outfile=outputfilename
00054     def draw(self,rootobj):
00055         rootobj.Draw()
00056         self.__canvas.Modified()
00057         self.__canvas.cd()
00058         self.__canvas.SetSelected(rootobj)
00059         self.__canvas.SaveAs(self.__outfile)
00060 if __name__=='__main__':
00061       
00062     da = TDatime(2010,03,30,13,10,00)
00063     h1f = TH1F("Luminposity","",1000,0.,1000)
00064     h1f.GetXaxis().SetNdivisions(-503)
00065     h1f.GetXaxis().SetTimeDisplay(1)
00066     h1f.GetXaxis().SetTimeFormat("%d\/%m %H:%M")
00067     h1f.GetXaxis().SetTimeOffset(da.Convert())       
00068     h1f.GetXaxis().SetLabelFont(32);
00069     h1f.GetXaxis().SetLabelSize(0.03);
00070     h1f.GetXaxis().SetTitleFont(32);
00071     h1f.GetXaxis().SetTitle("Date");
00072         
00073     h1f.GetYaxis().SetLabelFont(32);
00074     h1f.GetYaxis().SetLabelSize(0.03);
00075     h1f.GetYaxis().SetTitleFont(32);
00076     h1f.GetYaxis().SetTitle("L (#mub^{-1})");
00077     
00078     for i in range(0,1000):
00079         #h1f.GetXaxis().FindBin() ## Ricordati di calcolare il bin corretto per il tuo tempo
00080         h1f.SetBinContent(i,20.2+i)
00081     
00082     #m=interactiveRender()
00083     #m.draw(h1f)
00084     bat=batchRender('testroot.jpg')
00085     bat.draw(h1f)