-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathqa2.C
51 lines (43 loc) · 1.29 KB
/
qa2.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/// \file
/// \ingroup tutorial_math
/// \notebook -js
/// Test generation of random numbers distributed according to a function defined by the user.
///
/// \macro_image
/// \macro_output
/// \macro_code
///
/// \author Rene Brun
#include <TBenchmark.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TFormula.h>
#include <TH1F.h>
#include <TPaveLabel.h>
void qa2() {
//Fill a 1-D histogram from a parametric function
TCanvas *c1 = new TCanvas("c1","The FillRandom example",0,0,700,500);
gBenchmark->Start("fillrandom");
//
// A function (any dimension) or a formula may reference
// an already defined formula
//
TFormula *form1 = new TFormula("form1","abs(sin(x)/x)");
TF1 *sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
sqroot->SetParameters(10,4,1,20);
//
// Create a one dimensional histogram (one float per bin)
// and fill it following the distribution in function sqroot.
//
TH1F *h1f = new TH1F("h1f","Test random numbers",200,0,10);
h1f->SetFillColor(45);
h1f->FillRandom("sqroot",100000);
h1f->Draw();
TPaveLabel *lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
lfunction->SetFillColor(41);
c1->SetGridx();
c1->SetGridy();
h1f->SetDirectory(nullptr);
c1->Update();
sqroot->SetParameters(200,4,1,20);
}