void test_random(void) { // // plot the number of fits to a cdc segment that result in prob > prob_cut (currently set to 0.01). // #include #include gROOT->Reset(); //TTree *Bfield = (TTree *) gROOT->FindObject("Bfield"); gStyle->SetPalette(1,0); gStyle->SetOptStat(kTRUE); gStyle->SetOptFit(kTRUE); // gStyle->SetOptFit(1111); gStyle->SetPadRightMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadBottomMargin(0.15); gStyle->SetFillColor(0); // char string[256]; char filename[80]; Int_t j,jj; #define npts 100000; // define histograms nbins=100; TH1F *uniform = new TH1F("uniform","uniform distribution",nbins,0,1); TH1F *decay = new TH1F("decay","exponential distribution",nbins,0,40); TH1F *bell = new TH1F("bell","bell distribution",nbins,-10,10); TH1F *counts= new TH1F("counts","Poisson distribution",nbins/10,0,10); // TCanvas *c1 = new TCanvas("c1","c1 Test random",200,10,700,700); c1->SetBorderMode(0); c1->SetFillColor(0); // c1->SetGridx(); // c1->SetGridy(); // c1->SetLogy(); Double_t xmin=-1; Double_t xmax=1; // plot pulse function Double_t tau=4.; // unis of 1/x Double_t mean=3; // unis of 1/x Double_t sigma=2; // units of x Double_t Pmean=3; // Poisson mean TRandom1 *r = new TRandom1(); for (j=0;jUniform(); Double_t y = r->Exp(tau); Double_t z = r->Gaus(mean,sigma); // Int_t n = r->Gaus(Pmean); Int_t n = r->Poisson(Pmean); uniform->Fill(x); decay->Fill(y); bell->Fill(z); counts->Fill((Double_t) n); } c1->Divide(2,2); c1->cd(1); c1_1->SetBorderMode(0); c1_1->SetFillColor(0);; uniform->GetYaxis()->SetRangeUser(0,2*npts/nbins); uniform->Fit("pol1"); uniform->Draw(); c1->cd(2); c1_2->SetBorderMode(0); c1_2->SetFillColor(0); decay->Fit("expo"); decay->Draw(); c1->cd(3); c1_3->SetBorderMode(0); c1_3->SetFillColor(0); bell->Fit("gaus"); bell->Draw(); c1->cd(4); c1_3->SetBorderMode(0); c1_3->SetFillColor(0); counts->Fit("gaus"); counts->Draw(); }