00001 TCanvas *vC1;
00002 TGraph *grxy, *grin, *grout;
00003
00004 void approx()
00005 {
00006
00007
00008
00009
00010
00011
00012
00013
00014 Int_t n = 11;
00015 Double_t x[] = {1,2,3,4,5,6,6,6,8,9,10};
00016 Double_t y[] = {1,4,9,16,25,25,36,49,64,81,100};
00017 grxy = new TGraph(n,x,y);
00018
00019
00020 Int_t nout = 14;
00021 Double_t xout[] =
00022 {1.2,1.7,2.5,3.2,4.4,5.2,5.7,6.5,7.6,8.3,9.7,10.4,11.3,13};
00023
00024
00025 vC1 = new TCanvas("vC1","square",200,10,700,700);
00026 vC1->Divide(2,2);
00027
00028
00029 grin = new TGraph(n,x,y);
00030
00031 TGraphSmooth *gs = new TGraphSmooth("normal");
00032 grout = gs->Approx(grin,"linear");
00033 DrawSmooth(1,"Approx: ties = mean","X-axis","Y-axis");
00034
00035
00036
00037 grin = new TGraph(n,x,y);
00038
00039 grout = gs->Approx(grin,"linear", 14, xout, 0, 130);
00040 DrawSmooth(2,"Approx: ties = mean","","");
00041
00042
00043 Int_t vNout = grout->GetN();
00044 Double_t vXout, vYout;
00045 for (Int_t k=0;k<vNout;k++) {
00046 grout->GetPoint(k, vXout, vYout);
00047 cout << "k= " << k << " vXout[k]= " << vXout
00048 << " vYout[k]= " << vYout << endl;
00049 }
00050
00051
00052 grin = new TGraph(n,x,y);
00053
00054
00055 grout = gs->Approx(grin,"constant", 50, 0, 0, 0, 1, 0.5, "min");
00056 DrawSmooth(3,"Approx: ties = min","","");
00057
00058
00059 grin = new TGraph(n,x,y);
00060
00061 grout = gs->Approx(grin,"linear", 14, xout, 0, 0, 2, 0, "max");
00062 DrawSmooth(4,"Approx: ties = max","","");
00063
00064
00065 delete gs;
00066 }
00067
00068 void DrawSmooth(Int_t pad, const char *title, const char *xt,
00069 const char *yt)
00070 {
00071 vC1->cd(pad);
00072 TH1F *vFrame = gPad->DrawFrame(0,0,15,150);
00073 vFrame->SetTitle(title);
00074 vFrame->SetTitleSize(0.2);
00075 vFrame->SetXTitle(xt);
00076 vFrame->SetYTitle(yt);
00077 grxy->SetMarkerColor(kBlue);
00078 grxy->SetMarkerStyle(21);
00079 grxy->SetMarkerSize(0.5);
00080 grxy->Draw("P");
00081 grin->SetMarkerColor(kRed);
00082 grin->SetMarkerStyle(5);
00083 grin->SetMarkerSize(0.7);
00084 grin->Draw("P");
00085 grout->DrawClone("LP");
00086 }
00087