normalDist.C

Go to the documentation of this file.
00001 // tutorial illustrating the new statistical  distributions functions (pdf, cdf and quantile) 
00002 
00003 #ifndef __CINT__
00004 #include "Math/DistFunc.h"
00005 #include "TF1.h"
00006 #include "TCanvas.h"
00007 #include "TSystem.h"
00008 #include "TLegend.h"
00009 #include "TAxis.h"
00010 #endif
00011 
00012 
00013 
00014 void normalDist() { 
00015 
00016 #ifdef __CINT__
00017    gSystem->Load("libMathCore");
00018    gSystem->Load("libMathMore");
00019 #endif
00020 
00021    TF1 *pdfunc  = new TF1("pdf","ROOT::Math::normal_pdf(x, [0],[1])",-5,5);
00022    TF1 *cdfunc  = new TF1("cdf","ROOT::Math::normal_cdf(x, [0],[1])",-5,5);
00023    TF1 *ccdfunc = new TF1("cdf_c","ROOT::Math::normal_cdf_c(x, [0])",-5,5);
00024    TF1 *qfunc   = new TF1("quantile","ROOT::Math::normal_quantile(x, [0])",0,1);
00025    TF1 *cqfunc  = new TF1("quantile_c","ROOT::Math::normal_quantile_c(x, [0])",0,1);
00026 
00027    pdfunc->SetParameters(1.0,0.0);  // set sigma to 1 and mean to zero
00028    pdfunc->SetTitle("");
00029    pdfunc->SetLineColor(kBlue);
00030 
00031    pdfunc->GetXaxis()->SetLabelSize(0.06);
00032    pdfunc->GetXaxis()->SetTitle("x");
00033    pdfunc->GetXaxis()->SetTitleSize(0.07);
00034    pdfunc->GetXaxis()->SetTitleOffset(0.55);
00035    pdfunc->GetYaxis()->SetLabelSize(0.06);
00036  
00037 
00038 
00039 
00040 
00041    cdfunc->SetParameters(1.0,0.0);  // set sigma to 1 and mean to zero
00042    cdfunc->SetTitle("");
00043    cdfunc->SetLineColor(kRed);
00044 
00045    cdfunc->GetXaxis()->SetLabelSize(0.06);
00046    cdfunc->GetXaxis()->SetTitle("x");
00047    cdfunc->GetXaxis()->SetTitleSize(0.07);
00048    cdfunc->GetXaxis()->SetTitleOffset(0.55);
00049    
00050    cdfunc->GetYaxis()->SetLabelSize(0.06);
00051    cdfunc->GetYaxis()->SetTitle("p");
00052    cdfunc->GetYaxis()->SetTitleSize(0.07);
00053    cdfunc->GetYaxis()->SetTitleOffset(0.55);
00054  
00055    ccdfunc->SetParameters(1.0,0.0);  // set sigma to 1 and mean to zero
00056    ccdfunc->SetTitle("");
00057    ccdfunc->SetLineColor(kGreen);
00058 
00059    qfunc->SetParameter(0, 1.0);  // set sigma to 1 
00060    qfunc->SetTitle("");
00061    qfunc->SetLineColor(kRed);
00062    qfunc->SetNpx(1000); // to get more precision for p close to 0 or 1
00063 
00064    qfunc->GetXaxis()->SetLabelSize(0.06);
00065    qfunc->GetXaxis()->SetTitle("p");
00066    qfunc->GetYaxis()->SetLabelSize(0.06);
00067    qfunc->GetXaxis()->SetTitleSize(0.07);
00068    qfunc->GetXaxis()->SetTitleOffset(0.55);
00069    qfunc->GetYaxis()->SetTitle("x");
00070    qfunc->GetYaxis()->SetTitleSize(0.07);
00071    qfunc->GetYaxis()->SetTitleOffset(0.55);
00072 
00073    cqfunc->SetParameter(0, 1.0);  // set sigma to 1 
00074    cqfunc->SetTitle("");
00075    cqfunc->SetLineColor(kGreen);
00076    cqfunc->SetNpx(1000); 
00077    
00078 
00079    TCanvas * c1 = new TCanvas("c1","Normal Distributions",100,10,600,800);
00080 
00081    c1->Divide(1,3);
00082    c1->cd(1);
00083 
00084    pdfunc->Draw();
00085    TLegend *legend1 = new TLegend(0.583893,0.601973,0.885221,0.854151);
00086    legend1->AddEntry(pdfunc,"normal_pdf","l");
00087    legend1->Draw();
00088 
00089    c1->cd(2);
00090    cdfunc->Draw();
00091    ccdfunc->Draw("same");
00092    TLegend *legend2 = new TLegend(0.585605,0.462794,0.886933,0.710837);
00093    legend2->AddEntry(cdfunc,"normal_cdf","l");
00094    legend2->AddEntry(ccdfunc,"normal_cdf_c","l");
00095    legend2->Draw();
00096 
00097    c1->cd(3);
00098    qfunc->Draw();
00099    cqfunc->Draw("same");
00100    TLegend *legend3 = new TLegend(0.315094,0.633668,0.695179,0.881711);
00101    legend3->AddEntry(qfunc,"normal_quantile","l");
00102    legend3->AddEntry(cqfunc,"normal_quantile_c","l");
00103    legend3->Draw();
00104 
00105 
00106    
00107 }

Generated on Tue Jul 5 15:44:50 2011 for ROOT_528-00b_version by  doxygen 1.5.1