CMS 3D CMS Logo

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