# # Blatt 9 Aufgabe 9.2 # # Test zentraler Grenzwertsatz der Statistik # sum uniformly distributed random numbers # and histogramm them. # # To be used with pyRoot # import ROOT import math # number of events nEvent = 50000 # Create a new canvas, and customize it. c1 = ROOT.TCanvas( 'c1', 'Zentraler Grenzwertsatz', 200, 10, 700, 500 ) c1.Divide(2,3) # Initialize random number generator R = ROOT.TRandom3() # R.SetSeed(7892344) # fixed seed for testing R.SetSeed() # set seed to machine clock # Create Histogramms x1 = ROOT.TH1D( 'x1', 'n=1', 500, 0., 10) x2 = ROOT.TH1D( 'x2', 'n=2', 500, 0., 10) x3 = ROOT.TH1D( 'x3', 'n=3', 500, 0., 10) x6 = ROOT.TH1D( 'x6', 'n=6', 500, 0., 10) x8 = ROOT.TH1D( 'x6', 'n=8', 500, 0., 10) x10 = ROOT.TH1D( 'x6', 'n10',500, 0., 10) # Event loop for i in range(nEvent) : # random numbers between 0 and 1 # Filling histogramm with sums of uniformly distributed random numbers # The sums are with the increasing numbers of random variables more # and more gaussian n1 = R.Uniform(0.,1) x1.Fill(n1) n2 = R.Uniform(0.,1) x2.Fill(n1+n2) n3 = R.Uniform(0.,1) x3.Fill(n1+n2+n3) n4 = R.Uniform(0.,1) n5 = R.Uniform(0.,1) n6 = R.Uniform(0.,1) x6.Fill(n1+n2+n3+n4+n5+n6) n7 = R.Uniform(0.,1) n8 = R.Uniform(0.,1) x8.Fill(n1+n2+n3+n4+n5+n6+n7+n8) n9 = R.Uniform(0.,1) n10 = R.Uniform(0.,1) x10.Fill(n1+n2+n3+n4+n5+n6+n7+n8+n9+n10) # Draw histogramms and fit gaussian distributions c1.cd(1) x1.Draw() c1.cd(2) x2.Draw() x2.Fit('gaus') c1.cd(3) x3.Draw() x3.Fit('gaus') c1.cd(4) x6.Draw() x6.Fit('gaus') c1.cd(5) x8.Draw() x8.Fit('gaus') c1.cd(6) x10.Draw() x10.Fit('gaus') c1.Draw() c1.Modified() c1.Update()