Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 }