Logo ROOT   6.10/09
Reference Guide
mathcoreSpecFunc.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// \notebook
4 /// Example macro describing how to use the special mathematical functions
5 /// taking full advantage of the precision and speed of the C99 compliant
6 /// environments. To execute the macro type in:
7 ///
8 /// ~~~{.cpp}
9 /// root[0] .x mathcoreSpecFunc.C
10 /// ~~~
11 ///
12 /// It will create two canvases:
13 ///
14 /// 1. one with the representation of the tgamma, lgamma, erf and erfc functions
15 /// 2. one with the relative difference between the old ROOT versions and the
16 /// C99 implementation (on obsolete platform+compiler combinations which are
17 /// not C99 compliant it will call the original ROOT implementations, hence
18 /// the difference will be 0)
19 ///
20 /// The naming and numbering of the functions is taken from
21 /// [Matt Austern, (Draft) Technical Report on Standard Library Extensions, N1687=04-0127, September 10, 2004](A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1687.pdf")
22 ///
23 /// \macro_image
24 /// \macro_code
25 ///
26 /// \author Andras Zsenei
27 
28 #include "TF1.h"
29 #include "TSystem.h"
30 #include "TCanvas.h"
31 
32 void mathcoreSpecFunc() {
33 
34  gSystem->Load("libMathCore");
35  TF1 *f1a = new TF1("f1a","ROOT::Math::tgamma(x)",0,20);
36  TF1 *f1b = new TF1("f1b","abs((ROOT::Math::tgamma(x)-TMath::Gamma(x))/ROOT::Math::tgamma(x))",0,20);
37 
38  TF1 *f2a = new TF1("f2a","ROOT::Math::lgamma(x)",0,100);
39  TF1 *f2b = new TF1("f2b","abs((ROOT::Math::lgamma(x)-TMath::LnGamma(x))/ROOT::Math::lgamma(x))",0,100);
40 
41  TF1 *f3a = new TF1("f3a","ROOT::Math::erf(x)",0,5);
42  TF1 *f3b = new TF1("f3b","abs((ROOT::Math::erf(x)-TMath::Erf(x))/ROOT::Math::erf(x))",0,5);
43 
44  TF1 *f4a = new TF1("f4a","ROOT::Math::erfc(x)",0,5);
45  TF1 *f4b = new TF1("f4b","abs((ROOT::Math::erfc(x)-TMath::Erfc(x))/ROOT::Math::erfc(x))",0,5);
46 
47 
48  TCanvas *c1 = new TCanvas("c1","c1",800,600);
49 
50  f1a->SetLineColor(kBlue);
51  f1b->SetLineColor(kBlue);
52  f2a->SetLineColor(kBlue);
53  f2b->SetLineColor(kBlue);
54  f3a->SetLineColor(kBlue);
55  f3b->SetLineColor(kBlue);
56  f4a->SetLineColor(kBlue);
57  f4b->SetLineColor(kBlue);
58 
59  c1->Divide(2,2);
60 
61  c1->cd(1);
62  f1a->Draw();
63  c1->cd(2);
64  f2a->Draw();
65  c1->cd(3);
66  f3a->Draw();
67  c1->cd(4);
68  f4a->Draw();
69 
70 
71  TCanvas *c2 = new TCanvas("c2","c2",800,600);
72 
73  c2->Divide(2,2);
74 
75  c2->cd(1);
76  f1b->Draw();
77  c2->cd(2);
78  f2b->Draw();
79  c2->cd(3);
80  f3b->Draw();
81  c2->cd(4);
82  f4b->Draw();
83 
84 }
return c1
Definition: legend1.C:41
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:679
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1825
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1087
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
The Canvas class.
Definition: TCanvas.h:31
return c2
Definition: legend2.C:14
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
1-Dim function class
Definition: TF1.h:150
Definition: Rtypes.h:56