ROOT  6.06/09
Reference Guide
testSpecFuncBetaI.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 = 0;
19 const double MAX = 1;
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 
26 using namespace std;
27 
28 TGraph* drawPoints(Double_t x[], Double_t y[], int color, int style = 1)
29 {
30  TGraph* g = new TGraph(ARRAYSIZE, x, y);
31  g->SetLineColor(color);
32  g->SetLineStyle(style);
33  g->SetLineWidth(3);
34  g->Draw("SAME");
35 
36  return g;
37 }
38 
40 {
41  vector<Double_t> x( ARRAYSIZE );
42  vector<Double_t> yb( ARRAYSIZE );
43  vector<Double_t> ymb( ARRAYSIZE );
44 
45  int status = 0;
46 
47  double b = 0.2, a= 0.9;
48  cout << "** b = " << b << " **" << endl;
49  unsigned int index = 0;
50  for ( double i = MIN; i < MAX; i += INCREMENT )
51  {
52  if (verbose) {
53  cout << "i:"; cout.width(5); cout << i
54  << " index: "; cout.width(5); cout << index
55  << " TMath::BetaIncomplete(x,a,b): "; cout.width(10); cout << TMath::BetaIncomplete(i,a,b)
56  << " ROOT::Math::inc_beta(a,a,b): "; cout.width(10); cout << ROOT::Math::inc_beta(i,a,b)
57  << endl;
58  }
59 
60  x[index] = i;
61 
62  yb[index] = TMath::BetaIncomplete(i,a,b);
63  ymb[index] = ROOT::Math::inc_beta(i,a,b);
64  if ( std::fabs( yb[index] - ymb[index] ) > ERRORLIMIT )
65  {
66  cout << "i " << i
67  << " yb[index] " << yb[index]
68  << " ymb[index] " << ymb[index]
69  << " " << std::fabs( yb[index] - ymb[index] )
70  << endl;
71  status += 1;
72  }
73  index += 1;
74  }
75 
76  if ( showGraphics )
77  {
78 
79  TCanvas* c1 = new TCanvas("c1", "Two Graphs", 600, 400);
80  TH2F* hpx = new TH2F("hpx", "Two Graphs(hpx)", ARRAYSIZE, MIN, MAX, ARRAYSIZE, 0, 5);
81  hpx->SetStats(kFALSE);
82  hpx->Draw();
83 
84  int color = 2;
85 
86  TGraph *gb, *gmb;
87  gb = drawPoints(&x[0], &yb[0], color++);
88  gmb = drawPoints(&x[0], &ymb[0], color++, 7);
89 
90  TLegend* legend = new TLegend(0.61,0.72,0.86,0.86);
91  legend->AddEntry(gb, "TMath::BetaIncomplete()");
92  legend->AddEntry(gmb, "ROOT::Math::inc_beta()");
93  legend->Draw();
94 
95  c1->Show();
96  }
97 
98  cout << "Test Done!" << endl;
99 
100  return status;
101 }
102 
103 int main(int argc, char **argv)
104 {
105  // Parse command line arguments
106  for (Int_t i=1 ; i<argc ; i++) {
107  std::string arg = argv[i] ;
108  if (arg == "-g") {
109  showGraphics = true;
110  }
111  if (arg == "-v") {
112  showGraphics = true;
113  verbose = true;
114  }
115  if (arg == "-h") {
116  cerr << "Usage: " << argv[0] << " [-g] [-v]\n";
117  cerr << " where:\n";
118  cerr << " -g : graphics mode\n";
119  cerr << " -v : verbose mode";
120  cerr << endl;
121  return -1;
122  }
123  }
124 
125  TApplication* theApp = 0;
126  if ( showGraphics )
127  theApp = new TApplication("App",&argc,argv);
128 
129  int status = testSpecFuncBetaI();
130 
131  if ( showGraphics )
132  {
133  theApp->Run();
134  delete theApp;
135  theApp = 0;
136  }
137 
138  return status;
139 }
virtual void SetLineWidth(Width_t lwidth)
Definition: TAttLine.h:57
This class displays a legend box (TPaveText) containing several legend entries.
Definition: TLegend.h:35
int main(int argc, char **argv)
THist< 2, float > TH2F
Definition: THist.h:321
TCanvas * c1
Definition: legend1.C:2
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition: TLegend.cxx:373
double inc_beta(double x, double a, double b)
Calculates the normalized (regularized) incomplete beta function.
int Int_t
Definition: RtypesCore.h:41
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
TLegend * legend
Definition: pirndm.C:35
Double_t x[n]
Definition: legend1.C:17
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
const double MAX
const double ERRORLIMIT
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
Double_t E()
Definition: TMath.h:54
The Canvas class.
Definition: TCanvas.h:48
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
TGraph * drawPoints(Double_t x[], Double_t y[], int color, int style=1)
const double MIN
TCanvas * style()
Definition: style.C:1
Double_t y[n]
Definition: legend1.C:17
const int ARRAYSIZE
virtual void SetLineStyle(Style_t lstyle)
Definition: TAttLine.h:56
const double INCREMENT
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
void Show()
Definition: TCanvas.h:228
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45
int testSpecFuncBetaI()
Double_t BetaIncomplete(Double_t x, Double_t a, Double_t b)
Calculates the incomplete Beta-function.
Definition: TMath.cxx:2064
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8320