central_limit.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys, os
4 from os.path import join
5 from HandyFuncs import MakeGradient
6 
7 if "PYTHONSTARTUP" in os.environ:
8  if sys.argv[0]:
9  execfile(os.environ["PYTHONSTARTUP"])
10 elif os.path.exists("rootlogon.py"):
11  execfile("rootlogon.py")
12 
13 
14 #colors = [ kRed, kBlue, kGreen+2, kMagenta, kCyan ]
15 #Nexps = [ 2, 3, 4, 5, 6, , 30, 50 ]
16 Nexps = range(2, 31)
17 colors = MakeGradient( len(Nexps), (1, 0, 0), (0, 0, 1) )
18 trials = 10000
19 
20 rand = TRandom3()
21 
22 hists = {}
23 
24 
25 for nexp in Nexps:
26  hists[nexp] = TH1D("h%i"%nexp, ";Mean;", 101, 0, 1.01)
27  for t in range(trials):
28  sum = 0
29  for i in range(nexp):
30  sum += rand.Integer(2)
31  mean = float(sum) / float(nexp)
32  hists[nexp].Fill(mean)
33 
34 
35 fits = {}
36 
37 c1 = TCanvas("c1","c1")
38 
39 opt = "hist"
40 
41 gStyle.SetOptFit(False)
42 
43 for nexp, color in zip(Nexps, colors):
44  hists[nexp].SetLineColor(color)
45  hists[nexp].Fit("gaus")
46  fits[nexp] = hists[nexp].FindObject("gaus")
47  fits[nexp].SetLineColor(color)
48  hists[nexp].Draw(opt)
49  fits[nexp].Draw("same")
50 
51  #if "same" not in opt:
52  # opt += "same"
53  l1 = TLatex(0.3, 0.5, "%s"%nexp)
54  l1.SetNDC()
55  l1.SetTextColor(color)
56  l1.SetTextSize(0.07)
57  l1.Draw()
58  c1.Print("clt_%i.png"%nexp)
tree Draw("slc.nhit")
fVtxDx Fit("f")
def MakeGradient(nsteps, start, end)
Definition: HandyFuncs.py:152
correl_yv Fill(-(dy[iP-1][iC-1]), hyv->GetBinContent(iP, iC))
hmean SetLineColor(4)