TSpline3 problems

Hi,

So I have a TGraph of about 60 points. And they are quite unsmooth in the region of my interest. I want to now get a smooth representation of this set of points. They are particularly unsmooth from x=20 to 50 say.

I tried gr->Draw(“ac”) and it only connects the dots; i.e., my scattered points.

So I tried Splining it as:
TSpline3 *spline3 = new TSpline3(“Test”,gr);
spline3->Draw(“c”);

This still follows exactly my scattered points.

How do I get TSpline or even some other method to draw a smooth curve through my points?

Can I ask TSpline to use more than 60 points? Perhaps 60*10 points or something like that for a smoother plot?

Thanks in advance!

  • Sujeewa
1 Like

Could you post the shortest possible RUNNING script reproducing your problem?

Rene

Hi Rene,

Here’s the code: I am also attaching the a gif of what the tgraph and the tspline look like when I run this code. I want the tgraph points to be connected via a smooth parabola, not in a un-smooth curve like it is doing now.

I see there’s some smoothening done, but not to the level I want it. Also I tried using TF1, but there are several different functions here so it is not trivial. Plus, this is just for representation, so I would like to get a parabolic fit without having to go through a complex TFit.

void ShowFitPlotsToPost()
{

TCanvas *cc2 = new TCanvas(“cc2”,“cc2”,100,100,400,400);

cc2->cd();
TFile *file93 = TFile::Open(“filMomTruthToROOT.root”);
TGraph filMomTruth = ((TGraph)(file93->Get(“filMomTruth”)));

filMomTruth->SetLineColor(kGreen);
filMomTruth->Draw(“ac”);
cc2->Update();

TSpline3 *spline4 = new TSpline3(“Test1”,filMomTruth);
spline4->SetLineColor(kRed+5);
spline4->Draw(“c same”);

//the next I think is the same as above, as it takes the individual points of the TGraph
TSpline3 *spline3 = new TSpline3(“Test”,filMomTruth->GetX(),filMomTruth->GetY(),filMomTruth->GetN());
spline3->SetLineColor(kRed-5);
spline3->Draw(“same”);

}

Thanks!

  • Sujeewa

You forgot to post your data file

Rene

oh sorry, here it is…
filMomTruthToROOT.root (4.44 KB)

If you run the following few lines of code on your data set you will see that the smoothing is correct. You have data points extremely close in x,y and smoothing has to go through all the points.
The alternative is to fit with a function of your choice.

Rene

[code]TFile *file93 = TFile::Open(“filMomTruthToROOT.root”);
TGraph filMomTruth = ((TGraph)(file93->Get(“filMomTruth”)));

filMomTruth->SetLineColor(kGreen);
filMomTruth->SetMarkerStyle(21);
filMomTruth->SetMaximum(0.25);
filMomTruth->SetMinimum(0.20);
filMomTruth->Set(32);
filMomTruth->SetHistogram(0);
filMomTruth->Draw(“alp”); [/code]

1 Like