diff --git a/Lectures_my/EMPP/Lecture1/mchrzasz.tex b/Lectures_my/EMPP/Lecture1/mchrzasz.tex index f58acc8..c03e7dc 100644 --- a/Lectures_my/EMPP/Lecture1/mchrzasz.tex +++ b/Lectures_my/EMPP/Lecture1/mchrzasz.tex @@ -564,6 +564,47 @@ \end{footnotesize} \end{frame} + +\begin{frame}\frametitle{Buffon needle, $\rm \color{RubineRed}{Lecture1/Heads\_tails}$ } +\begin{small} + + +$\Rrightarrow$ Lets make this toy experiment and calculate the $\pi$ number.\\ +$\hookrightarrow$ We can simulate the central position $(y)$ of an needle between $(-L, L)$ from $\mathcal{U}(-L, L)$. + + \begin{exampleblock}{Symmetry:} +Please note the symmetry of the problem, if the position of the needle would be $>L$ then we can shift the needle by any number of $L$'s. + \end{exampleblock} + +$\hookrightarrow$ New we simulate the angle $(\phi)$ with a flat distribution from $(0,\pi)$. +$\hookrightarrow$ The maximum and minimum $y$ position of the needle are: +\begin{align*} +y_{\max}=y+\vert \cos \phi \vert l\\ +y_{\min}=y-\vert \cos \phi \vert l +\end{align*} +$\hookrightarrow$ Now we check if the needle touches any of the lines: $y=L$, $y=0$ or $y=-L$. If yes we count the events. +\end{small} +\begin{center} + + +\begin{footnotesize} + + +\begin{tabular}{r c c c } +$N$ & $\hat{\pi}$ & $\hat{\pi} - \pi$ & $\sigma(\hat{\pi})$ \\ +10000 & $3.12317$ & $-0.01842$ & $0.03047$\\ +100000 & $3.14707$ & $0.00547$ & $0.00979$\\ +1000000 & $3.13682$ & $-0.00477$ & $0.00307$\\ +10000000 & $3.14096$ & $-0.00063$ & $0.00097$\\ + + +\end{tabular} + +\end{footnotesize} +\end{center} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame}\frametitle{Central Limit Theorem} \begin{footnotesize} \begin{exampleblock}{} diff --git a/Lectures_my/EMPP/MC_examples/CLT/dupa.png b/Lectures_my/EMPP/MC_examples/CLT/dupa.png new file mode 100644 index 0000000..70db5f7 --- /dev/null +++ b/Lectures_my/EMPP/MC_examples/CLT/dupa.png Binary files differ diff --git a/Lectures_my/EMPP/MC_examples/CLT/ht.py b/Lectures_my/EMPP/MC_examples/CLT/ht.py new file mode 100644 index 0000000..bfa1be7 --- /dev/null +++ b/Lectures_my/EMPP/MC_examples/CLT/ht.py @@ -0,0 +1,31 @@ +from ROOT import * +import sys + +def main(argv=sys.argv): + + + pi=3.14159265359 + c=TCanvas("c1", "c1", 800,600) + + NTOYS=1000000 + rand=TRandom(123) + + hists=[] + + for i in range(1,13, 2): + hist=TH1D("hist", "hist", 400, 0, 10) + for j in range(0, NTOYS): + tmp=0. + for k in range(0,i): + tmp+=rand.Rndm() + hist.Fill(tmp) + hists.append(hist) + + for i in range(0,len(hists)): + if(i==0): hists[i].DrawNormalized() + else: hists[i].DrawNormalized("SAME") + + c.SaveAs("dupa.png") + +if __name__ == "__main__": + sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/CLT/ht.py~ b/Lectures_my/EMPP/MC_examples/CLT/ht.py~ new file mode 100644 index 0000000..d9f4fdf --- /dev/null +++ b/Lectures_my/EMPP/MC_examples/CLT/ht.py~ @@ -0,0 +1,31 @@ +from ROOT import * +import sys + +def main(argv=sys.argv): + + + pi=3.14159265359 + c=TCanvas("c1", "c1", 800,600) + + NTOYS=10000 + rand=TRandom(123) + + hists=[] + + for i in range(1,13, 2): + hist=TH1D("hist", "hist", 400, 0, 10) + for j in range(0, NTOYS): + tmp=0. + for k in range(0,i): + tmp+=rand.Rndm() + hist.Fill(tmp) + hists.append(hist) + + for i in range(0,len(hists)): + if(i==0): hists[i].DrawNormalized() + else: hists[i].DrawNormalized("SAME") + + c.SaveAs("dupa.png") + +if __name__ == "__main__": + sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/Heads_tails/ht.py b/Lectures_my/EMPP/MC_examples/Heads_tails/ht.py deleted file mode 100644 index fcb8078..0000000 --- a/Lectures_my/EMPP/MC_examples/Heads_tails/ht.py +++ /dev/null @@ -1,23 +0,0 @@ -from ROOT import * -import sys - -def main(argv=sys.argv): - - - pi=3.14159265359 - c=TCanvas("c1", "c1", 800,600) - fun=TF1("f1", "0.9*cos(x)", 0, pi/2) - fun.SetLineColor(kBlack) - fun.SetFillColor(1) - fun.SetTitle("") - fun.GetXaxis().SetTitle('x') - fun.GetYaxis().SetTitle('y') - - fun.Draw("FC") - - c1.SaveAs("result.png") - - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/Heads_tails/ht.py~ b/Lectures_my/EMPP/MC_examples/Heads_tails/ht.py~ deleted file mode 100644 index b9852a4..0000000 --- a/Lectures_my/EMPP/MC_examples/Heads_tails/ht.py~ +++ /dev/null @@ -1,22 +0,0 @@ -from ROOT import * -import sys - -def main(argv=sys.argv): - - - pi=3.14159265359 - c=TCanvas("c1", "c1", 800,600) - fun=TF1("f1", "0.9*cos(x)", 0, pi/2) - fun.SetLineColor(kBlack) - fun.SetFillColor(1) - fun.SetTitle("") - fun.GetXaxis().SetTitle('x') - - fun.Draw("FC") - - c1.SaveAs("result.png") - - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/Heads_tails/ht_MC.py b/Lectures_my/EMPP/MC_examples/Heads_tails/ht_MC.py new file mode 100644 index 0000000..33d131c --- /dev/null +++ b/Lectures_my/EMPP/MC_examples/Heads_tails/ht_MC.py @@ -0,0 +1,44 @@ +from ROOT import * +import sys + +def main(argv=sys.argv): + ntoys=[10000,100000, 1000000, 10000000] + for i in ntoys: + calc_pi(i) + +def calc_pi(NTOYS): + + # seting up dimensions + L=1 + l=0.8 + pi=3.14159265359 + rand=TRandom3(12) + # the lines on the table are at ..,-2L, -L, 0, L, 2L,... + counter=0. + + + + for i in range(NTOYS): + rand_y=rand.Rndm()-0.5 # this is in range (-0.5,0.5) + rand_y=rand_y*2.*L # now we have range -L, L + rand_angle=rand.Rndm() + rand_angle=rand_angle*pi # this is the angle in range(0,pi) + delta_y=(l/2)*cos(rand_angle) + y_max=rand_y+abs(delta_y) + y_min=rand_y-abs(delta_y) + if(y_max>L or y_min<-L): counter=counter+1. + if(y_max>0 and y_min<0): counter=counter+1. + + + counter=counter/NTOYS + #now remember P=2l/piL, so: + Pi=2*l/(L*counter) + counter_err=(1./sqrt(NTOYS))*sqrt(counter*(1.-counter)) + pi_err=(counter_err/counter)*Pi + + print NTOYS , round(Pi,5), round(Pi-pi,5), round(pi_err,5) + + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/Heads_tails/ht_plot.py b/Lectures_my/EMPP/MC_examples/Heads_tails/ht_plot.py new file mode 100644 index 0000000..fcb8078 --- /dev/null +++ b/Lectures_my/EMPP/MC_examples/Heads_tails/ht_plot.py @@ -0,0 +1,23 @@ +from ROOT import * +import sys + +def main(argv=sys.argv): + + + pi=3.14159265359 + c=TCanvas("c1", "c1", 800,600) + fun=TF1("f1", "0.9*cos(x)", 0, pi/2) + fun.SetLineColor(kBlack) + fun.SetFillColor(1) + fun.SetTitle("") + fun.GetXaxis().SetTitle('x') + fun.GetYaxis().SetTitle('y') + + fun.Draw("FC") + + c1.SaveAs("result.png") + + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/dupa.png b/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/dupa.png deleted file mode 100644 index 70db5f7..0000000 --- a/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/dupa.png +++ /dev/null Binary files differ diff --git a/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/ht.py b/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/ht.py deleted file mode 100644 index bfa1be7..0000000 --- a/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/ht.py +++ /dev/null @@ -1,31 +0,0 @@ -from ROOT import * -import sys - -def main(argv=sys.argv): - - - pi=3.14159265359 - c=TCanvas("c1", "c1", 800,600) - - NTOYS=1000000 - rand=TRandom(123) - - hists=[] - - for i in range(1,13, 2): - hist=TH1D("hist", "hist", 400, 0, 10) - for j in range(0, NTOYS): - tmp=0. - for k in range(0,i): - tmp+=rand.Rndm() - hist.Fill(tmp) - hists.append(hist) - - for i in range(0,len(hists)): - if(i==0): hists[i].DrawNormalized() - else: hists[i].DrawNormalized("SAME") - - c.SaveAs("dupa.png") - -if __name__ == "__main__": - sys.exit(main()) diff --git a/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/ht.py~ b/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/ht.py~ deleted file mode 100644 index d9f4fdf..0000000 --- a/Lectures_my/EMPP/MC_examples/Large_Number_Theorem/ht.py~ +++ /dev/null @@ -1,31 +0,0 @@ -from ROOT import * -import sys - -def main(argv=sys.argv): - - - pi=3.14159265359 - c=TCanvas("c1", "c1", 800,600) - - NTOYS=10000 - rand=TRandom(123) - - hists=[] - - for i in range(1,13, 2): - hist=TH1D("hist", "hist", 400, 0, 10) - for j in range(0, NTOYS): - tmp=0. - for k in range(0,i): - tmp+=rand.Rndm() - hist.Fill(tmp) - hists.append(hist) - - for i in range(0,len(hists)): - if(i==0): hists[i].DrawNormalized() - else: hists[i].DrawNormalized("SAME") - - c.SaveAs("dupa.png") - -if __name__ == "__main__": - sys.exit(main())