(b) Dir ROOT Klasse TRandom bietet enthält etliche weitere Funktionen um Zufallszahlen für andere Verteilungen zu erzeugen, z.B. Poisson, Rndm, Exp, .... Probieren Sie einige aus und füllen Sie geeignete Histogramme.
C++ IO
ifstream data_file;
data_file.open("rohr1.dat");
double x;
// book histogram ...
while ( data_file >>x ) // reads next value into x
{ // Fill histo ...
}
Python IO
import numpy as np
data = np.loadtxt('rohr1.dat') # read all data in numpy array
# book histo ....
for x in data: # loop over data
# fill histo
Erzeugen Sie ein Histogramm und Füllen die Werte ein. ( Lösungsbeispiel: .C, .py )
(b) Analog für rohr2.dat in ein 2-dim Histogramm (`scatter-plot').
TH2F h2("h","mytitle",nx,xlow,xhig,ny,ylow,yhigh);
...
h2.Fill(x,y)
C++ IO x,y
...
while ( data_file >>x >>y) // reads next value pair into x and y
Python IO x,y
...
data2 = np.loadtxt('rohr2.dat') # read all data in numpy array
...
for x,y in data2: # loop over data2 entries
...
(a) Verwenden Sie gleichverteilte Zufallszahlen (gRandom->Rndm() ) und testen Sie
wie die Verteilung von abhängt.
void tclim( Int_t n = 12, Int_t ns = 1000 ) { TH1F * hclim = new TH1F("hclim", "central limit test", 100, -5, 5); for ( Int_t i = 0; i<ns; i++ ) { Float_t sum = 0; for ( Int_t j = 0; j<n ; j++ ) { sum += gRandom->Rndm() - 0.5; } hclim->Fill( sum ); } }
(b) Nehmen Sie statt der Gleichverteilung die Exponentialverteilung (gRandom->Exp(1)