ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CrystalBall.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// Example of CrystalBall Function and its distribution (pdf and cdf)
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Lorenzo Moneta
9 
10 void CrystalBall() {
11 
12  auto c1 = new TCanvas();
13  c1->Divide(1,3);
14 
15  // crystal ball function
16  c1->cd(1);
17 
18  auto f1 = new TF1("f1","crystalball",-5,5);
19  f1->SetParameters(1, 0, 1, 2, 0.5);
21  f1->Draw();
22  // use directly the functionin ROOT::MATH note that the parameters definition is different is (alpha, n sigma, mu)
23  auto f2 = new TF1("f2","ROOT::Math::crystalball_function(x, 2, 1, 1, 0)",-5,5);
24  f2->SetLineColor(kGreen);
25  f2->Draw("same");
26  auto f3 = new TF1("f3","ROOT::Math::crystalball_function(x, 2, 2, 1, 0)",-5,5);
27  f3->SetLineColor(kBlue);
28  f3->Draw("same");
29 
30  auto legend = new TLegend(0.7,0.6,0.9,1.);
31  legend->AddEntry(f1,"N=0.5 alpha=2","L");
32  legend->AddEntry(f2,"N=1 alpha=2","L");
33  legend->AddEntry(f3,"N=2 alpha=2","L");
34  legend->Draw();
35 
36  c1->cd(2);
37  auto pdf1 = new TF1("pdf","crystalballn",-5,5);
38  pdf1->SetParameters(2, 0, 1, 2, 3);
39  pdf1->Draw();
40  auto pdf2 = new TF1("pdf","ROOT::Math::crystalball_pdf(x, 3, 1.01, 1, 0)",-5,5);
41  pdf2->SetLineColor(kBlue);
42  pdf2->Draw("same");
43  auto pdf3 = new TF1("pdf","ROOT::Math::crystalball_pdf(x, 2, 2, 1, 0)",-5,5);
44  pdf3->SetLineColor(kGreen);
45  pdf3->Draw("same");
46 
47  legend = new TLegend(0.7,0.6,0.9,1.);
48  legend->AddEntry(pdf1,"N=3 alpha=2","L");
49  legend->AddEntry(pdf2,"N=1.01 alpha=3","L");
50  legend->AddEntry(pdf3,"N=2 alpha=3","L");
51  legend->Draw();
52 
53  c1->cd(3);
54  auto cdf = new TF1("cdf","ROOT::Math::crystalball_cdf(x, 1.2, 2, 1, 0)",-5,5);
55  auto cdfc = new TF1("cdfc","ROOT::Math::crystalball_cdf_c(x, 1.2, 2, 1, 0)",-5,5);
56  cdf->SetLineColor(kRed-3);
57  cdf->SetMinimum(0.);
58  cdf->SetMaximum(1.);
59  cdf->Draw();
60  cdfc->SetLineColor(kMagenta);
61  cdfc->Draw("Same");
62 
63  legend = new TLegend(0.7,0.7,0.9,1.);
64  legend->AddEntry(cdf,"N=1.2 alpha=2","L");
65  legend->AddEntry(cdfc,"N=1.2 alpha=2","L");
66  legend->Draw();
67 }
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:432
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
TCanvas * c1
Definition: legend1.C:2
Definition: Rtypes.h:61
tuple f2
Definition: surfaces.py:24
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
void f3()
Definition: na49.C:50
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1052
Definition: Rtypes.h:61
TLegend * legend
Definition: pirndm.C:35
double cdf(double *x, double *p)
Definition: unuranDistr.cxx:44
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
The Canvas class.
Definition: TCanvas.h:48
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
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:1073
1-Dim function class
Definition: TF1.h:149
TF1 * f1
Definition: legend1.C:11
Definition: Rtypes.h:61