2 from optparse
import OptionParser
6 usage = "usage: %prog[options]" 7 parser = OptionParser(usage=usage) 9 parser.add_option("-f","--filename",dest="filename",help="filename for histogram creation",default="NA") 11 (options,args)=parser.parse_args() 12 pathname =options.filename 16 import os, sys, shutil
19 print " drawUncertainties.py <filename1> [filename2]" 21 pathname =
str(sys.argv[1])
24 pathname1 =
str(sys.argv[2])
29 for num
in range(0,121):
30 newbins.append(num*1.0)
32 n_universes = len(universes)
33 avg_hist = universes[0].Clone(universes[0].GetName()+
"_avg")
34 for i
in range(0,avg_hist.GetNbinsX()+1):
35 avg_hist.SetBinContent(i,0.0)
36 avg_hist.SetBinError(i,0.0)
37 avg_hist.Scale(1,
"width")
38 error_hist = universes[0].Clone(universes[0].GetName()+
"_error")
39 for i
in range(0,error_hist.GetNbinsX()+1):
40 error_hist.SetBinContent(i,0.0)
41 error_hist.SetBinError(i,0.0)
42 for i
in range(n_universes):
44 universes[i].
Scale(1,
"width")
45 avg_hist.Add(universes[i])
46 avg_hist.Scale(1/float(n_universes))
49 for j
in range(error_hist.GetNbinsX()+2):
51 for i
in range(n_universes):
52 error += 1/float(n_universes)*ROOT.TMath.Power(universes[i].GetBinContent(j)-avg_hist.GetBinContent(j),2)
53 error_hist.SetBinContent(j,ROOT.TMath.Sqrt(error))
55 error_hist.Divide(avg_hist)
60 n_universes=len(universes)
61 avg_hist=universes[0].Clone(universes[0].GetName()+
"_avg")
62 for i
in range(n_universes):
63 avg_hist.Add(universes[i])
64 avg_hist.Scale(1/float(n_universes))
68 def PrintPlots(rootfile,in_dir,in_files,universes,frac,urange):
70 for i
in range(universes):
71 histo_universes.append(rootfile.Get(in_dir+
"/"+in_files+
"_"+
str(i)))
73 c1 = ROOT.TCanvas(
"c1",
"c1",750,750)
74 error_universes.SetLineWidth(3)
75 if "htotal" in error_universes.GetName():
76 print error_universes.GetName()[:-8],
type(error_universes)
78 (error_universes.GetXaxis()).SetRangeUser(0,20)
79 error_universes.Draw(
"hist")
80 c1.Print(
str(in_files)+
".pdf")
82 error_universes.Draw(
"hist")
83 c1.Print(
str(in_files)+
".pdf")
89 for i
in range(universes):
90 histo_universes.append(rootfile.Get(in_dir+
"/"+in_file+
"_"+
str(i)))
91 c1 = ROOT.TCanvas(
"c1",
"c1",750,750)
93 (histo_universes[0].GetXaxis()).SetRangeUser(0,20)
94 maxm= histo_universes[0].GetMaximum()
95 histo_universes[0].SetMaximum(maxm+0.1*maxm)
96 histo_universes[0].Draw(
"hist")
97 for i
in range(0,universes):
98 histo_universes[i].Draw(
"same")
106 newbins=array.array(
'd',[])
108 for num
in range(0,17):
109 newbins.append(num*0.5)
111 for num
in range(5,11):
112 newbins.append(num*2)
115 for num
in range(0,41):
116 newbins.append(num*1.0)
119 for hist
in input_histos:
120 temphistname=hist.GetName()+
"_rebinned" 121 temphist=hist.Rebin(counter-1,temphistname,newbins)
123 output_histos.append(temphist)
128 directory=[
"total",
"others",
"targetpcpi",
"targetpck",
"targetncpi",
129 "targetpcnu",
"targetmesonInc",
"targetnuA",
"totabsorption",
"tgtabsorption"]
130 files=[
"htotal",
"hothers",
"htargetpcpi",
"htargetpcK",
"htargetncpi",
131 "htargetpcnu",
"htargetmesonInc",
"htargetnucleonA",
"habsorption",
"htargetabsorption"]
132 legends=[
"Total HP",
"others",
"pC-->#pi X",
"pC-->KX",
"nC-->#pi X",
"pC-->nucleonX",
"meson inc.",
"nucloen-A",
133 "other abs.",
"Target Absorption"]
134 color=[38,38,4,4,46,46,43,43,3,3]
136 style=[0,1,1,2,1,2,1,2,1,2,1]
137 for j
in range(len(directory)):
139 in_dir=nutype+
"_"+directory[j]
140 in_files=files[j]+
"_"+nutype
141 print in_dir+
"/"+in_files
142 for i
in range(universes):
143 histo_universes.append(rootfile.Get(
str(in_dir)+
"/"+
str(in_files)+
"_"+
str(i)))
146 errhists.append(error_universes)
150 c1 = ROOT.TCanvas(
"c1",
"c1",750,750)
151 leg = ROOT.TLegend(0.3,0.5,0.5,0.9)
153 errhists[0].SetLineColor(1)
154 errhists[0].SetLineWidth(3)
155 errhists[0].SetMinimum(0)
156 (errhists[0].GetXaxis()).SetRangeUser(0,20)
157 leg.AddEntry(errhists[0],
str(legends[0]),
"lp")
158 errhists[0].SetMaximum(0.20)
159 errhists[0].SetMinimum(0)
160 errhists[0].Draw(
"hist")
162 for i
in range(1,len(errhists)):
163 errhists[i].SetLineColor(color[i])
164 errhists[i].SetLineStyle(style[i])
165 errhists[i].SetLineWidth(3)
166 errhists[i].Draw(
"histsame")
167 leg.AddEntry(errhists[i],
str(legends[i]),
"lp")
176 print "need at least two files to print stack plots...." 180 for i
in range(universes):
181 histo1_universes.append(rfile1.Get(in_dir+
"/"+in_files+
"_"+
str(i)))
182 histo2_universes.append(rfile2.Get(in_dir+
"/"+in_files+
"_"+
str(i)))
185 error_universes1.SetLineColor(1)
186 error_universes2.SetLineColor(2)
187 error_universes1.SetLineWidth(3)
188 error_universes2.SetLineWidth(3)
190 (error_universes1.GetXaxis()).SetRangeUser(0,20)
191 (error_universes2.GetXaxis()).SetRangeUser(0,20)
193 max1 = error_universes1.GetMaximum()
194 max2 = error_universes2.GetMaximum()
196 c1 = ROOT.TCanvas(
"c1",
"c1",750,750)
198 error_universes1.SetMinimum(0)
199 error_universes1.Draw(
"hist")
200 error_universes2.Draw(
"histSame")
202 error_universes2.SetMinimum(0)
203 error_universes2.Draw(
"hist")
204 error_universes1.Draw(
"histSame")
205 leg1 = ROOT.TLegend(0.5,0.7,0.7,0.9)
207 leg1.AddEntry(error_universes1,
"FTFP",
"lp")
208 leg1.AddEntry(error_universes2,
"QGSP",
"lp")
211 newpath=current+
"/comp_plots" 212 if not os.path.exists(newpath):
214 c1.Print(
str(newpath)+
"/"+
str(in_files)+
"_comp.pdf")
220 def PrintRatioErrorPlots(rfile1,rfile2,in_dir,in_files,universes,frac,urange,RPlots=False,rebin=True,uniform=True):
222 print "need at least 2 files to compare the ratio error plots...exiting " 224 print "Ratio and Error info for "+rfile1.GetName()+
" / "+rfile2.GetName()
229 for i
in range(universes):
230 histo1_universes.append(rfile1.Get(in_dir+
"/"+in_files+
"_"+
str(i)))
231 histo2_universes.append(rfile2.Get(in_dir+
"/"+in_files+
"_"+
str(i)))
233 for i
in range(universes):
234 histo1_universes[i].Divide(histo2_universes[i])
243 for i
in range(universes):
244 rebin_histo1[i].Divide(rebin_histo2[i])
249 (error_universes.GetXaxis()).SetRangeUser(0,20)
250 (ratio_universe.GetXaxis()).SetRangeUser(0,20)
251 c1 = ROOT.TCanvas(
"c1",
"c1",750,750)
252 leg1 = ROOT.TLegend(0.5,0.7,0.7,0.9)
255 ratio_universe.SetLineWidth(3)
256 ratio_universe.Draw(
"histe")
262 error_universes.SetMinimum(0)
263 error_universes.SetLineWidth(3)
264 error_universes.Draw(
"hist")
265 leg1.AddEntry(error_universes,
"Error for Far/Near ")
270 in_file = ROOT.TFile(
str(pathname))
271 rfile = ROOT.TFile(
str(pathname1))
def DrawTogether(rootfile, nutype, universes, frac, urange)
Scale(size_t pos, T factor) -> Scale< T >
def RebinHistogram(input_histos, uniform=False)
def PrintPlots(rootfile, in_dir, in_files, universes, frac, urange)
def PrintStackPlots(rfile1, rfile2, in_dir, in_files, universes, frac, urange)
def AddUniverses(universes)
def MakeErrorHistogram(universes, asFrac=True)
def PrintRatioErrorPlots(rfile1, rfile2, in_dir, in_files, universes, frac, urange, RPlots=False, rebin=True, uniform=True)
def DrawFluxTogether(rootfile, in_dir, in_file, universes)