Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
qa2.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Test generation of random numbers distributed according to a function defined by the user

#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);
}
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:233
virtual void SetParameters(const Double_t *params)
Definition TF1.h:677
The Formula class.
Definition TFormula.h:89
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
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:8970
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
Definition TH1.cxx:3530
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3068
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
return c1
Definition legend1.C:41
Author
Rene Brun

Definition in file qa2.C.