00001
00002
00003
00004 #include "TH1.h"
00005 #include "TF1.h"
00006 #include "TKDE.h"
00007 #include "TCanvas.h"
00008
00009 #include "TRandom.h"
00010 #ifndef __CINT__
00011 #include "Math/DistFunc.h"
00012 #endif
00013 #include "TLegend.h"
00014
00015
00016
00017
00018
00019
00020 void exampleTKDE(int n = 1000) {
00021
00022
00023
00024
00025 int nbin = 100;
00026 double xmin = 0;
00027 double xmax = 10;
00028
00029 TH1D * h1 = new TH1D("h1","h1",nbin,xmin,xmax);
00030
00031
00032
00033 std::vector<double> data(n);
00034 for (int i = 0; i < n; ++i) {
00035 if (i < 0.4*n) {
00036 data[i] = gRandom->Gaus(2,1);
00037 h1->Fill(data[i]);
00038 }
00039 else {
00040 data[i] = gRandom->Gaus(7,1.5);
00041 h1->Fill(data[i]);
00042 }
00043 }
00044
00045
00046 h1->Scale(1./h1->Integral(),"width" );
00047 h1->SetStats(false);
00048 h1->SetTitle("Bi-Gaussian");
00049 h1->Draw();
00050
00051
00052 TF1 * f1 = new TF1("f1","0.4*ROOT::Math::normal_pdf(x,1,2)+0.6*ROOT::Math::normal_pdf(x,1.5,7)",xmin,xmax);
00053 f1->SetLineColor(kGreen+2);
00054 f1->Draw("SAME");
00055
00056
00057
00058
00059
00060 double rho = 1.0;
00061 TKDE * kde = new TKDE(n, &data[0], xmin,xmax, "", rho);
00062
00063 kde->Draw("SAME");
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 TLegend * legend = new TLegend(0.6,0.7,0.9,0.95);
00089 legend->AddEntry(f1,"True function");
00090 legend->AddEntry(kde->GetDrawnFunction(),"TKDE");
00091 legend->AddEntry(kde->GetDrawnLowerFunction(),"TKDE - #sigma");
00092 legend->AddEntry(kde->GetDrawnUpperFunction(),"TKDE + #sigma");
00093 legend->Draw();
00094 return;
00095
00096 gPad->Update();
00097
00098
00099 }
00100