Simple spline does not work!


I do have a practical copy of the spline example, and it does not draw me a spline!

It does draw the TGraph within the correct area inside the canvas.
In general, this area is not very well-documented… If someone has examples of using splines to smooth the data from jitter etc., that will be most appreciated! Fitting is not really an option as the data spectra are rather chaotic set of peaks & dips :slight_smile:

Thanks, EG

[code]//=========================== spline.C ==================================
void spline(){

TCanvas *c1 = new TCanvas(“c1”,“spline”,100,80,800,600);

TGraphErrors *gr_test = new TGraphErrors(“data.txt”, “%lg %lg”, “gr_test”);
gr_test->Sort(); // test is just a set of x,y two columns, tab delimited.

//— make some dummy plot for the canvas to draw graph in
// I use 100 bins so I’d be able to zoom in later on by hand
TH2F *h_dummy = new TH2F(“h_dummy”,“Dummy Name”, 100, -20.,20., 100, 0., 120.);


TSpline3 *grs_test = new TSpline3(“grs_test”, gr_test);

h_dummy->Draw();// just a dummy to make output look pretty and within desired intervals x,y

gr_test ->Draw(“P same”); // Points in blue
grs_test->Draw(“L same”); // Should be spline line in red which is not there!

data.txt (17.5 KB)


   gr_test ->Draw("P same"); // Points in blue
   grs_test->Draw("L same"); // Should be spline line in red which is not 


   gr_test ->Draw("APL"); 

Did not do much good at all. I do not see the spline. Please try it.

I’ll check

I found the problem.

First of all you can write your macro in the following simple way (but that’s not the problem it is just simpler and cleaner):

void spline(){
   TCanvas *c1 = new TCanvas("c1","spline",100,80,800,600);
   TGraphErrors *gr_test  = new TGraphErrors("data.txt", "%lg %lg", "gr_test");
   TSpline3 *grs_test = new TSpline3("grs_test", gr_test);
   gr_test ->Draw("P");

The problem comes from your data file. I found out that you have 5 points (at the end of the file) aligned vertically:

12.5      2.38
12.5      2.23
12.5      2.22
12.5      2.23
12.5      2.21

Remove 4 of them an it will work. The spline algoritm seems to generate infinity with these 5 points.

Oh, wow! Thank you so very much! I should have tried it on a much simpler test file with full control of what’s going on… I really appreciate your help!

You’re welcome :slight_smile: