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 #12 from scikit-hep/issue-override-jaggedarray-sum
Browse files Browse the repository at this point in the history
Issue override jaggedarray sum
  • Loading branch information
jpivarski authored Nov 28, 2018
2 parents 973fa35 + bb1a9af commit 158169a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion uproot_methods/classes/TLorentzVector.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,15 @@ def rotate_euler(self, phi=0, theta=0, psi=0):
def islightlike(self, tolerance=1e-10):
return awkward.util.numpy.absolute(self.mag2) < tolerance

def sum(self):
if isinstance(self, awkward.JaggedArray):
return TLorentzVectorArray.from_cartesian(self.x.sum(), self.y.sum(), self.z.sum(), self.t.sum())
else:
return TLorentzVector(self.x.sum(), self.y.sum(), self.z.sum(), self.t.sum())

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if method != "__call__":
raise NotImplemented
return NotImplemented

inputs = list(inputs)
for i in range(len(inputs)):
Expand Down
6 changes: 6 additions & 0 deletions uproot_methods/classes/TVector2.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def x(self):
def y(self):
return self["fY"]

def sum(self):
if isinstance(self, awkward.JaggedArray):
return TVector2Array.from_cartesian(self.x.sum(), self.y.sum())
else:
return TVector2(self.x.sum(), self.y.sum())

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if method != "__call__":
return NotImplemented
Expand Down
8 changes: 7 additions & 1 deletion uproot_methods/classes/TVector3.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,15 @@ def rotate_euler(self, phi=0, theta=0, psi=0):
out["fZ"] = z
return out

def sum(self):
if isinstance(self, awkward.JaggedArray):
return TVector3Array.from_cartesian(self.x.sum(), self.y.sum(), self.z.sum())
else:
return TVector3(self.x.sum(), self.y.sum(), self.z.sum())

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if method != "__call__":
raise NotImplemented
return NotImplemented

inputs = list(inputs)
for i in range(len(inputs)):
Expand Down
2 changes: 1 addition & 1 deletion uproot_methods/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import re

__version__ = "0.2.8"
__version__ = "0.2.9"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down

0 comments on commit 158169a

Please sign in to comment.