Logo ROOT  
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
16void 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");
47 gr4->Draw("psame");
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}
int Int_t
Definition: RtypesCore.h:45
double Double_t
Definition: RtypesCore.h:59
@ kRed
Definition: Rtypes.h:66
@ kGreen
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
The Canvas class.
Definition: TCanvas.h:23
1-Dim function class
Definition: TF1.h:213
virtual Double_t GetRandom(TRandom *rng=nullptr, Option_t *opt=nullptr)
Return a random number following this function shape.
Definition: TF1.cxx:2197
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition: TGraph.cxx:808
void SetTitle(const char *title="") override
Change (i.e.
Definition: TGraph.cxx:2338
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:577
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3338
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3060
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:6586
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
return c1
Definition: legend1.C:41
const Int_t n
Definition: legend1.C:16
TF1 * f1
Definition: legend1.C:11
Double_t Vavilov(Double_t x, Double_t kappa, Double_t beta2)
Returns the value of the Vavilov density function.
Definition: TMath.cxx:2769