11
11
import array
12
12
import rootplotlib as rpl
13
13
import ROOT
14
+ import root_numpy
14
15
import numpy as np
15
16
16
17
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 )
17
46
18
47
#
19
48
# Create TH1F histogram
@@ -31,8 +60,6 @@ def new2( name, xbins, ybins, title=''):
31
60
ybins = array .array ('d' , ybins )
32
61
elif type (xbins ) is np .array :
33
62
ybins = array .array ('d' , ybins .tolist ())
34
- print (xbins )
35
- print (ybins )
36
63
return ROOT .TH2F (name , title , len (xbins )- 1 , xbins , len (ybins )- 1 , ybins )
37
64
38
65
0 commit comments