CMS 3D CMS Logo

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