Skip to content

Commit 9635bab

Browse files
Fill out Object and NumPy implementations. (#33)
* Fill out Object and NumPy implementations. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Drop LongitudinalW, as it can't be used in non-Lorentz spatial vectors. * Implemented Z, the first longitudinal coordinate. * All tests for Z. * All the basic spatial properties implemented and tested. * All the basic Lorentz properties implemented and tested. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9c0648d commit 9635bab

33 files changed

+5424
-124
lines changed

docs/api/inheritance.svg

Lines changed: 3230 additions & 0 deletions
Loading

src/vector/backends/numpy_.py

Lines changed: 456 additions & 25 deletions
Large diffs are not rendered by default.

src/vector/backends/object_.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
import vector.methods
1212

1313

14-
class AzimuthalObject:
14+
class CoordinatesObject:
1515
pass
1616

1717

18-
class LongitudinalObject:
18+
class AzimuthalObject(CoordinatesObject):
1919
pass
2020

2121

22-
class TemporalObject:
22+
class LongitudinalObject(CoordinatesObject):
23+
pass
24+
25+
26+
class TemporalObject(CoordinatesObject):
2327
pass
2428

2529

@@ -96,21 +100,6 @@ def elements(self):
96100
)
97101

98102

99-
class LongitudinalObjectW(typing.NamedTuple):
100-
w: float
101-
102-
@property
103-
def elements(self):
104-
return (self.w,)
105-
106-
107-
LongitudinalObjectW.__bases__ = (
108-
LongitudinalObject,
109-
vector.geometry.LongitudinalW,
110-
tuple,
111-
)
112-
113-
114103
class TemporalObjectT(typing.NamedTuple):
115104
t: float
116105

@@ -149,9 +138,15 @@ class PlanarVectorObject(vector.geometry.PlanarVector, PlanarObject):
149138
pass
150139

151140

141+
class PlanarPointObject(vector.geometry.PlanarPoint, PlanarObject):
142+
pass
143+
144+
152145
class SpatialObject(vector.methods.Spatial):
153146
__slots__ = ("azimuthal", "longitudinal")
154147

148+
lib = numpy
149+
155150
def __init__(self, azimuthal, longitudinal):
156151
self.azimuthal = azimuthal
157152
self.longitudinal = longitudinal
@@ -164,9 +159,15 @@ class SpatialVectorObject(vector.geometry.SpatialVector, SpatialObject):
164159
pass
165160

166161

162+
class SpatialPointObject(vector.geometry.SpatialPoint, SpatialObject):
163+
pass
164+
165+
167166
class LorentzObject(vector.methods.Lorentz):
168167
__slots__ = ("azimuthal", "longitudinal", "temporal")
169168

169+
lib = numpy
170+
170171
def __init__(self, azimuthal, longitudinal, temporal):
171172
self.azimuthal = azimuthal
172173
self.longitudinal = longitudinal
@@ -180,6 +181,10 @@ class LorentzVectorObject(vector.geometry.LorentzVector, LorentzObject):
180181
pass
181182

182183

184+
class LorentzPointObject(vector.geometry.LorentzPoint, LorentzObject):
185+
pass
186+
187+
183188
class TransformObject:
184189
lib = numpy
185190

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
2+
#
3+
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
4+
# or https://github.com/scikit-hep/vector for details.
5+
6+
import vector.compute.lorentz.t # noqa: F401
7+
import vector.compute.lorentz.t2 # noqa: F401
8+
import vector.compute.lorentz.tau # noqa: F401
9+
import vector.compute.lorentz.tau2 # noqa: F401

