Skip to content

Commit

Permalink
update all
Browse files Browse the repository at this point in the history
  • Loading branch information
jodafons committed Dec 16, 2021
1 parent 3adf4aa commit 38a40f3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions rootplotlib/hist2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,38 @@
import array
import rootplotlib as rpl
import ROOT
import root_numpy
import numpy as np


def make_hist(name, xaxis_values, yaxis_values, xbins, xmin, xmax, ybins, ymin, ymax):
'''
This function will fill a 2D histogram faster than in ROOT and them transform the object into a TH2F in order to make the fit
Arguments:
- root_histogram_name: the histogram name for ROOT
- xaxis_values: the values to be used for fill x-axis
- yaxis_values: the values to be used for fill y-axis
- xbin_size: the x-axis bin size
- ybin_size: the y-axis bin size
- x_min: the minimum in x-axis
- x_max: the maximum in x-axis
- y_min: the minimum in y-axis
- y_max: the maximum in y-axis
'''

xbin_size = (xmax - xmin)/xbins
ybin_size = (ymax - ymin)/ybins

# create the bin edges
binx = np.arange(xmin, xmax, step=xbin_size)
biny = np.arange(ymin, ymax, step=ybin_size)
# create a numpy histogram2d
H, xedges, yedges = np.histogram2d(x=xaxis_values, y=yaxis_values, bins=(binx, biny))
# transform into a TH2F
# create a TH2F to use
hist = ROOT.TH2F( name, '', len(binx)-1, xmin, xmax, len(biny)-1, ymin, ymax)
return root_numpy.array2hist(H, hist)

#
# Create TH1F histogram
Expand All @@ -31,8 +60,6 @@ def new2( name, xbins, ybins, title=''):
ybins = array.array('d', ybins)
elif type(xbins) is np.array:
ybins = array.array('d', ybins.tolist())
print(xbins)
print(ybins)
return ROOT.TH2F(name, title, len(xbins)-1, xbins, len(ybins)-1, ybins)


Expand Down

0 comments on commit 38a40f3

Please sign in to comment.