#include "TString.h"
#include "TInterpreter.h"
#include <fstream>
#include "TH1.h"
#include "TGraphSmooth.h"
#include "TCanvas.h"
#include "TSystem.h"
TCanvas *vC1;
TGraph *grin, *grout;
void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt)
{
vC1->cd(pad);
TH1F *vFrame = gPad->DrawFrame(0,-130,60,70);
vFrame->SetTitle(title);
vFrame->SetTitleSize(0.2);
vFrame->SetXTitle(xt);
vFrame->SetYTitle(yt);
grin->Draw("P");
grout->DrawClone("LPX");
}
void motorcycle()
{
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("motorcycle.C","");
dir.ReplaceAll("/./","/");
Double_t *x = new Double_t[133];
Double_t *y = new Double_t[133];
Double_t vX, vY;
Int_t vNData = 0;
ifstream vInput;
vInput.open(Form("%smotorcycle.dat",dir.Data()));
while (1) {
vInput >> vX >> vY;
if (!vInput.good()) break;
x[vNData] = vX;
y[vNData] = vY;
vNData++;
}
vInput.close();
grin = new TGraph(vNData,x,y);
vC1 = new TCanvas("vC1","Smooth Regression",200,10,900,700);
vC1->Divide(2,3);
TGraphSmooth *gs = new TGraphSmooth("normal");
grout = gs->SmoothKern(grin,"normal",2.0);
DrawSmooth(1,"Kernel Smoother: bandwidth = 2.0","times","accel");
grout = gs->SmoothKern(grin,"normal",5.0);
DrawSmooth(2,"Kernel Smoother: bandwidth = 5.0","","");
grout = gs->SmoothLowess(grin,"",0.67);
DrawSmooth(3,"Lowess: f = 2/3","","");
grout = gs->SmoothLowess(grin,"",0.2);
DrawSmooth(4,"Lowess: f = 0.2","","");
grout = gs->SmoothSuper(grin,"",0,0);
DrawSmooth(5,"Super Smoother: bass = 0","","");
grout = gs->SmoothSuper(grin,"",3);
DrawSmooth(6,"Super Smoother: bass = 3","","");
delete [] x;
delete [] y;
delete gs;
}
|
|