src/vector/compute/lorentz/t.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
2+
#
3+
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
4+
# or https://github.com/scikit-hep/vector for details.
5+
6+
import numpy
7+
8+
from vector.compute.lorentz import t2
9+
from vector.geometry import (
10+
AzimuthalRhoPhi,
11+
AzimuthalXY,
12+
LongitudinalEta,
13+
LongitudinalTheta,
14+
LongitudinalZ,
15+
TemporalT,
16+
TemporalTau,
17+
aztype,
18+
ltype,
19+
ttype,
20+
)
21+
22+
23+
def xy_z_t(lib, x, y, z, t):
24+
return t
25+
26+
27+
def xy_z_tau(lib, x, y, z, tau):
28+
return lib.sqrt(t2.xy_z_tau(lib, x, y, z, tau))
29+
30+
31+
def xy_theta_t(lib, x, y, theta, t):
32+
return t
33+
34+
35+
def xy_theta_tau(lib, x, y, theta, tau):
36+
return lib.sqrt(t2.xy_theta_tau(lib, x, y, theta, tau))
37+
38+
39+
def xy_eta_t(lib, x, y, eta, t):
40+
return t
41+
42+
43+
def xy_eta_tau(lib, x, y, eta, tau):
44+
return lib.sqrt(t2.xy_eta_tau(lib, x, y, eta, tau))
45+
46+
47+
def rhophi_z_t(lib, rho, phi, z, t):
48+
return t
49+
50+
51+
def rhophi_z_tau(lib, rho, phi, z, tau):
52+
return lib.sqrt(t2.rhophi_z_tau(lib, rho, phi, z, tau))
53+
54+
55+
def rhophi_theta_t(lib, rho, phi, theta, t):
56+
return t
57+
58+
59+
def rhophi_theta_tau(lib, rho, phi, theta, tau):
60+
return lib.sqrt(t2.rhophi_theta_tau(lib, rho, phi, theta, tau))
61+
62+
63+
def rhophi_eta_t(lib, rho, phi, eta, t):
64+
return t
65+
66+
67+
def rhophi_eta_tau(lib, rho, phi, eta, tau):
68+
return lib.sqrt(t2.rhophi_eta_tau(lib, rho, phi, eta, tau))
69+
70+
71+
dispatch_map = {
72+
(AzimuthalXY, LongitudinalZ, TemporalT): xy_z_t,
73+
(AzimuthalXY, LongitudinalZ, TemporalTau): xy_z_tau,
74+
(AzimuthalXY, LongitudinalTheta, TemporalT): xy_theta_t,
75+
(AzimuthalXY, LongitudinalTheta, TemporalTau): xy_theta_tau,
76+
(AzimuthalXY, LongitudinalEta, TemporalT): xy_eta_t,
77+
(AzimuthalXY, LongitudinalEta, TemporalTau): xy_eta_tau,
78+
(AzimuthalRhoPhi, LongitudinalZ, TemporalT): rhophi_z_t,
79+
(AzimuthalRhoPhi, LongitudinalZ, TemporalTau): rhophi_z_tau,
80+
(AzimuthalRhoPhi, LongitudinalTheta, TemporalT): rhophi_theta_t,
81+
(AzimuthalRhoPhi, LongitudinalTheta, TemporalTau): rhophi_theta_tau,
82+
(AzimuthalRhoPhi, LongitudinalEta, TemporalT): rhophi_eta_t,
83+
(AzimuthalRhoPhi, LongitudinalEta, TemporalTau): rhophi_eta_tau,
84+
}
85+
86+
87+
def dispatch(v):
88+
with numpy.errstate(all="ignore"):
89+
return v.lib.nan_to_num(
90+
dispatch_map[aztype(v), ltype(v), ttype(v),](
91+
v.lib,
92+
*v.azimuthal.elements,
93+
*v.longitudinal.elements,
94+
*v.temporal.elements
95+
),
96+
nan=0.0,
97+
)

src/vector/compute/lorentz/t2.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
2+
#
3+
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
4+
# or https://github.com/scikit-hep/vector for details.
5+
6+
import numpy
7+
8+
from vector.compute.spatial import mag2
9+
from vector.geometry import (
10+
AzimuthalRhoPhi,
11+
AzimuthalXY,
12+
LongitudinalEta,
13+
LongitudinalTheta,
14+
LongitudinalZ,
15+
TemporalT,
16+
TemporalTau,
17+
aztype,
18+
ltype,
19+
ttype,
20+
)
21+
22+
23+
def xy_z_t(lib, x, y, z, t):
24+
return t ** 2
25+
26+
27+
def xy_z_tau(lib, x, y, z, tau):
28+
return tau ** 2 + mag2.xy_z(lib, x, y, z)
29+
30+
31+
def xy_theta_t(lib, x, y, theta, t):
32+
return t ** 2
33+
34+
35+
def xy_theta_tau(lib, x, y, theta, tau):
36+
return tau ** 2 + mag2.xy_theta(lib, x, y, theta)
37+
38+
39+
def xy_eta_t(lib, x, y, eta, t):
40+
return t ** 2
41+
42+
43+
def xy_eta_tau(lib, x, y, eta, tau):
44+
return tau ** 2 + mag2.xy_eta(lib, x, y, eta)
45+
46+
47+
def rhophi_z_t(lib, rho, phi, z, t):
48+
return t ** 2
49+
50+
51+
def rhophi_z_tau(lib, rho, phi, z, tau):
52+
return tau ** 2 + mag2.rhophi_z(lib, rho, phi, z)
53+
54+
55+
def rhophi_theta_t(lib, rho, phi, theta, t):
56+
return t ** 2
57+
58+
59+
def rhophi_theta_tau(lib, rho, phi, theta, tau):
60+
return tau ** 2 + mag2.rhophi_theta(lib, rho, phi, theta)
61+
62+
63+
def rhophi_eta_t(lib, rho, phi, eta, t):
64+
return t ** 2
65+
66+
67+
def rhophi_eta_tau(lib, rho, phi, eta, tau):
68+
return tau ** 2 + mag2.rhophi_eta(lib, rho, phi, eta)
69+
70+
71+
dispatch_map = {
72+
(AzimuthalXY, LongitudinalZ, TemporalT): xy_z_t,
73+
(AzimuthalXY, LongitudinalZ, TemporalTau): xy_z_tau,
74+
(AzimuthalXY, LongitudinalTheta, TemporalT): xy_theta_t,
75+
(AzimuthalXY, LongitudinalTheta, TemporalTau): xy_theta_tau,
76+
(AzimuthalXY, LongitudinalEta, TemporalT): xy_eta_t,
77+
(AzimuthalXY, LongitudinalEta, TemporalTau): xy_eta_tau,
78+
(AzimuthalRhoPhi, LongitudinalZ, TemporalT): rhophi_z_t,
79+
(AzimuthalRhoPhi, LongitudinalZ, TemporalTau): rhophi_z_tau,
80+
(AzimuthalRhoPhi, LongitudinalTheta, TemporalT): rhophi_theta_t,
81+
(AzimuthalRhoPhi, LongitudinalTheta, TemporalTau): rhophi_theta_tau,
82+
(AzimuthalRhoPhi, LongitudinalEta, TemporalT): rhophi_eta_t,
83+
(AzimuthalRhoPhi, LongitudinalEta, TemporalTau): rhophi_eta_tau,
84+
}
85+
86+
87+
def dispatch(v):
88+
with numpy.errstate(all="ignore"):
89+
return v.lib.nan_to_num(
90+
dispatch_map[aztype(v), ltype(v), ttype(v),](
91+
v.lib,
92+
*v.azimuthal.elements,
93+
*v.longitudinal.elements,
94+
*v.temporal.elements
95+
),
96+
nan=0.0,
97+
)

