Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #42 from marinang/mm_th3
Browse files Browse the repository at this point in the history
Introduction of TH3
  • Loading branch information
jpivarski authored Feb 22, 2019
2 parents 8ef0109 + 92bc52a commit 3c54167
Show file tree
Hide file tree
Showing 2 changed files with 309 additions and 25 deletions.
52 changes: 27 additions & 25 deletions uproot_methods/classes/TH2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

# Copyright (c) 2019, IRIS-HEP
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Expand All @@ -28,13 +28,12 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import numbers
import sys

import numpy

import uproot_methods.base


class Methods(uproot_methods.base.ROOTMethods):
@property
def numbins(self):
Expand Down Expand Up @@ -75,8 +74,8 @@ def yhigh(self):
@property
def underflows(self):
uf = numpy.array(self.allvalues)
xuf = uf[:,0]
yuf = uf[0]
xuf = uf[0]
yuf = uf[:, 0]
return xuf, yuf

@property
Expand All @@ -90,8 +89,8 @@ def yunderflows(self):
@property
def overflows(self):
of = numpy.array(self.allvalues)
xof = of[:,-1]
yof = of[-1]
xof = of[-1]
yof = of[:, -1]
return xof, yof

@property
Expand Down Expand Up @@ -154,43 +153,46 @@ def allbins(self):
@property
def values(self):
va = self.allvalues
return va[1:self.ynumbins+1, 1:self.xnumbins+1]
return va[1:self.xnumbins+1, 1:self.ynumbins+1]

@property
def allvalues(self):
v = numpy.array(self[:], dtype=getattr(self, "_dtype", numpy.dtype(numpy.float64)).newbyteorder("="))
return v.reshape(self.ynumbins + 2, self.xnumbins + 2)
dtype = getattr(self, "_dtype", numpy.dtype(numpy.float64))
v = numpy.array(self[:], dtype=dtype.newbyteorder("="))
v = v.reshape(self.ynumbins + 2, self.xnumbins + 2)
return v.T

@property
def variances(self):
va = self.allvariances
return va[1:self.ynumbins+1, 1:self.xnumbins+1]
return va[1:self.xnumbins+1, 1:self.ynumbins+1]

@property
def allvariances(self):
if len(getattr(self, "_fSumw2", [])) != len(self):
v = numpy.array(self, dtype=numpy.float64)
else:
v = numpy.array(self._fSumw2, dtype=numpy.float64)
return v.reshape(self.ynumbins + 2, self.xnumbins + 2)
v = v.reshape(self.ynumbins + 2, self.xnumbins + 2)
return v.T

def numpy(self):
return (self.values,) + self.edges
return (self.values, [self.edges])

def allnumpy(self):
return (self.allvalues,) + self.alledges
return (self.allvalues, [self.alledges])

def interval(self, index, axis):
if axis == "x":
low = self.xlow
high = self.xhigh
low = self.xlow
high = self.xhigh
nbins = self.xnumbins
bins = self._fXaxis._fXbins
bins = self._fXaxis._fXbins
elif axis == "y":
low = self.ylow
high = self.yhigh
low = self.ylow
high = self.yhigh
nbins = self.ynumbins
bins = self._fYaxis._fXbins
bins = self._fYaxis._fXbins
else:
raise ValueError("axis must be 'x' or 'y'")

Expand All @@ -203,7 +205,7 @@ def interval(self, index, axis):
return high, float("inf")
else:
if not bins:
norm = float(high-low) / nbins
norm = float(high-low) / nbins
xedges = (index-1)*norm + low, index*norm + low
else:
xedges = bins[index-1], bins[index]
Expand Down
Loading

0 comments on commit 3c54167

Please sign in to comment.