11 def __init__( self, name = "HistControl", title = "Controls the histograms", doOutputFile=False):
14 ROOT.TNamed.__init__( self, name, title )
16 self.SetTitle( title )
30 print 'already stored a tprofile object with name', name
32 tprof = ROOT.TProfile(name, title, numbinx, xmin, xmax)
39 print 'already stored a th1f object with name', name
41 hist1d = ROOT.TH1F(name, title, numbinx, xmin, xmax)
46 def BookHist2D(self, name, title, numbinx, xmin, xmax, numbiny, ymin, ymax):
48 print 'already stored a th2f object with name', name
50 hist2d = ROOT.TH2F(name, title, numbinx, xmin, xmax, numbiny, ymin, ymax)
58 str =
''.
join(random.choice(string.ascii_uppercase + string.digits)
for x
in range(N))
59 print 'randomstring', str
63 colors = [ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta],
67 if isinstance(histname, list):
69 for (index,hname)
in enumerate(histname):
74 for (index,hname)
in enumerate(histname):
77 for (index,hname)
in enumerate(histname):
79 if index >= len(colors):
80 print 'add more colors'
83 self.
__OneDHists[ hname ].SetLineColor(colors[index])
96 canvas.SaveAs(
'output/'+imagename+
'.png')
99 def SaveTH2FToImage(self, histname, imagename, doth2f2graph=False, minY=1., maxY=-1.):
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'
117 if hist_frame
is not None:
119 graph.SetLineWidth(3)
120 graph_err.Draw(
'3SAME')
130 canvas.SaveAs(
'output/'+imagename+
'.png')
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)
168 print 'No such TH2F as', 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)
218 print 'No such th1f with name', name
226 print 'No such th2f with name', name
234 print 'No such tprofile with name', name
241 print 'Cannot save hists to file. No output file set.'
244 outputFile = ROOT.TFile(self.GetName()+
'.root',
'RECREATE')
246 if hist1D.GetEntries() != 0:
249 if hist2D.GetEntries() != 0: