testrandom.C: Performance test of all the ROOT random generator (TRandom, TRandom1, TRandom2 and TRandom3) | Math tutorials |
#include "TMath.h" #include "TCanvas.h" #include "TRandom.h" #include "TGraph.h" void vavilov() { //test of the TMath::Vavilov distribution //Author: Anna Kreshuk Int_t n = 1000; Double_t *x = new Double_t[n]; Double_t *y1 = new Double_t[n]; Double_t *y2 = new Double_t[n]; Double_t *y3 = new Double_t[n]; Double_t *y4 = new Double_t[n]; TRandom r; for (Int_t i=0; i<n; i++) { x[i] = r.Uniform(-2, 10); y1[i] = TMath::Vavilov(x[i], 0.3, 0.5); y2[i] = TMath::Vavilov(x[i], 0.15, 0.5); y3[i] = TMath::Vavilov(x[i], 0.25, 0.5); y4[i] = TMath::Vavilov(x[i], 0.05, 0.5); } TCanvas *c1 = new TCanvas("c1", "Vavilov density"); c1->SetGrid(); c1->SetHighLightColor(19); TGraph *gr1 = new TGraph(n, x, y1); TGraph *gr2 = new TGraph(n, x, y2); TGraph *gr3 = new TGraph(n, x, y3); TGraph *gr4 = new TGraph(n, x, y4); gr1->SetTitle("TMath::Vavilov density"); gr1->Draw("ap"); gr2->Draw("psame"); gr2->SetMarkerColor(kRed); gr3->Draw("psame"); gr3->SetMarkerColor(kBlue); gr4->Draw("psame"); gr4->SetMarkerColor(kGreen); TF1 *f1 = new TF1("f1", "TMath::Vavilov(x, 0.3, 0.5)", -2, 10); TH1F *hist = new TH1F("vavilov", "vavilov", 100, -2, 10); for (int i=0; i<10000; i++) { hist->Fill(f1->GetRandom()); } hist->Scale(1/1200.); hist->Draw("same"); } vavilov.C:1 vavilov.C:2 vavilov.C:3 vavilov.C:4 vavilov.C:5 vavilov.C:6 vavilov.C:7 vavilov.C:8 vavilov.C:9 vavilov.C:10 vavilov.C:11 vavilov.C:12 vavilov.C:13 vavilov.C:14 vavilov.C:15 vavilov.C:16 vavilov.C:17 vavilov.C:18 vavilov.C:19 vavilov.C:20 vavilov.C:21 vavilov.C:22 vavilov.C:23 vavilov.C:24 vavilov.C:25 vavilov.C:26 vavilov.C:27 vavilov.C:28 vavilov.C:29 vavilov.C:30 vavilov.C:31 vavilov.C:32 vavilov.C:33 vavilov.C:34 vavilov.C:35 vavilov.C:36 vavilov.C:37 vavilov.C:38 vavilov.C:39 vavilov.C:40 vavilov.C:41 vavilov.C:42 vavilov.C:43 vavilov.C:44 vavilov.C:45 vavilov.C:46 vavilov.C:47 vavilov.C:48 vavilov.C:49 vavilov.C:50 vavilov.C:51 vavilov.C:52 |
|