I do simple TSpline to TGraph points in pyroot like,
spline = ROOT.TSpline3(“name”, Graph)
and then easily get values for some x:
for x in LIST: spline.Eval(x)
But now I want this TSpline as TF1 object so I can integrate and do other stuff;
The simple
fit = TF1( “fit”, spline, 0.1, 2.95)
Graph.Fit(“fit”)
Doesn’t work for me; I know the number of parameters is missing in fit, but this wouldn’t mean anything since its a spline not a user-defined function!
a fit is a procedure with which you extract the “best” value for the parameters of your model as well as their uncertainties. In your case you are trying to fit a spline to your data, without having parameters. In some sense the procedure is not well defined.
What are you really trying to achieve?
if one runs this in pyroot this works; TSpline fits the TGraph and one can get then any point from Eval; Now, you can not Integrate the TSpline but I need here a TF1 object
With PyROOT, you can construct TF1 objects from Python callables. In C++, one of the overloads of the TF1 constructor has this signature: TF1 (const char *name, Double_t(*fcn)(Double_t *, Double_t *), Double_t xmin=0, Double_t xmax=1, Int_t npar=0, Int_t ndim=1, EAddToList addToGlobList=EAddToList::kDefault)
So the function it expects has two parameters which are double arrays. See for instance this example:
and here:
What you could do is wrap your TSpline3 in a python function def mywrapper(x, p): ... that uses the TSpline3.