Skip to content

Commit

Permalink
feat: coordinate transformation functions with momentum names (#424)
Browse files Browse the repository at this point in the history
* feat: coordinate transformation functions with momentum names

* Add tests + cleanup

* Fix awkward tests
  • Loading branch information
Saransh-cpp authored Feb 21, 2024
1 parent 4cec27d commit 8493623
Show file tree
Hide file tree
Showing 3 changed files with 428 additions and 134 deletions.
200 changes: 200 additions & 0 deletions src/vector/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,27 @@ def to_xy(self) -> VectorProtocolPlanar:
"""
raise AssertionError

def to_pxpy(self) -> VectorProtocolPlanar:
"""
Converts to $px$-$py$ coordinates, possibly eliminating dimensions with a
projection.
"""
raise AssertionError

def to_rhophi(self) -> VectorProtocolPlanar:
r"""
Converts to $\rho$-$\phi$ coordinates, possibly eliminating dimensions with a
projection.
"""
raise AssertionError

def to_ptphi(self) -> VectorProtocolPlanar:
r"""
Converts to $pt$-$\phi$ coordinates, possibly eliminating dimensions with a
projection.
"""
raise AssertionError

def to_xyz(self) -> VectorProtocolSpatial:
"""
Converts to $x$-$y$-$z$ coordinates, possibly eliminating or imputing
Expand All @@ -234,6 +248,27 @@ def to_xyeta(self) -> VectorProtocolSpatial:
"""
raise AssertionError

def to_pxpypz(self) -> VectorProtocolSpatial:
"""
Converts to $px$-$py$-$pz$ coordinates, possibly eliminating or imputing
dimensions with a projection.
"""
raise AssertionError

def to_pxpytheta(self) -> VectorProtocolSpatial:
r"""
Converts to $px$-$py$-$\theta$ coordinates, possibly eliminating or imputing
dimensions with a projection.
"""
raise AssertionError

def to_pxpyeta(self) -> VectorProtocolSpatial:
r"""
Converts to $px$-$py$-$\eta$ coordinates, possibly eliminating or imputing
dimensions with a projection.
"""
raise AssertionError

def to_rhophiz(self) -> VectorProtocolSpatial:
r"""
Converts to $\rho$-$\phi$-$z$ coordinates, possibly eliminating or imputing
Expand All @@ -255,6 +290,27 @@ def to_rhophieta(self) -> VectorProtocolSpatial:
"""
raise AssertionError

def to_ptphipz(self) -> VectorProtocolSpatial:
r"""
Converts to $pt$-$\phi$-$pz$ coordinates, possibly eliminating or imputing
dimensions with a projection.
"""
raise AssertionError

def to_ptphitheta(self) -> VectorProtocolSpatial:
r"""
Converts to $pt$-$\phi$-$\theta$ coordinates, possibly eliminating or
imputing dimensions with a projection.
"""
raise AssertionError

def to_ptphieta(self) -> VectorProtocolSpatial:
r"""
Converts to $pt$-$\phi$-$\eta$ coordinates, possibly eliminating or
imputing dimensions with a projection.
"""
raise AssertionError

def to_xyzt(self) -> VectorProtocolLorentz:
"""
Converts to $x$-$y$-$z$-$t$ coordinates, possibly imputing dimensions with
Expand Down Expand Up @@ -297,6 +353,48 @@ def to_xyetatau(self) -> VectorProtocolLorentz:
"""
raise AssertionError

def to_pxpypzenergy(self) -> VectorProtocolLorentz:
r"""
Converts to $px$-$py$-$pz$-$energy$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_pxpythetaenergy(self) -> VectorProtocolLorentz:
r"""
Converts to $px$-$py$-$\theta$-$energy$ coordinates, possibly imputing
dimensions with a projection.
"""
raise AssertionError

def to_pxpyetaenergy(self) -> VectorProtocolLorentz:
r"""
Converts to $px$-$py$-$\eta$-$energy$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_pxpypzmass(self) -> VectorProtocolLorentz:
r"""
Converts to $px$-$py$-$pz$-$mass$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_pxpythetamass(self) -> VectorProtocolLorentz:
r"""
Converts to $px$-$py$-$\theta$-$energy$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_pxpyetamass(self) -> VectorProtocolLorentz:
r"""
Converts to $px$-$py$-$\eta$-$mass$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_rhophizt(self) -> VectorProtocolLorentz:
r"""
Converts to $\rho$-$\phi$-$z$-$t$ coordinates, possibly imputing dimensions
Expand Down Expand Up @@ -339,6 +437,48 @@ def to_rhophietatau(self) -> VectorProtocolLorentz:
"""
raise AssertionError

def to_ptphipzenergy(self) -> VectorProtocolLorentz:
r"""
Converts to $pt$-$\phi$-$pz$-$energy$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_ptphithetaenergy(self) -> VectorProtocolLorentz:
r"""
Converts to $pt$-$\phi$-$\theta$-$energy$ coordinates, possibly imputing
dimensions with a projection.
"""
raise AssertionError

def to_ptphietaenergy(self) -> VectorProtocolLorentz:
r"""
Converts to $pt$-$\phi$-$\eta$-$energy$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_ptphipzmass(self) -> VectorProtocolLorentz:
r"""
Converts to $pt$-$\phi$-$pz$-$mass$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_ptphithetamass(self) -> VectorProtocolLorentz:
r"""
Converts to $pt$-$\phi$-$\theta$-$mass$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def to_ptphietamass(self) -> VectorProtocolLorentz:
r"""
Converts to $pt$-$\phi$-$\theta$-$mass$ coordinates, possibly imputing dimensions
with a projection.
"""
raise AssertionError

def unit(self: SameVectorType) -> SameVectorType:
"""
Returns vector(s) normalized to unit length, which is `rho == 1` for 2D
Expand Down Expand Up @@ -2656,6 +2796,9 @@ def to_xy(self) -> VectorProtocolPlanar:
1,
)

def to_pxpy(self) -> VectorProtocolPlanar:
return self.to_xy()

def to_rhophi(self) -> VectorProtocolPlanar:
from vector._compute import planar

Expand All @@ -2666,6 +2809,9 @@ def to_rhophi(self) -> VectorProtocolPlanar:
1,
)

def to_ptphi(self) -> VectorProtocolPlanar:
return self.to_rhophi()

def to_xyz(self) -> VectorProtocolSpatial:
from vector._compute import planar, spatial

Expand Down Expand Up @@ -2708,6 +2854,15 @@ def to_xyeta(self) -> VectorProtocolSpatial:
1,
)

def to_pxpypz(self) -> VectorProtocolSpatial:
return self.to_xyz()

def to_pxpytheta(self) -> VectorProtocolSpatial:
return self.to_xytheta()

def to_pxpyeta(self) -> VectorProtocolSpatial:
return self.to_xyeta()

def to_rhophiz(self) -> VectorProtocolSpatial:
from vector._compute import planar, spatial

Expand Down Expand Up @@ -2750,6 +2905,15 @@ def to_rhophieta(self) -> VectorProtocolSpatial:
1,
)

def to_ptphipz(self) -> VectorProtocolSpatial:
return self.to_rhophiz()

def to_ptphitheta(self) -> VectorProtocolSpatial:
return self.to_rhophitheta()

def to_ptphieta(self) -> VectorProtocolSpatial:
return self.to_rhophieta()

def to_xyzt(self) -> VectorProtocolLorentz:
from vector._compute import lorentz, planar, spatial

Expand Down Expand Up @@ -2852,6 +3016,24 @@ def to_xyetatau(self) -> VectorProtocolLorentz:
1,
)

def to_pxpypzenergy(self) -> VectorProtocolLorentz:
return self.to_xyzt()

def to_pxpythetaenergy(self) -> VectorProtocolLorentz:
return self.to_xythetat()

def to_pxpyetaenergy(self) -> VectorProtocolLorentz:
return self.to_xyetat()

def to_pxpypzmass(self) -> VectorProtocolLorentz:
return self.to_xyztau()

def to_pxpythetamass(self) -> VectorProtocolLorentz:
return self.to_xythetatau()

def to_pxpyetamass(self) -> VectorProtocolLorentz:
return self.to_xyetatau()

def to_rhophizt(self) -> VectorProtocolLorentz:
from vector._compute import lorentz, planar, spatial

Expand Down Expand Up @@ -2954,6 +3136,24 @@ def to_rhophietatau(self) -> VectorProtocolLorentz:
1,
)

def to_ptphipzenergy(self) -> VectorProtocolLorentz:
return self.to_rhophizt()

def to_ptphithetaenergy(self) -> VectorProtocolLorentz:
return self.to_rhophithetat()

def to_ptphietaenergy(self) -> VectorProtocolLorentz:
return self.to_rhophietat()

def to_ptphipzmass(self) -> VectorProtocolLorentz:
return self.to_rhophiztau()

def to_ptphithetamass(self) -> VectorProtocolLorentz:
return self.to_rhophithetatau()

def to_ptphietamass(self) -> VectorProtocolLorentz:
return self.to_rhophietatau()


class Vector2D(Vector, VectorProtocolPlanar):
def to_Vector2D(self) -> VectorProtocolPlanar:
Expand Down
Loading

0 comments on commit 8493623

Please sign in to comment.