vavilov.C

Go to the documentation of this file.
00001 #include "TMath.h"
00002 #include "TCanvas.h"
00003 #include "TRandom.h"
00004 #include "TGraph.h"
00005    
00006 void vavilov()
00007 {
00008    //test of the TMath::Vavilov distribution
00009    //Author: Anna Kreshuk
00010    
00011    Int_t n = 1000;
00012    Double_t *x  = new Double_t[n];
00013    Double_t *y1 = new Double_t[n];
00014    Double_t *y2 = new Double_t[n];
00015    Double_t *y3 = new Double_t[n];
00016    Double_t *y4 = new Double_t[n];
00017 
00018    TRandom r;
00019    for (Int_t i=0; i<n; i++) {
00020       x[i]  = r.Uniform(-2, 10);
00021       y1[i] = TMath::Vavilov(x[i], 0.3, 0.5);
00022       y2[i] = TMath::Vavilov(x[i], 0.15, 0.5);
00023       y3[i] = TMath::Vavilov(x[i], 0.25, 0.5);
00024       y4[i] = TMath::Vavilov(x[i], 0.05, 0.5);
00025    }
00026 
00027    TCanvas *c1 = new TCanvas("c1", "Vavilov density");
00028    c1->SetGrid();
00029    c1->SetHighLightColor(19);
00030    TGraph *gr1 = new TGraph(n, x, y1);
00031    TGraph *gr2 = new TGraph(n, x, y2);
00032    TGraph *gr3 = new TGraph(n, x, y3);
00033    TGraph *gr4 = new TGraph(n, x, y4);
00034    gr1->SetTitle("TMath::Vavilov density");
00035    gr1->Draw("ap");
00036    gr2->Draw("psame");
00037    gr2->SetMarkerColor(kRed);
00038    gr3->Draw("psame");
00039    gr3->SetMarkerColor(kBlue);
00040    gr4->Draw("psame");
00041    gr4->SetMarkerColor(kGreen);
00042 
00043    TF1 *f1 = new TF1("f1", "TMath::Vavilov(x, 0.3, 0.5)", -2, 10);
00044 
00045    TH1F *hist = new TH1F("vavilov", "vavilov", 100, -2, 10);
00046    for (int i=0; i<10000; i++) {
00047       hist->Fill(f1->GetRandom());
00048    }
00049    hist->Scale(1/1200.);
00050    hist->Draw("same");
00051 }

Generated on Tue Jul 5 15:44:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1