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

Detailed Description

View in nbviewer Open in SWAN
Tutorial illustrating the use of TMath::GammaDist and TMath::LogNormal

void mathGammaNormal(){
TCanvas *myc = new TCanvas("c1","gamma and lognormal",10,10,600,800);
myc->Divide(1,2);
TPad *pad1 = (TPad *)myc->cd(1);
pad1->SetLogy();
pad1->SetGrid();
//TMath::GammaDist
TF1 *fgamma = new TF1("fgamma", "TMath::GammaDist(x, [0], [1], [2])", 0, 10);
fgamma->SetParameters(0.5, 0, 1);
TF1 *f1 = fgamma->DrawCopy();
f1->SetMinimum(1e-5);
fgamma->SetParameters(1, 0, 1);
TF1 *f2 = fgamma->DrawCopy("same");
fgamma->SetParameters(2, 0, 1);
TF1 *f3 = fgamma->DrawCopy("same");
fgamma->SetParameters(5, 0, 1);
TF1 *f4 = fgamma->DrawCopy("same");
TLegend *legend1 = new TLegend(.2,.15,.5,.4);
legend1->AddEntry(f1,"gamma = 0.5 mu = 0 beta = 1","l");
legend1->AddEntry(f2,"gamma = 1 mu = 0 beta = 1","l");
legend1->AddEntry(f3,"gamma = 2 mu = 0 beta = 1","l");
legend1->AddEntry(f4,"gamma = 5 mu = 0 beta = 1","l");
legend1->Draw();
//TMath::LogNormal
TPad *pad2 = (TPad *)myc->cd(2);
pad2->SetLogy();
pad2->SetGrid();
TF1 *flog = new TF1("flog", "TMath::LogNormal(x, [0], [1], [2])", 0, 5);
flog->SetParameters(0.5, 0, 1);
TF1 *g1 = flog->DrawCopy();
flog->SetParameters(1, 0, 1);
TF1 *g2 = flog->DrawCopy("same");
flog->SetParameters(2, 0, 1);
TF1 *g3 = flog->DrawCopy("same");
flog->SetParameters(5, 0, 1);
TF1 *g4 = flog->DrawCopy("same");
TLegend *legend2 = new TLegend(.2,.15,.5,.4);
legend2->AddEntry(g1,"sigma = 0.5 theta = 0 m = 1","l");
legend2->AddEntry(g2,"sigma = 1 theta = 0 m = 1","l");
legend2->AddEntry(g3,"sigma = 2 theta = 0 m = 1","l");
legend2->AddEntry(g4,"sigma = 5 theta = 0 m = 1","l");
legend2->Draw();
}
#define e(i)
Definition RSha256.hxx:103
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:716
1-Dim function class
Definition TF1.h:233
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum value along Y for this function In case the function is already drawn,...
Definition TF1.cxx:3407
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition TF1.cxx:1365
virtual void SetParameters(const Double_t *params)
Definition TF1.h:670
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition TLegend.cxx:317
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Definition TLegend.cxx:422
The most important graphics class in the ROOT system.
Definition TPad.h:28
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
Definition TPad.h:332
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1196
void SetLogy(Int_t value=1) override
Set Lin/Log scale for Y.
Definition TPad.cxx:6030
TF1 * f1
Definition legend1.C:11
Author
Anna Kreshuk

Definition in file mathGammaNormal.C.