ATLAS Offline Software
Loading...
Searching...
No Matches
python.rebin2 Namespace Reference

Functions

 rebin2 (h, name, gx=1, gy=1)

Function Documentation

◆ rebin2()

python.rebin2.rebin2 ( h,
name,
gx = 1,
gy = 1 )
Rebin the 2D histogram H.
Use NAME for the new histogram.
Group together GX bins in x and GY bins in y.

Definition at line 14 of file rebin2.py.

14def rebin2 (h, name, gx=1, gy=1):
15 """Rebin the 2D histogram H.
16Use NAME for the new histogram.
17Group together GX bins in x and GY bins in y.
18"""
19 old_nx = h.GetNbinsX()
20 old_ny = h.GetNbinsY()
21 new_nx = old_nx//gx
22 new_ny = old_ny//gy
23 hnew = ROOT.TH2F (name,
24 h.GetTitle(),
25 new_nx,
26 h.GetXaxis().GetXmin(),
27 h.GetXaxis().GetXmax(),
28 new_ny,
29 h.GetYaxis().GetXmin(),
30 h.GetYaxis().GetXmax())
31 for ix in range(0, new_nx):
32 for iy in range(0, new_ny):
33 sum = 0
34 for iix in range(0, gx):
35 for iiy in range(0, gy):
36 sum += h.GetBinContent(ix*gx+iix+1, iy*gy+iiy+1)
37 hnew.SetBinContent(ix+1, iy+1, sum)
38 return hnew
39