Created
April 6, 2011 16:01
-
-
Save mgmarino/905920 to your computer and use it in GitHub Desktop.
How to make a TF1 that calls to python code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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