Logo ROOT   6.14/05
Reference Guide
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 }
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:6101
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3251
virtual Double_t GetRandom()
Return a random number following this function shape.
Definition: TF1.cxx:1981
return c1
Definition: legend1.C:41
Definition: Rtypes.h:59
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
int Int_t
Definition: RtypesCore.h:41
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2216
Definition: Rtypes.h:59
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:745
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:327
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
1-Dim function class
Definition: TF1.h:211
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
TF1 * f1
Definition: legend1.C:11
Definition: Rtypes.h:59
const Int_t n
Definition: legend1.C:16
void SetHighLightColor(Color_t col)
Definition: TCanvas.h:213
Double_t Vavilov(Double_t x, Double_t kappa, Double_t beta2)