Logo ROOT   6.10/09
Reference Guide
mathGammaNormal.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// \notebook
4 /// Tutorial illustrating the use of TMath::GammaDist and TMath::LogNormal
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Anna Kreshuk
10 
11 void mathGammaNormal(){
12  TCanvas *myc = new TCanvas("c1","gamma and lognormal",10,10,600,800);
13  myc->Divide(1,2);
14  TPad *pad1 = (TPad *)myc->cd(1);
15  pad1->SetLogy();
16  pad1->SetGrid();
17 
18  //TMath::GammaDist
19  TF1 *fgamma = new TF1("fgamma", "TMath::GammaDist(x, [0], [1], [2])", 0, 10);
20  fgamma->SetParameters(0.5, 0, 1);
21  TF1 *f1 = fgamma->DrawCopy();
22  f1->SetMinimum(1e-5);
23  f1->SetLineColor(kRed);
24  fgamma->SetParameters(1, 0, 1);
25  TF1 *f2 = fgamma->DrawCopy("same");
26  f2->SetLineColor(kGreen);
27  fgamma->SetParameters(2, 0, 1);
28  TF1 *f3 = fgamma->DrawCopy("same");
29  f3->SetLineColor(kBlue);
30  fgamma->SetParameters(5, 0, 1);
31  TF1 *f4 = fgamma->DrawCopy("same");
33  TLegend *legend1 = new TLegend(.2,.15,.5,.4);
34  legend1->AddEntry(f1,"gamma = 0.5 mu = 0 beta = 1","l");
35  legend1->AddEntry(f2,"gamma = 1 mu = 0 beta = 1","l");
36  legend1->AddEntry(f3,"gamma = 2 mu = 0 beta = 1","l");
37  legend1->AddEntry(f4,"gamma = 5 mu = 0 beta = 1","l");
38  legend1->Draw();
39 
40  //TMath::LogNormal
41  TPad *pad2 = (TPad *)myc->cd(2);
42  pad2->SetLogy();
43  pad2->SetGrid();
44  TF1 *flog = new TF1("flog", "TMath::LogNormal(x, [0], [1], [2])", 0, 5);
45  flog->SetParameters(0.5, 0, 1);
46  TF1 *g1 = flog->DrawCopy();
47  g1->SetLineColor(kRed);
48  flog->SetParameters(1, 0, 1);
49  TF1 *g2 = flog->DrawCopy("same");
50  g2->SetLineColor(kGreen);
51  flog->SetParameters(2, 0, 1);
52  TF1 *g3 = flog->DrawCopy("same");
53  g3->SetLineColor(kBlue);
54  flog->SetParameters(5, 0, 1);
55  TF1 *g4 = flog->DrawCopy("same");
57  TLegend *legend2 = new TLegend(.2,.15,.5,.4);
58  legend2->AddEntry(g1,"sigma = 0.5 theta = 0 m = 1","l");
59  legend2->AddEntry(g2,"sigma = 1 theta = 0 m = 1","l");
60  legend2->AddEntry(g3,"sigma = 2 theta = 0 m = 1","l");
61  legend2->AddEntry(g4,"sigma = 5 theta = 0 m = 1","l");
62  legend2->Draw();
63 }
64 
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:588
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:23
virtual TF1 * DrawCopy(Option_t *option="") const
Draw a copy of this function with its current attributes.
Definition: TF1.cxx:1115
Definition: Rtypes.h:56
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:452
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
Definition: Rtypes.h:56
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum value along Y for this function In case the function is already drawn, set also the minimum in the helper histogram.
Definition: TF1.cxx:3176
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:323
TString flog
Definition: pq2main.cxx:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The most important graphics class in the ROOT system.
Definition: TPad.h:29
The Canvas class.
Definition: TCanvas.h:31
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:359
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1135
double f2(const double *x)
1-Dim function class
Definition: TF1.h:150
TF1 * f1
Definition: legend1.C:11
Definition: Rtypes.h:56
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.
Definition: TPad.cxx:5780