Using python functions into RooFit
Closed this issue · 1 comments
guiguem commented
The recommended method to use custom pdf is to use C++ and Phylloxera.
However it should be possible to bind a python function too.
Here is a nasty but working example on how to generate a RooFit pdf from a python function:
class RosenBrock(ROOT.TPyMultiGenFunction):
def __init__( self ):
print("CREATED")
ROOT.TPyMultiGenFunction.__init__( self, self )
def NDim( self ):
print('PYTHON NDim called')
return 2
def __call__(self,args):
x = args[0]
y = args[1];
tmp1 = y-x*x;
tmp2 = 1-x;
return 100*tmp1*tmp1+tmp2*tmp2;
if __name__ == "__main__":
rose = RosenBrock()
f = ROOT.TPyMultiGenFunction(rose)
x = ROOT.RooRealVar("x","x",0,10)
a = ROOT.RooRealVar("a","a",1,2)
fx = ROOT.RooFit.bindFunction("test",f, ROOT.RooArgList(x, a))
We should be able to adapt this to just need to import the function from the right module and integrate it into a RooFit processor.
guiguem commented
Solved in morpho morphoorg/morpho#141