Skip to content

Commit 38a40f3

Browse files
committed
update all
1 parent 3adf4aa commit 38a40f3

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

rootplotlib/hist2d.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,38 @@
1111
import array
1212
import rootplotlib as rpl
1313
import ROOT
14+
import root_numpy
1415
import numpy as np
1516

1617

18+
def make_hist(name, xaxis_values, yaxis_values, xbins, xmin, xmax, ybins, ymin, ymax):
19+
'''
20+
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
21+
22+
Arguments:
23+
- root_histogram_name: the histogram name for ROOT
24+
- xaxis_values: the values to be used for fill x-axis
25+
- yaxis_values: the values to be used for fill y-axis
26+
- xbin_size: the x-axis bin size
27+
- ybin_size: the y-axis bin size
28+
- x_min: the minimum in x-axis
29+
- x_max: the maximum in x-axis
30+
- y_min: the minimum in y-axis
31+
- y_max: the maximum in y-axis
32+
'''
33+
34+
xbin_size = (xmax - xmin)/xbins
35+
ybin_size = (ymax - ymin)/ybins
36+
37+
# create the bin edges
38+
binx = np.arange(xmin, xmax, step=xbin_size)
39+
biny = np.arange(ymin, ymax, step=ybin_size)
40+
# create a numpy histogram2d
41+
H, xedges, yedges = np.histogram2d(x=xaxis_values, y=yaxis_values, bins=(binx, biny))
42+
# transform into a TH2F
43+
# create a TH2F to use
44+
hist = ROOT.TH2F( name, '', len(binx)-1, xmin, xmax, len(biny)-1, ymin, ymax)
45+
return root_numpy.array2hist(H, hist)
1746

1847
#
1948
# Create TH1F histogram
@@ -31,8 +60,6 @@ def new2( name, xbins, ybins, title=''):
3160
ybins = array.array('d', ybins)
3261
elif type(xbins) is np.array:
3362
ybins = array.array('d', ybins.tolist())
34-
print(xbins)
35-
print(ybins)
3663
return ROOT.TH2F(name, title, len(xbins)-1, xbins, len(ybins)-1, ybins)
3764

3865

0 commit comments

Comments
 (0)