Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
qa2.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_fit
3/// \notebook -js
4/// Test generation of random numbers distributed according to a function defined by the user
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \author Rene Brun
11
12void qa2() {
13 //Fill a 1-D histogram from a parametric function
14 TCanvas *c1 = new TCanvas("c1","The FillRandom example",0,0,700,500);
15
16 gBenchmark->Start("fillrandom");
17 //
18 // A function (any dimension) or a formula may reference
19 // an already defined formula
20 //
21 TFormula *form1 = new TFormula("form1","abs(sin(x)/x)");
22 TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
23 sqroot->SetParameters(10,4,1,20);
24
25 //
26 // Create a one dimensional histogram (one float per bin)
27 // and fill it following the distribution in function sqroot.
28 //
29 TH1F *h1f = new TH1F("h1f","Test random numbers",200,0,10);
30 h1f->SetFillColor(45);
31 h1f->FillRandom("sqroot",100000);
32 h1f->Draw();
33 TPaveLabel *lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
34 lfunction->SetFillColor(41);
35
36 c1->SetGridx();
37 c1->SetGridy();
38
39 h1f->SetDirectory(0);
40
41 c1->Update();
42
43 sqroot->SetParameters(200,4,1,20);
44}
R__EXTERN TBenchmark * gBenchmark
Definition TBenchmark.h:59
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void Start(const char *name)
Starts Benchmark with the specified name.
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:213
virtual void SetParameters(const Double_t *params)
Definition TF1.h:644
The Formula class.
Definition TFormula.h:87
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8767
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3526
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3074
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
return c1
Definition legend1.C:41