Dear experts,
I am trying to use spline inside a workspace. This seems to be quite difficult since:
- There is no support for spline in RooFit. It should not be a big deal since they can be defined as TF1
- The only implementation I know is TSpline and derived class but TSpline is not a TF1, why?
I am running this code
from array import array
class Function:
def __init__(self, x, y):
f = ROOT.TSpline3("spline", x, y, len(x))
self.f = f
def __call__(self, x, par=None):
x = x[0]
y = self.f.Eval(x)
return y
x = array('d', [1, 3, 5])
y = array('d', [1, 6, 9])
f = ROOT.TF1("f_efficiency", Function(x, y), min(x), max(x), 0)
mass = ROOT.RooRealVar("mass", "mass", min(x), max(x))
fr = ROOT.RooFit.bindFunction(f, mass)
ws = ROOT.RooWorkspace('ws')
getattr(ws, 'import')(f)
getattr(ws, 'import')(fr)
ws.writeToFile('w.root')
With ROOT 5 and 6 it crashed when closing the file. With ROOT 6.04 (but not ROOT 6.02 and not ROOT 5) I am able to reopen the file and use the workspace.
- Am I doing something wrong?
- Is there an easier way to do it?