4 from os.path
import join
6 from HandyFuncs
import VerticalRange
8 if "PYTHONSTARTUP" in os.environ:
10 execfile(os.environ[
"PYTHONSTARTUP"])
11 elif os.path.exists(
"rootlogon.py"):
12 execfile(
"rootlogon.py")
15 hpred = TH1D(
"hpred",
"", 20, 0, 20)
16 hrand = TH1D(
"hrand",
"", 20, 0, 20)
17 hpred.GetXaxis().CenterTitle()
18 hpred.GetYaxis().CenterTitle()
20 hpred.SetLineColor(kRed)
21 hrand.SetLineColor(kBlack)
23 rand = TRandom3(27565)
25 for i
in range(0, 20):
26 val = 100*TMath.Exp(-i/10.)
28 hrand.Fill(i, rand.Poisson(val))
29 hpred.SetBinError(i+1, 0)
30 hrand.SetBinError(i+1,
sqrt(hrand.GetBinContent(i+1)))
36 c1 = TCanvas(
"c1",
"c1")
45 for i
in range(1, hmc.GetNbinsX()+1):
46 ei = hmc.GetBinContent(i)*alpha
47 oi = hdata.GetBinContent(i)
49 chi2 += (ei - oi)**2 / sigma**2
53 Ndof = hpred.GetNbinsX()
54 p = TMath.Prob(chi2, Ndof)
60 c1.Print(
"chisq1.png")
63 halt = TH1D(
"halt",
"", 20, 0, 20)
64 halt.SetLineColor(kBlack)
66 for i
in range(0, 20):
67 val = hpred.GetBinContent(i+1) + 7
69 halt.SetBinError(i+1,
sqrt(val))
71 c2 = TCanvas(
"c2",
"c2")
77 Ndof = hpred.GetNbinsX()
78 p = TMath.Prob(chi2, Ndof)
84 c2.Print(
"chisq2.png")
88 hpred2 = hpred.Clone()
90 hpred3 = hpred.Clone()
93 c3 = TCanvas(
"c3",
"c3")
100 c3.Print(
"chisq3.png")
103 print "chi2 2 =",
CalcChi2(hpred2, hrand)
104 print "chi2 0.5 =",
CalcChi2(hpred3, hrand)
107 c3.Print(
"chisq4.png")
110 hlike = TH1D(
"hlike",
";#theta;#chi^{2}", 400, 0.8, 1.2)
111 hlike.GetXaxis().CenterTitle()
112 hlike.GetYaxis().CenterTitle()
117 for bin
in range(hlike.GetNbinsX()):
118 theta = hlike.GetBinLowEdge(bin)
119 chi2 =
CalcChi2(hpred, hrand, theta)
120 hlike.SetBinContent(bin+1, chi2)
124 print bin, theta, chi2
126 c4 = TCanvas(
"c4",
"c4")
129 c4.Print(
"chisq5.png")
def CalcChi2(hmc, hdata, alpha=1.)
def VerticalRange(hists, xrange=(0, 0), ratio=False, forceOne=True, ignoreError=False, maxerr=0.25, absMax=-999, absMin=-999, buffer=0.05, verbose=0, log=False)