Passing argument to a TF1 object for a TSpline3 build in function

_ROOT Version: 6.06 or even 5.34
Platform: Linux
Compiler: Not Provided


I made multiple fits using TSpline3 function; Then, since I needed the “X value given Y” I had to embed the spline into the TF1 object. For instance,

TF1* fit = new TF1("f_spline4", spline, 0, 8); 

Double_t spline(Double_t *x, Double_t* p) {

   Double_t xx = x[0];
   TSpline3* sp3 = new TSpline(......);

   return sp3->Eval(xx);

This works fine for a single case but have multiple TSpine3 fits; I went with a simple solution of iterating with a global variable, like,

TF1* fit[100];
vector<TF1*> Vfit; 

for (GlobalIter = 0; GlobalIter < N; GlobalIter++){

      fit[GlobalIter] = new TF1("f_spline4", spline_4nodes, 0, 8);


 Double_t spline_4nodes(Double_t *x, Double_t* p) {

   Double_t xx = x[0];
   TSpline3* sp3 = VecSpl[GlobalIter];
   return sp3->Eval(xx);

When I run this macro it sets GlobalIter to the last value “N” and actually calls the spline function in TF1 over > x100; I can send the full macro; I would appreciate your advice, thanks,


@moneta can help you with this.
Note also this howto explaining how to format a post. (I edited your post accordingly)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.