Smooth TGraph

I would like to smooth 1D TGraph - remove higher frequencies.
(chopt=“C” is not what I am asking for)

There is a TGraph::Smooth(Int_t npoints, Double_t* x, Double_t* y, Int_t drawtype)
but it’s not clear to me how to use it. Is there any example?

You can use a spline function. see example below.


void gspline() {
   TCanvas *c1 = new TCanvas("c1","gerrors2",200,10,700,500);
   const Int_t n = 10;
   Double_t x[]  = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
   Double_t y[]  = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};

   TGraph *gr = new TGraph(n,x,y);
   TSpline3 *s3 = new TSpline3("s3",gr->GetX(),gr->GetY(),gr->GetN());
   s3->Draw("l same");

Spline doesn’t remove higher frequencies, it goes through the data points.
I wanted to have a smooth curve which removes “jumpy” points like a Fourrier filter. I guess the TGraph::Smooth function does something like that, doesn’t it?

If you can put your data in form of histogram you can use TH1::Smooth.
See also class TSpectrum::Smooth