ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
testSpecFuncBeta.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
5 #include <cmath>
6 
7 #include <TMath.h>
8 #include <Math/SpecFunc.h>
9 
10 #include <TApplication.h>
11 
12 #include <TCanvas.h>
13 #include <TH2F.h>
14 #include <TGraph.h>
15 #include <TLegend.h>
16 
17 const double ERRORLIMIT = 1E-8;
18 const double MIN = -2.5;
19 const double MAX = +2.5;
20 const double INCREMENT = 0.01;
21 const int ARRAYSIZE = (int) (( MAX - MIN ) / INCREMENT) + 1;
22 
23 bool showGraphics = false;
24 bool verbose = false;
25 using namespace std;
26 
27 TGraph* drawPoints(Double_t x[], Double_t y[], int color, int style = 1)
28 {
29  TGraph* g = new TGraph(ARRAYSIZE, x, y);
30  g->SetLineColor(color);
31  g->SetLineStyle(style);
32  g->SetLineWidth(3);
33  g->Draw("SAME");
34 
35  return g;
36 }
37 
39 {
40  vector<Double_t> x( ARRAYSIZE );
41  vector<Double_t> yb( ARRAYSIZE );
42  vector<Double_t> ymb( ARRAYSIZE );
43 
44  int status = 0;
45 
46  int color = 2;
47  TGraph *gb = nullptr, *gmb = nullptr;
48  TCanvas* c1 = new TCanvas("c1", "BetaFunction", 600, 400);
49  TH2F* hpx;
50  {
51  hpx = new TH2F("hpx", "BetaFunction(p,b)", ARRAYSIZE, MIN, MAX, ARRAYSIZE, 0, 5);
52  hpx->SetStats(kFALSE);
53  hpx->Draw();
54  }
55 
56  for ( double b = 0.9; b < 2; b+=0.4)
57  {
58  cout << "** b = " << b << " **" << endl;
59  unsigned int index = 0;
60  for ( double i = MIN; i < MAX; i += INCREMENT )
61  {
62  if (verbose) {
63  cout << "i:"; cout.width(5); cout << i
64  << " index: "; cout.width(5); cout << index
65  << " TMath::Beta(p,b): "; cout.width(10); cout << TMath::Beta(i,b)
66  << " ROOT::Math::beta(p,b): "; cout.width(10); cout << ROOT::Math::beta(i,b)
67  << endl;
68  }
69  x[index] = i;
70  yb[index] = TMath::Beta(i,b);
71  ymb[index] = ROOT::Math::beta(i,b);
72  if ( std::fabs( yb[index] - ymb[index] ) > ERRORLIMIT )
73  {
74  cout << "i " << i
75  << " b " << b
76  << " yb[index] " << yb[index]
77  << " ymb[index] " << ymb[index]
78  << " " << std::fabs( yb[index] - ymb[index] )
79  << endl;
80  status += 1;
81  }
82  index += 1;
83  }
84 
85  gb = drawPoints(&x[0], &yb[0], color++);
86  gmb = drawPoints(&x[0], &ymb[0], color++, 7);
87  }
88 
89  if ( showGraphics )
90  {
91  TLegend* legend = new TLegend(0.61,0.72,0.86,0.86);
92  legend->AddEntry(gb, "TMath::Beta()");
93  legend->AddEntry(gmb, "ROOT::Math::beta()");
94  legend->Draw();
95 
96  c1->Show();
97  }
98 
99  cout << "Test Done!" << endl;
100 
101  return status;
102 }
103 
104 int main(int argc, char **argv)
105 {
106  // Parse command line arguments
107  for (Int_t i=1 ; i<argc ; i++) {
108  std::string arg = argv[i] ;
109  if (arg == "-g") {
110  showGraphics = true;
111  }
112  if (arg == "-v") {
113  showGraphics = true;
114  verbose = true;
115  }
116  if (arg == "-h") {
117  cerr << "Usage: " << argv[0] << " [-g] [-v]\n";
118  cerr << " where:\n";
119  cerr << " -g : graphics mode\n";
120  cerr << " -v : verbose mode";
121  cerr << endl;
122  return -1;
123  }
124  }
125 
126  TApplication* theApp = 0;
127  if ( showGraphics )
128  theApp = new TApplication("App",&argc,argv);
129 
130  int status = testSpecFuncBeta();
131 
132  if ( showGraphics )
133  {
134  theApp->Run();
135  delete theApp;
136  theApp = 0;
137  }
138 
139  return status;
140 }
const double MAX
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
TCanvas * c1
Definition: legend1.C:2
const int ARRAYSIZE
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
int main(int argc, char **argv)
int Int_t
Definition: RtypesCore.h:41
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
const Bool_t kFALSE
Definition: Rtypes.h:92
TLegend * legend
Definition: pirndm.C:35
double beta(double x, double y)
Calculates the beta function.
Double_t x[n]
Definition: legend1.C:17
const double MIN
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
TGraph * drawPoints(Double_t x[], Double_t y[], int color, int style=1)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Double_t E()
Definition: TMath.h:54
Double_t Beta(Double_t p, Double_t q)
Calculates Beta-function Gamma(p)*Gamma(q)/Gamma(p+q).
Definition: TMath.cxx:1973
const double ERRORLIMIT
double Double_t
Definition: RtypesCore.h:55
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition: TLegend.cxx:280
const double INCREMENT
TCanvas * style()
Definition: style.C:1
Double_t y[n]
Definition: legend1.C:17
int testSpecFuncBeta()
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45
TH1F * hpx
Definition: hcons.C:32