testSpecFuncBetaI.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <vector>
00004 
00005 #include <cmath>
00006 
00007 #include <TMath.h>
00008 #include <Math/SpecFunc.h>
00009 
00010 #include <TApplication.h>
00011 
00012 #include <TCanvas.h>
00013 #include <TH2F.h>
00014 #include <TGraph.h>
00015 #include <TLegend.h>
00016 
00017 const double ERRORLIMIT = 1E-8;
00018 const double MIN = 0;
00019 const double MAX = 1;
00020 const double INCREMENT = 0.01;
00021 const int ARRAYSIZE = (int) (( MAX - MIN ) / INCREMENT) + 1;
00022 
00023 bool showGraphics = true;
00024 
00025 using namespace std;
00026 
00027 TGraph* drawPoints(Double_t x[], Double_t y[], int color, int style = 1)
00028 {
00029    TGraph* g = new TGraph(ARRAYSIZE, x, y);
00030    g->SetLineColor(color);
00031    g->SetLineStyle(style);
00032    g->SetLineWidth(3);
00033    g->Draw("SAME");
00034 
00035    return g;
00036 }
00037 
00038 int testSpecFuncBetaI() 
00039 {
00040    vector<Double_t> x( ARRAYSIZE );
00041    vector<Double_t> yb( ARRAYSIZE );
00042    vector<Double_t> ymb( ARRAYSIZE );
00043 
00044    int status = 0;
00045 
00046    double b = 0.2, a= 0.9;
00047    cout << "** b = " << b << " **" << endl;
00048    unsigned int index = 0;
00049    for ( double i = MIN; i < MAX; i += INCREMENT )
00050    {
00051 //       cout << "i:"; cout.width(5); cout << i 
00052 //            << " index: "; cout.width(5); cout << index 
00053 //            << " TMath::BetaIncomplete(x,a,b): "; cout.width(10); cout << TMath::BetaIncomplete(i,a,b)
00054 //            << " ROOT::Math::inc_beta(a,a,b): "; cout.width(10); cout << ROOT::Math::inc_beta(i,a,b)
00055 //            << endl;
00056       
00057       x[index] = i;
00058 
00059       yb[index] = TMath::BetaIncomplete(i,a,b);
00060       ymb[index] = ROOT::Math::inc_beta(i,a,b);
00061       if ( std::fabs( yb[index] - ymb[index] ) > ERRORLIMIT )
00062       {
00063          cout << "i " << i   
00064               << " yb[index] " << yb[index]
00065               << " ymb[index] " << ymb[index]
00066               << " " << std::fabs( yb[index] - ymb[index] )
00067               << endl;
00068          status += 1;
00069       }
00070       index += 1;
00071    }
00072 
00073    if ( showGraphics )
00074    {
00075 
00076       TCanvas* c1 = new TCanvas("c1", "Two Graphs", 600, 400); 
00077       TH2F* hpx = new TH2F("hpx", "Two Graphs(hpx)", ARRAYSIZE, MIN, MAX, ARRAYSIZE, 0, 5);
00078       hpx->SetStats(kFALSE);
00079       hpx->Draw();
00080       
00081       int color = 2;
00082       
00083       TGraph *gb, *gmb;
00084       gb = drawPoints(&x[0], &yb[0], color++);
00085       gmb = drawPoints(&x[0], &ymb[0], color++, 7);
00086       
00087       TLegend* legend = new TLegend(0.61,0.72,0.86,0.86);
00088       legend->AddEntry(gb, "TMath::BetaIncomplete()");
00089       legend->AddEntry(gmb, "ROOT::Math::inc_beta()");
00090       legend->Draw();
00091       
00092       c1->Show();
00093    }
00094 
00095    cout << "Test Done!" << endl;
00096 
00097    return status;
00098 }
00099 
00100 int main(int argc, char **argv) 
00101 {
00102    if ( argc > 1 && argc != 2 )
00103    {
00104       cerr << "Usage: " << argv[0] << " [-ng]\n";
00105       cerr << "  where:\n";
00106       cerr << "     -ng : no graphics mode";
00107       cerr << endl;
00108       exit(1);
00109    }
00110 
00111    if ( argc == 2 && strcmp( argv[1], "-ng") == 0 ) 
00112    {
00113       showGraphics = false;
00114    }
00115 
00116    TApplication* theApp = 0;
00117    if ( showGraphics )
00118       theApp = new TApplication("App",&argc,argv);
00119 
00120    int status = testSpecFuncBetaI();
00121 
00122    if ( showGraphics )
00123    {
00124       theApp->Run();
00125       delete theApp;
00126       theApp = 0;
00127    }
00128 
00129    return status;
00130 }

Generated on Tue Jul 5 14:34:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1