Logo ROOT  
Reference Guide
fillrandom.C File Reference

Detailed Description

View in nbviewer Open in SWAN Fill a 1-D histogram from a parametric function.

void fillrandom() {
TCanvas *c1 = new TCanvas("c1","The FillRandom example",200,10,700,900);
auto pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95);
auto pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45);
pad1->Draw();
pad2->Draw();
pad1->cd();
gBenchmark->Start("fillrandom");
//
// A function (any dimension) or a formula may reference
// an already defined formula
//
auto form1 = new TFormula("form1","abs(sin(x)/x)");
auto sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
sqroot->SetParameters(10,4,1,20);
pad1->SetGridx();
pad1->SetGridy();
pad1->GetFrame()->SetBorderMode(-1);
pad1->GetFrame()->SetBorderSize(5);
sqroot->SetLineColor(4);
sqroot->SetLineWidth(6);
sqroot->Draw();
auto lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
lfunction->Draw();
c1->Update();
//
// Create a one dimensional histogram (one float per bin)
// and fill it following the distribution in function sqroot.
//
pad2->cd();
pad2->GetFrame()->SetBorderMode(-1);
pad2->GetFrame()->SetBorderSize(5);
auto h1f = new TH1F("h1f","Test random numbers",200,0,10);
h1f->SetFillColor(45);
h1f->FillRandom("sqroot",10000);
h1f->Draw();
c1->Update();
//
// Open a ROOT file and save the formula, function and histogram
//
TFile myfile("fillrandom.root","RECREATE");
form1->Write();
sqroot->Write();
h1f->Write();
gBenchmark->Show("fillrandom");
}
Author
Rene Brun

Definition in file fillrandom.C.

TWbox::SetBorderMode
virtual void SetBorderMode(Short_t bordermode)
Definition: TWbox.h:57
fillrandom
Definition: fillrandom.py:1
TPad
Definition: TPad.h:26
TFormula
Definition: TFormula.h:85
TBenchmark::Start
virtual void Start(const char *name)
Starts Benchmark with the specified name.
Definition: TBenchmark.cxx:172
TPad::SetGridy
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:329
TPaveLabel::Draw
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
TF1::SetParameters
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:640
TPad::SetGridx
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:328
gBenchmark
R__EXTERN TBenchmark * gBenchmark
Definition: TBenchmark.h:59
TWbox::SetBorderSize
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:58
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3444
TFile
Definition: TFile.h:54
TPaveLabel
Definition: TPaveLabel.h:20
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TF1::Draw
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1338
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
TObject::Write
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:795
TPad::GetFrame
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2847
TF1
1-Dim function class
Definition: TF1.h:212
TBenchmark::Show
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Definition: TBenchmark.cxx:155
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41
TPad::Draw
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285