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
12#include <TBenchmark.h>
13#include <TCanvas.h>
14#include <TF1.h>
15#include <TFormula.h>
16#include <TH1F.h>
17#include <TPaveLabel.h>
18
19void qa2() {
20 //Fill a 1-D histogram from a parametric function
21 TCanvas *c1 = new TCanvas("c1","The FillRandom example",0,0,700,500);
22
23 gBenchmark->Start("fillrandom");
24 //
25 // A function (any dimension) or a formula may reference
26 // an already defined formula
27 //
28 TFormula *form1 = new TFormula("form1","abs(sin(x)/x)");
29 TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
30 sqroot->SetParameters(10,4,1,20);
31
32 //
33 // Create a one dimensional histogram (one float per bin)
34 // and fill it following the distribution in function sqroot.
35 //
36 TH1F *h1f = new TH1F("h1f","Test random numbers",200,0,10);
37 h1f->SetFillColor(45);
38 h1f->FillRandom("sqroot",100000);
39 h1f->Draw();
40 TPaveLabel *lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
41 lfunction->SetFillColor(41);
42
43 c1->SetGridx();
44 c1->SetGridy();
45
46 h1f->SetDirectory(nullptr);
47
48 c1->Update();
49
50 sqroot->SetParameters(200,4,1,20);
51}
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:214
virtual void SetParameters(const Double_t *params)
Definition TF1.h:650
The Formula class.
Definition TFormula.h:87
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
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:8854
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3520
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3067
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
return c1
Definition legend1.C:41