ATLAS Offline Software
PhysicsAnalysis
PyAnalysis
PyAnalysisUtils
python
rebin2.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2
3
#
4
# $Id: rebin2.py,v 1.1 2005-05-09 17:15:59 ssnyder Exp $
5
# File: rebin2.py
6
# Created: sss, 2004.
7
# Purpose: Rebin a 2D histogram.
8
#
9
10
from
builtins
import
range
11
import
ROOT
12
13
14
def
rebin2
(h, name, gx=1, gy=1):
15
"""Rebin the 2D histogram H.
16
Use NAME for the new histogram.
17
Group 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
python.rebin2.rebin2
def rebin2(h, name, gx=1, gy=1)
Definition:
rebin2.py:14
plotBeamSpotVxVal.range
range
Definition:
plotBeamSpotVxVal.py:195
Generated on Sun Dec 22 2024 21:16:59 for ATLAS Offline Software by
1.8.18