|
def | __init__ (self, name="HistControl", title="Controls the histograms", doOutputFile=False) |
|
def | BookTProfile (self, name, title, numbinx, xmin, xmax) |
|
def | BookHist1D (self, name, title, numbinx, xmin, xmax) |
|
def | BookHist2D (self, name, title, numbinx, xmin, xmax, numbiny, ymin, ymax) |
|
def | GetRandomString (self, N) |
|
def | SaveTH1FToImage (self, histname, imagename, drawoptions='HIST', colors=[ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta], linewidth=2) |
|
def | SaveTH2FToImage (self, histname, imagename, doth2f2graph=False, minY=1., maxY=-1.) |
|
def | getRMSs (self, hist) |
|
def | TwoDHist2Graph (self, name, doErros=False) |
|
def | FillHist1D (self, name, value) |
|
def | FillHist2D (self, name, valuex, valuey) |
|
def | FillTProfile (self, name, valuex, valuey) |
|
def | SaveAllToFile (self) |
|
Definition at line 9 of file HistControl.py.
◆ __init__()
def HistControl.HistControl.__init__ |
( |
|
self, |
|
|
|
name = "HistControl" , |
|
|
|
title = "Controls the histograms" , |
|
|
|
doOutputFile = False |
|
) |
| |
Definition at line 11 of file HistControl.py.
11 def __init__( self, name = "HistControl", title = "Controls the histograms", doOutputFile=False):
14 ROOT.TNamed.__init__( self, name, title )
16 self.SetTitle( title )
22 self.__OutputROOTFile =
None
24 self.__doOutputFile = doOutputFile
◆ BookHist1D()
def HistControl.HistControl.BookHist1D |
( |
|
self, |
|
|
|
name, |
|
|
|
title, |
|
|
|
numbinx, |
|
|
|
xmin, |
|
|
|
xmax |
|
) |
| |
Definition at line 36 of file HistControl.py.
36 def BookHist1D(self, name, title, numbinx, xmin, xmax):
38 if name
in self.__OneDHists.
keys():
39 print 'already stored a th1f object with name', name
41 hist1d = ROOT.TH1F(name, title, numbinx, xmin, xmax)
42 self.__OneDHists[ name ] = hist1d
◆ BookHist2D()
def HistControl.HistControl.BookHist2D |
( |
|
self, |
|
|
|
name, |
|
|
|
title, |
|
|
|
numbinx, |
|
|
|
xmin, |
|
|
|
xmax, |
|
|
|
numbiny, |
|
|
|
ymin, |
|
|
|
ymax |
|
) |
| |
Definition at line 46 of file HistControl.py.
46 def BookHist2D(self, name, title, numbinx, xmin, xmax, numbiny, ymin, ymax):
47 if name
in self.__TwoDHists.
keys():
48 print 'already stored a th2f object with name', name
50 hist2d = ROOT.TH2F(name, title, numbinx, xmin, xmax, numbiny, ymin, ymax)
51 self.__TwoDHists[ name ] = hist2d
◆ BookTProfile()
def HistControl.HistControl.BookTProfile |
( |
|
self, |
|
|
|
name, |
|
|
|
title, |
|
|
|
numbinx, |
|
|
|
xmin, |
|
|
|
xmax |
|
) |
| |
Definition at line 28 of file HistControl.py.
28 def BookTProfile(self, name, title, numbinx, xmin, xmax):
29 if name
in self.__TProfiles.
keys():
30 print 'already stored a tprofile object with name', name
32 tprof = ROOT.TProfile(name, title, numbinx, xmin, xmax)
33 self.__TProfiles[ name ] = tprof
◆ FillHist1D()
def HistControl.HistControl.FillHist1D |
( |
|
self, |
|
|
|
name, |
|
|
|
value |
|
) |
| |
Definition at line 214 of file HistControl.py.
214 def FillHist1D(self, name, value):
215 if name
in self.__OneDHists:
216 self.__OneDHists[ name ].Fill(value)
218 print 'No such th1f with name', name
◆ FillHist2D()
def HistControl.HistControl.FillHist2D |
( |
|
self, |
|
|
|
name, |
|
|
|
valuex, |
|
|
|
valuey |
|
) |
| |
Definition at line 222 of file HistControl.py.
222 def FillHist2D(self, name, valuex, valuey):
223 if name
in self.__TwoDHists:
224 self.__TwoDHists[ name ].Fill(valuex, valuey)
226 print 'No such th2f with name', name
◆ FillTProfile()
def HistControl.HistControl.FillTProfile |
( |
|
self, |
|
|
|
name, |
|
|
|
valuex, |
|
|
|
valuey |
|
) |
| |
Definition at line 230 of file HistControl.py.
230 def FillTProfile(self, name, valuex, valuey):
231 if name
in self.__TProfiles:
232 self.__TProfiles[ name ].Fill(valuex, valuey)
234 print 'No such tprofile with name', name
◆ GetRandomString()
def HistControl.HistControl.GetRandomString |
( |
|
self, |
|
|
|
N |
|
) |
| |
Definition at line 57 of file HistControl.py.
57 def GetRandomString(self, N):
58 str =
''.
join(random.choice(string.ascii_uppercase + string.digits)
for x
in range(N))
59 print 'randomstring', str
◆ getRMSs()
def HistControl.HistControl.getRMSs |
( |
|
self, |
|
|
|
hist |
|
) |
| |
Definition at line 134 of file HistControl.py.
134 def getRMSs(self, hist):
136 mean = hist.GetMean()
137 nentries = hist.GetEntries()
143 for bin
in range(1, hist.GetNbinsX()+1):
144 if hist.GetBinCenter(bin) < mean:
145 print 'low', hist.GetBinContent(bin)
146 nDown = nDown + hist.GetBinContent(bin)
147 rmsDown +=
float(hist.GetBinContent(bin))*(mean -
float(hist.GetBinCenter(bin)))**2
149 nUp = nUp + hist.GetBinContent(bin)
150 rmsUp +=
float(hist.GetBinContent(bin))*(mean -
float(hist.GetBinCenter(bin)))**2
154 rmsDown = ROOT.TMath.Sqrt(rmsDown/
float(nentries))
159 rmsUp = ROOT.TMath.Sqrt(rmsUp/
float(nentries))
163 return (rmsDown,rmsUp)
◆ SaveAllToFile()
def HistControl.HistControl.SaveAllToFile |
( |
|
self | ) |
|
Definition at line 239 of file HistControl.py.
239 def SaveAllToFile(self):
240 if not self.__doOutputFile:
241 print 'Cannot save hists to file. No output file set.'
244 outputFile = ROOT.TFile(self.GetName()+
'.root',
'RECREATE')
245 for name1D, hist1D
in self.__OneDHists.
iteritems():
246 if hist1D.GetEntries() != 0:
248 for name2D, hist2D
in self.__TwoDHists.
iteritems():
249 if hist2D.GetEntries() != 0:
251 for nametprof, histtprof
in self.__TProfiles.
iteritems():
◆ SaveTH1FToImage()
def HistControl.HistControl.SaveTH1FToImage |
( |
|
self, |
|
|
|
histname, |
|
|
|
imagename, |
|
|
|
drawoptions = 'HIST' , |
|
|
|
colors = [ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta] , |
|
|
|
linewidth = 2 |
|
) |
| |
Definition at line 62 of file HistControl.py.
62 def SaveTH1FToImage(self, histname, imagename, drawoptions = 'HIST',
63 colors = [ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta],
65 canvas = ROOT.TCanvas(
'canvas'+self.GetRandomString(6))
67 if isinstance(histname, list):
69 for (index,hname)
in enumerate(histname):
70 if self.__OneDHists[ hname ].GetMaximum() > maxy:
71 maxy = self.__OneDHists[ hname ].GetMaximum()
74 for (index,hname)
in enumerate(histname):
75 self.__OneDHists[ hname ].SetMaximum(maxy*1.2)
77 for (index,hname)
in enumerate(histname):
78 self.__OneDHists[ hname ].SetLineWidth(linewidth)
79 if index >= len(colors):
80 print 'add more colors'
83 self.__OneDHists[ hname ].SetLineColor(colors[index])
85 self.__OneDHists[ hname ].Draw(drawoptions)
87 self.__OneDHists[ hname ].Draw(drawoptions+
'SAME')
92 self.__OneDHists[ hname ].SetLineWidth(linewidth)
93 self.__OneDHists[ hname ].SetLineColor(colors[0])
94 self.__OneDHists[ hname ].Draw(drawoptions)
96 canvas.SaveAs(
'output/'+imagename+
'.png')
◆ SaveTH2FToImage()
def HistControl.HistControl.SaveTH2FToImage |
( |
|
self, |
|
|
|
histname, |
|
|
|
imagename, |
|
|
|
doth2f2graph = False , |
|
|
|
minY = 1. , |
|
|
|
maxY = -1. |
|
) |
| |
Definition at line 99 of file HistControl.py.
99 def SaveTH2FToImage(self, histname, imagename, doth2f2graph=False, minY=1., maxY=-1.):
100 canvas = ROOT.TCanvas(
'canvas'+self.GetRandomString(6))
103 if (minY<maxY)
and doth2f2graph:
104 hist_frame = ROOT.TH1F(
'hist_frame', self.__TwoDHists[ histname ].GetTitle(),
105 100, self.__TwoDHists[ histname ].GetXaxis().GetXmin(), self.__TwoDHists[ histname ].GetXaxis().GetXmax())
106 hist_frame.SetXTitle( self.__TwoDHists[ histname ].GetXaxis().GetTitle() )
107 hist_frame.SetYTitle( self.__TwoDHists[ histname ].GetYaxis().GetTitle() )
108 hist_frame.SetMinimum(minY)
109 hist_frame.SetMaximum(maxY)
110 if isinstance(histname, list):
111 print 'still need to figure this out'
115 graph_err = self.TwoDHist2Graph(histname, doErros=
True)
116 graph = self.TwoDHist2Graph(histname, doErros=
False)
117 if hist_frame
is not None:
119 graph.SetLineWidth(3)
120 graph_err.Draw(
'3SAME')
127 self.__TwoDHists[ histname ].Draw()
130 canvas.SaveAs(
'output/'+imagename+
'.png')
◆ TwoDHist2Graph()
def HistControl.HistControl.TwoDHist2Graph |
( |
|
self, |
|
|
|
name, |
|
|
|
doErros = False |
|
) |
| |
Definition at line 166 of file HistControl.py.
166 def TwoDHist2Graph(self, name, doErros=False):
167 if not name
in self.__TwoDHists.
keys():
168 print 'No such TH2F as', name
171 hist = self.__TwoDHists[ name ]
180 for bin
in range(1, hist.GetNbinsX()+1 ):
181 hist_projY = hist.ProjectionY(
'pY'+
str(bin), bin, bin)
182 if hist_projY.GetEntries() != 0:
183 mean = hist_projY.GetMean()
184 list_mean.append( mean )
185 list_x.append( hist.GetXaxis().GetBinCenter(bin) )
189 (yel,yeh) = self.getRMSs(hist_projY)
199 array_mean = array.array(
'd', list_mean)
200 array_x = array.array(
'd', list_x)
201 array_xel = array.array(
'd', list_xel)
202 array_yel = array.array(
'd', list_yel)
203 array_xeh = array.array(
'd', list_xeh)
204 array_yeh = array.array(
'd', list_yeh)
207 graph_mean = ROOT.TGraphAsymmErrors(len(list_mean), array_x, array_mean, array_xel,array_xeh,array_yel,array_yeh)
208 graph_mean.SetFillColor(ROOT.kRed)
210 graph_mean = ROOT.TGraph(len(list_mean), array_x, array_mean)
◆ __doOutputFile
HistControl.HistControl.__doOutputFile |
|
private |
◆ __Graphs
HistControl.HistControl.__Graphs |
|
private |
◆ __OneDHists
HistControl.HistControl.__OneDHists |
|
private |
◆ __OutputROOTFile
HistControl.HistControl.__OutputROOTFile |
|
private |
◆ __TProfiles
HistControl.HistControl.__TProfiles |
|
private |
◆ __TwoDHists
HistControl.HistControl.__TwoDHists |
|
private |
The documentation for this class was generated from the following file: