#include "TMinuit.h" #include "TRandom.h" #include "TH1F.h" #include "TMath.h" #include #include #include "TGraphErrors.h" const double TWOPI=TMath::TwoPi(); const double RANDM=RAND_MAX; // Summary in a Histogram TH1F *Average = new TH1F("Average","",100,0,1); //---------------------------------------------------------------------- void CLT() //---------------------------------------------------------------------- { // Illustration of the Central Limit Theorem (CLT) // Generate a number N of uniform distributions between 0 and 1 // You can change the number of iterations here const int N = 2; double A; // Generate events for (int ievt=0; ievt!=100000; ievt++) { A=0.; for (int i=0; i!=N; i++) { A+=rand()/RANDM; } A=A/N; Average->Fill(A); } // Usual Style options in root gROOT->SetStyle("Plain"); gStyle->SetCanvasColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetPadColor(0); gStyle->SetLineWidth(1.); gStyle->SetCanvasDefH(596); gStyle->SetCanvasDefW(596); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetFrameBorderMode(0); gStyle->SetTitleBorderSize(0); gStyle->SetStatBorderSize(0); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetPalette(1); gStyle->SetOptStat(0); c0 = new TCanvas("c0", "", 0, 0, 600, 450); c0->SetLeftMargin(0.12); c0->SetRightMargin(0.12); c0->SetBottomMargin(0.2); Average->SetMinimum(0.); Average->Draw(); //Average->Fit("gaus"); cout << "Mean " << Average->GetMean() << " RMS " << Average->GetRMS() << endl; }