src/vector/compute/lorentz/tau.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
2+
#
3+
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
4+
# or https://github.com/scikit-hep/vector for details.
5+
6+
import numpy
7+
8+
from vector.compute.lorentz import tau2
9+
from vector.geometry import (
10+
AzimuthalRhoPhi,
11+
AzimuthalXY,
12+
LongitudinalEta,
13+
LongitudinalTheta,
14+
LongitudinalZ,
15+
TemporalT,
16+
TemporalTau,
17+
aztype,
18+
ltype,
19+
ttype,
20+
)
21+
22+
23+
def xy_z_t(lib, x, y, z, t):
24+
return lib.sqrt(tau2.xy_z_t(lib, x, y, z, t))
25+
26+
27+
def xy_z_tau(lib, x, y, z, tau):
28+
return tau
29+
30+
31+
def xy_theta_t(lib, x, y, theta, t):
32+
return lib.sqrt(tau2.xy_theta_t(lib, x, y, theta, t))
33+
34+
35+
def xy_theta_tau(lib, x, y, theta, tau):
36+
return tau
37+
38+
39+
def xy_eta_t(lib, x, y, eta, t):
40+
return lib.sqrt(tau2.xy_eta_t(lib, x, y, eta, t))
41+
42+
43+
def xy_eta_tau(lib, x, y, eta, tau):
44+
return tau
45+
46+
47+
def rhophi_z_t(lib, rho, phi, z, t):
48+
return lib.sqrt(tau2.rhophi_z_t(lib, rho, phi, z, t))
49+
50+
51+
def rhophi_z_tau(lib, rho, phi, z, tau):
52+
return tau
53+
54+
55+
def rhophi_theta_t(lib, rho, phi, theta, t):
56+
return lib.sqrt(tau2.rhophi_theta_t(lib, rho, phi, theta, t))
57+
58+
59+
def rhophi_theta_tau(lib, rho, phi, theta, tau):
60+
return tau
61+
62+
63+
def rhophi_eta_t(lib, rho, phi, eta, t):
64+
return lib.sqrt(tau2.rhophi_eta_t(lib, rho, phi, eta, t))
65+
66+
67+
def rhophi_eta_tau(lib, rho, phi, eta, tau):
68+
return tau
69+
70+
71+
dispatch_map = {
72+
(AzimuthalXY, LongitudinalZ, TemporalT): xy_z_t,
73+
(AzimuthalXY, LongitudinalZ, TemporalTau): xy_z_tau,
74+
(AzimuthalXY, LongitudinalTheta, TemporalT): xy_theta_t,
75+
(AzimuthalXY, LongitudinalTheta, TemporalTau): xy_theta_tau,
76+
(AzimuthalXY, LongitudinalEta, TemporalT): xy_eta_t,
77+
(AzimuthalXY, LongitudinalEta, TemporalTau): xy_eta_tau,
78+
(AzimuthalRhoPhi, LongitudinalZ, TemporalT): rhophi_z_t,
79+
(AzimuthalRhoPhi, LongitudinalZ, TemporalTau): rhophi_z_tau,
80+
(AzimuthalRhoPhi, LongitudinalTheta, TemporalT): rhophi_theta_t,
81+
(AzimuthalRhoPhi, LongitudinalTheta, TemporalTau): rhophi_theta_tau,
82+
(AzimuthalRhoPhi, LongitudinalEta, TemporalT): rhophi_eta_t,
83+
(AzimuthalRhoPhi, LongitudinalEta, TemporalTau): rhophi_eta_tau,
84+
}
85+
86+
87+
def dispatch(v):
88+
with numpy.errstate(all="ignore"):
89+
return v.lib.nan_to_num(
90+
dispatch_map[aztype(v), ltype(v), ttype(v),](
91+
v.lib,
92+
*v.azimuthal.elements,
93+
*v.longitudinal.elements,
94+
*v.temporal.elements
95+
),
96+
nan=0.0,
97+
)

0 commit comments

Comments
 (0)