Pyroot : FillRandom method with complicated function


is there a way to fill a histogram with the FillRandom method if the function involved is not as simple as in the example below? I am thinking of something like :

def func(x, y, p1, p2 , p3 …, pn):
return z = …

where func is given to a TF2 object
xy = TF2( ‘xy’, ‘func’, x0, x1, y0, y1)

Do you have any suggestions?

Example of working code used above in the text:
# Upper and lower bounds of the 2D histogram and the 2D function:
x0 = 0.
x1 = 100.
y0 = 0.
y1 = 100.

# Simple 2D function to fill the histogram :
xy = TF2( ‘xy’, ‘(x*y)’, x0, x1, y0, y1)

# Create and fill histogram :
bin_no = 11
h3 = TH2D(“h3”, “fill the boxes”, bin_no, x0, x1, bin_no, y0, y1)
n_entries = 1000
h3.FillRandom(“xy”, n_entries)


FillRandom should work with any function provided by the user. The only requirements is that the integral of the function in each histogram bin can be computed

Best Regards



This should work:

def myfunc(x, y):
  return x*y

xy = TF2( 'xy', 'myfunc(x,y)', x0, x1, y0, y1)

Please note the parameter passing to myfunc in the constructor of TF2.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.