testSpecFuncBeta.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 = -2.5;
00019 const double MAX = +2.5;
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 testSpecFuncBeta() 
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    int color = 2;
00047    TGraph *gb, *gmb;
00048    TCanvas* c1 = new TCanvas("c1", "BetaFunction", 600, 400); 
00049    TH2F* hpx;
00050    {   
00051       hpx = new TH2F("hpx", "BetaFunction(p,b)", ARRAYSIZE, MIN, MAX, ARRAYSIZE, 0, 5);
00052       hpx->SetStats(kFALSE);
00053       hpx->Draw();
00054    }
00055 
00056    for ( double b = 0.9; b < 2; b+=0.4)
00057    {
00058       cout << "** b = " << b << " **" << endl;
00059       unsigned int index = 0;
00060       for ( double i = MIN; i < MAX; i += INCREMENT )
00061       {
00062 //          cout << "i:"; cout.width(5); cout << i 
00063 //                     << " index: "; cout.width(5); cout << index 
00064 //                     << " TMath::Beta(p,b): "; cout.width(10); cout << TMath::Beta(i,b)
00065 //                     << " ROOT::Math::beta(p,b): "; cout.width(10); cout << ROOT::Math::beta(i,b)
00066 //                     << endl;
00067          
00068          x[index] = i;
00069          yb[index] = TMath::Beta(i,b);
00070          ymb[index] = ROOT::Math::beta(i,b);
00071          if ( std::fabs( yb[index] - ymb[index] ) > ERRORLIMIT )
00072          {
00073             cout << "i " << i
00074                  << " b " << b
00075                  << " yb[index] " << yb[index]
00076                  << " ymb[index] " << ymb[index]
00077                  << " " << std::fabs( yb[index] - ymb[index] )
00078                  << endl;
00079             status += 1;
00080          }
00081          index += 1;
00082       }
00083       
00084       gb = drawPoints(&x[0], &yb[0], color++);
00085       gmb = drawPoints(&x[0], &ymb[0], color++, 7);
00086    }
00087 
00088    if ( showGraphics )
00089    {  
00090       TLegend* legend = new TLegend(0.61,0.72,0.86,0.86);
00091       legend->AddEntry(gb, "TMath::Beta()");
00092       legend->AddEntry(gmb, "ROOT::Math::beta()");
00093       legend->Draw();
00094       
00095       c1->Show();
00096    }
00097 
00098    cout << "Test Done!" << endl;
00099 
00100    return status;
00101 }
00102 
00103 int main(int argc, char **argv) 
00104 {
00105    if ( argc > 1 && argc != 2 )
00106    {
00107       cerr << "Usage: " << argv[0] << " [-ng]\n";
00108       cerr << "  where:\n";
00109       cerr << "     -ng : no graphics mode";
00110       cerr << endl;
00111       exit(1);
00112    }
00113 
00114    if ( argc == 2 && strcmp( argv[1], "-ng") == 0 ) 
00115    {
00116       showGraphics = false;
00117    }
00118 
00119    TApplication* theApp = 0;
00120    if ( showGraphics )
00121       theApp = new TApplication("App",&argc,argv);
00122 
00123    int status = testSpecFuncBeta();
00124 
00125    if ( showGraphics )
00126    {
00127       theApp->Run();
00128       delete theApp;
00129       theApp = 0;
00130    }
00131 
00132    return status;
00133 }

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