# TSpline3 and TF1

Dear all,
I created a graph out of an histogram and then I fitted the graph with a cubic Spline3. Now I would like to use the spline to find the x value (abscissa), once the y is given. For the functions TF1 such method is called GetX, but for TSpline3 it does not exist. I think a solution is to define a function using the spline I created, but I could not do it. Could please someone help me? I tried the following but it does not work:

// graph creation from histogram h1
TGraph *gr1;

``````double t[nbins];
double z[nbins];
for (int i=0;i<=nbins;i++) {
t[i] = h1->GetBinCenter(i);
z[i] = h1->GetBinContent(i);
}
``````

// use a cubic spline to smooth the graph
TSpline3 *s = new TSpline3(“grs”,gr1);
s->SetLineColor(kRed);
s->Draw(“same”);
h1->Draw(“same”);

// attempt to create a function using the spline s
double_t xxx;

TF1 *fInterpolator = new TF1(“fInterpolator”, s->Eval(xxx), h1->GetBinCenter(1), h1->GetBinCenter(nbins));

Regards,

Andrea

If I understand correctly, you filled a TGraph w/ y vs x, and you want a way to look up x given y. Why not just fill the TGraph as x vs y (flip the order of x and y when putting the data into the TGraph), and use an “Eval” to look up x? i.e. x=graph->Eval(y) ?

what if inverting doesn’t work as the result is not a function? (there is a set of the same y values for different x, if i invert then get different x values for the same x so spline fit fails!)…?

I have the same issue here - how do I get X given Y from a TSpline3 ?

There may be multiple solutions.

I would investigate `TSpline3::GetCoeff`.