Logo ROOT   6.08/07
Reference Guide
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 void 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 }
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:319
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:439
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8051
return c1
Definition: legend1.C:41
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:174
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:24
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3293
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2851
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:63
The F O R M U L A class.
Definition: TFormula.h:89
The Canvas class.
Definition: TCanvas.h:41
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:320
1-Dim function class
Definition: TF1.h:149
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183