Skip to content

Instantly share code, notes, and snippets.

@mgmarino
Created April 6, 2011 16:01
Show Gist options
  • Save mgmarino/905920 to your computer and use it in GitHub Desktop.
Save mgmarino/905920 to your computer and use it in GitHub Desktop.
How to make a TF1 that calls to python code
import ROOT
class PoissonClass:
def __init__(self, upper_range, tag = ''):
self.function = ROOT.TF1('py_poisson' + tag, self, 0, upper_range, 2)
self.function.SetParName(0, 'Overall Normalization')
self.function.SetParName(1, 'Lambda')
def __call__(self, x, par):
res = 0.0
xx = x[0]
if xx >= 0:
try:
res = par[0]*math.pow(par[1], xx)/\
(ROOT.TMath.Gamma(xx+1)*math.exp(par[1]))
except OverflowError:
return 0.0
return res
def get_TF1(self):
return self.function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment