00001 #include "TString.h"
00002 #include "TInterpreter.h"
00003 #include <fstream>
00004 #include "TH1.h"
00005 #include "TGraphSmooth.h"
00006 #include "TCanvas.h"
00007 #include "TSystem.h"
00008
00009
00010 TCanvas *vC1;
00011 TGraph *grin, *grout;
00012
00013 void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt)
00014 {
00015 vC1->cd(pad);
00016 TH1F *vFrame = gPad->DrawFrame(0,-130,60,70);
00017 vFrame->SetTitle(title);
00018 vFrame->SetTitleSize(0.2);
00019 vFrame->SetXTitle(xt);
00020 vFrame->SetYTitle(yt);
00021 grin->Draw("P");
00022 grout->DrawClone("LPX");
00023 }
00024
00025
00026 void motorcycle()
00027 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00045 dir.ReplaceAll("motorcycle.C","");
00046 dir.ReplaceAll("/./","/");
00047
00048
00049 Double_t *x = new Double_t[133];
00050 Double_t *y = new Double_t[133];
00051 Double_t vX, vY;
00052 Int_t vNData = 0;
00053 ifstream vInput;
00054 vInput.open(Form("%smotorcycle.dat",dir.Data()));
00055 while (1) {
00056 vInput >> vX >> vY;
00057 if (!vInput.good()) break;
00058 x[vNData] = vX;
00059 y[vNData] = vY;
00060 vNData++;
00061 }
00062 vInput.close();
00063 grin = new TGraph(vNData,x,y);
00064
00065
00066 vC1 = new TCanvas("vC1","Smooth Regression",200,10,900,700);
00067 vC1->Divide(2,3);
00068
00069
00070
00071 TGraphSmooth *gs = new TGraphSmooth("normal");
00072 grout = gs->SmoothKern(grin,"normal",2.0);
00073 DrawSmooth(1,"Kernel Smoother: bandwidth = 2.0","times","accel");
00074
00075
00076 grout = gs->SmoothKern(grin,"normal",5.0);
00077 DrawSmooth(2,"Kernel Smoother: bandwidth = 5.0","","");
00078
00079
00080
00081 grout = gs->SmoothLowess(grin,"",0.67);
00082 DrawSmooth(3,"Lowess: f = 2/3","","");
00083
00084
00085 grout = gs->SmoothLowess(grin,"",0.2);
00086 DrawSmooth(4,"Lowess: f = 0.2","","");
00087
00088
00089
00090 grout = gs->SmoothSuper(grin,"",0,0);
00091 DrawSmooth(5,"Super Smoother: bass = 0","","");
00092
00093
00094 grout = gs->SmoothSuper(grin,"",3);
00095 DrawSmooth(6,"Super Smoother: bass = 3","","");
00096
00097
00098 delete [] x;
00099 delete [] y;
00100 delete gs;
00101 }
00102