Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
vavilov.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// \notebook
4 /// Test of the TMath::Vavilov distribution
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Anna Kreshuk
10 
11 #include "TMath.h"
12 #include "TCanvas.h"
13 #include "TRandom.h"
14 #include "TGraph.h"
15 
16 void vavilov()
17 {
18  Int_t n = 1000;
19  Double_t *xvalues = new Double_t[n];
20  Double_t *yvalues1 = new Double_t[n];
21  Double_t *yvalues2 = new Double_t[n];
22  Double_t *yvalues3 = new Double_t[n];
23  Double_t *yvalues4 = new Double_t[n];
24 
25  TRandom r;
26  for (Int_t i=0; i<n; i++) {
27  xvalues[i] = r.Uniform(-2, 10);
28  yvalues1[i] = TMath::Vavilov(xvalues[i], 0.3, 0.5);
29  yvalues2[i] = TMath::Vavilov(xvalues[i], 0.15, 0.5);
30  yvalues3[i] = TMath::Vavilov(xvalues[i], 0.25, 0.5);
31  yvalues4[i] = TMath::Vavilov(xvalues[i], 0.05, 0.5);
32  }
33 
34  TCanvas *c1 = new TCanvas("c1", "Vavilov density");
35  c1->SetGrid();
36  c1->SetHighLightColor(19);
37  TGraph *gr1 = new TGraph(n, xvalues, yvalues1);
38  TGraph *gr2 = new TGraph(n, xvalues, yvalues2);
39  TGraph *gr3 = new TGraph(n, xvalues, yvalues3);
40  TGraph *gr4 = new TGraph(n, xvalues, yvalues4);
41  gr1->SetTitle("TMath::Vavilov density");
42  gr1->Draw("ap");
43  gr2->Draw("psame");
44  gr2->SetMarkerColor(kRed);
45  gr3->Draw("psame");
46  gr3->SetMarkerColor(kBlue);
47  gr4->Draw("psame");
48  gr4->SetMarkerColor(kGreen);
49 
50  TF1 *f1 = new TF1("f1", "TMath::Vavilov(x, 0.3, 0.5)", -2, 10);
51 
52  TH1F *hist = new TH1F("vavilov", "vavilov", 100, -2, 10);
53  for (int i=0; i<10000; i++) {
54  hist->Fill(f1->GetRandom());
55  }
56  hist->Scale(1/1200.);
57  hist->Draw("same");
58 }