|
1 |
| -# [Interface](@id interface) |
| 1 | +```@meta |
| 2 | +CurrentModule = LorentzVectorBase |
| 3 | +``` |
2 | 4 |
|
3 |
| -The main purpose of `LorentzVectorBase` is to provide a general interface for _Julia |
4 |
| -objects with Lorentz vector informations_. This means one implements a minimal set of |
5 |
| -accessor functions, specified by a _coordinate system_, and `LorentzVectorBase` provides |
6 |
| -implementations for a whole suite of additional accessor functions. |
| 5 | +# `LorentzVectorBase` Interface |
7 | 6 |
|
8 |
| -## Definition |
| 7 | +The `LorentzVectorBase` package defines a **common interface for |
| 8 | +LorentzVectorBase-compliant types** in Julia. This interface allows developers to define |
| 9 | +their own custom four-vector types (e.g., for particles or kinematic configurations) and |
| 10 | +automatically gain access to a large suite of common kinematic computations. |
9 | 11 |
|
10 |
| -A type that adheres to the interface described in this section will be referred to as |
11 |
| -_`LorentzVectorBase`-compliant_. A package providing such a type will be called _the provider_. |
| 12 | +## Purpose |
12 | 13 |
|
13 |
| -## Coordinate Systems |
| 14 | +The main goal is to provide a lightweight abstraction that enables: |
14 | 15 |
|
15 |
| -The provider must define a preferred coordinate system for its _`KinematicInterface`-compliant_ |
16 |
| -type and provide accessors for the components of this system using standardized methods |
17 |
| -(outlined below). If the object natively supports multiple coordinate systems, the provider |
18 |
| -should choose the one in which component access is the most efficient as the _preferred |
19 |
| -coordinate system_. This system must be one of the supported options. |
| 16 | +- Interoperability between different packages using Lorentz vectors |
| 17 | +- Automatic derivation of many derived quantities (e.g. $p_T$, $\eta$, $m$) from a minimal interface |
| 18 | +- Coordinate system flexibility while maintaining performance |
20 | 19 |
|
21 |
| -The `LorentzVectorBase` package supplements these component accessors to cover all supported |
22 |
| -coordinate systems. It uses the components of the _preferred coordinate system_ to implement |
23 |
| -complementary accessors. Julia’s dispatch mechanism prioritizes the accessors provided by |
24 |
| -the object itself. |
| 20 | +## Defining a Lorentz-Vector-Like Type |
25 | 21 |
|
26 |
| -!!! note |
| 22 | +To make your type compliant with `LorentzVectorBase`, you must: |
27 | 23 |
|
28 |
| - A `KinematicInterface`-compliant type can store additional data beyond the four-vector. For instance, |
29 |
| - a type representing an elementary particle may comply while containing more information than |
30 |
| - just the particle’s four-momentum. |
| 24 | +1. **Assign a coordinate system** using: |
31 | 25 |
|
32 |
| -## Implementation |
| 26 | + ```julia |
| 27 | + LorentzVectorBase.coordinate_system(::Type{MyVector}) = XYZT() |
| 28 | + ``` |
33 | 29 |
|
34 |
| -A type `MyLorentzVector` (which do not necessary need to be a vector) will comply with the `KinematicInterface` if it implements |
35 |
| -one of the following sets of methods: |
| 30 | + Coordinate systems are tagged using constructors like `XYZT()`, `PtEtaPhiE()`, etc. These indicate how the four components are interpreted. |
36 | 31 |
|
37 |
| -### Option 1: Position with Cartesian Coordinates |
| 32 | +2. **Implement the four accessors required by the chosen coordinate system**. |
| 33 | + For example, with `XYZT()`: |
38 | 34 |
|
39 |
| -| Required Methods | Brief Description | |
40 |
| -| --------------------------------------------------------------------------------------- | ----------------------------------------------- | |
41 |
| -| `LorentzVectorBase.islorentzvector(::Type{MyLorentzVector})` | Declare that your type implements the interface | |
42 |
| -| `LorentzVectorBase.coordinate_system(::Type{MyLorentzVector}) = LorentzVectorBase.XYZE` | Declare the preferred coordinate system | |
43 |
| -| `LorentzVectorBase.x(::MyLorentzVector)` | X Cartesian coordinate | |
44 |
| -| `LorentzVectorBase.y(::MyLorentzVector)` | Y Cartesian coordinate | |
45 |
| -| `LorentzVectorBase.z(::MyLorentzVector)` | Z Cartesian coordinate | |
46 |
| -| `LorentzVectorBase.t(::MyLorentzVector)` | Time coordinate (t) | |
| 35 | + ```julia |
| 36 | + x(::MyVector) |
| 37 | + y(::MyVector) |
| 38 | + z(::MyVector) |
| 39 | + t(::MyVector) |
| 40 | + ``` |
47 | 41 |
|
48 |
| -### Option 2: Four-Momentum with Cartesian Coordinates |
| 42 | + You can inspect the required accessors for a given coordinate system using: |
49 | 43 |
|
50 |
| -| Required Methods | Brief Description | |
51 |
| -| --------------------------------------------------------------------------------------- | ----------------------------------------------- | |
52 |
| -| `LorentzVectorBase.islorentzvector(::Type{MyLorentzVector})` | Declare that your type implements the interface | |
53 |
| -| `LorentzVectorBase.coordinate_system(::Type{MyLorentzVector}) = LorentzVectorBase.XYZE` | Declare the preferred coordinate system | |
54 |
| -| `LorentzVectorBase.px(::MyLorentzVector)` | Momentum X-component | |
55 |
| -| `LorentzVectorBase.py(::MyLorentzVector)` | Momentum Y-component | |
56 |
| -| `LorentzVectorBase.pz(::MyLorentzVector)` | Momentum Z-component | |
57 |
| -| `LorentzVectorBase.energy(::MyLorentzVector)` | Energy | |
| 44 | + ```julia |
| 45 | + coordinate_system(XYZT()) # returns (:x, :y, :z, :t) |
| 46 | + ``` |
58 | 47 |
|
59 |
| -### Option 3: Four-Momentum with Cylindrical Coordinates |
| 48 | + This indicates which component accessors your type must implement to be compliant with that system. |
60 | 49 |
|
61 |
| -| Required Methods | Brief Description | |
62 |
| -| -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | |
63 |
| -| `LorentzVectorBase.islorentzvector(::Type{MyLorentzVector})` | Declare that your type implements the interface | |
64 |
| -| `LorentzVectorBase.coordinate_system(::Type{MyLorentzVector})` | Declare the preferred coordinate system, which must return `PtEtaPhiM`, `PtEtaPhiE`, `PtYPhiM`, or `PtYPhiE` (from `LorentzVectorBase`) | |
65 |
| -| `LorentzVectorBase.pt(::MyLorentzVector)` | Transverse momentum | |
66 |
| -| `LorentzVectorBase.phi(::MyLorentzVector)` | Azimuthal angle | |
| 50 | +That's it! Once those are defined, the `LorentzVectorBase` package will automatically |
| 51 | +provide implementations for a wide variety of additional kinematic functions and |
| 52 | +coordinate conversions. |
67 | 53 |
|
68 |
| -Additionally, you must implement _one_ of the following: |
| 54 | +## What You Get Automatically |
69 | 55 |
|
70 |
| -| Required Method | Description | |
71 |
| -| ----------------------------------------------- | ------------------------------------------- | |
72 |
| -| `LorentzVectorBase.eta(::MyLorentzVector)` | Pseudorapidity | |
73 |
| -| `LorentzVectorBase.rapidity(::MyLorentzVector)` | Rapidity relative to the beam axis (z-axis) | |
| 56 | +Once a minimal interface is implemented, the following functions become available (among others), categorized by topic: |
74 | 57 |
|
75 |
| -And _one_ of: |
| 58 | +### Cartesian Components |
76 | 59 |
|
77 |
| -| Required Method | Description | |
78 |
| -| --------------------------------------------- | -------------- | |
79 |
| -| `LorentzVectorBase.energy(::MyLorentzVector)` | Energy | |
80 |
| -| `LorentzVectorBase.mass(::MyLorentzVector)` | Invariant mass | |
| 60 | +- [`x`](@ref), [`y`](@ref), [`z`](@ref), [`t`](@ref) |
| 61 | +- [`px`](@ref), [`py`](@ref), [`pz`](@ref), [`E`](@ref) |
81 | 62 |
|
82 |
| -The methods returning the coordinates of the preferred system (as specified by `coordinate_system()`) must be implemented. |
| 63 | +### Spherical and Cylindrical Coordinates |
83 | 64 |
|
84 |
| -## Optional Methods |
| 65 | +- [`spatial_magnitude`](@ref), [`spatial_magnitude2`](@ref) |
| 66 | +- [`polar_angle`](@ref), [`cos_theta`](@ref) |
| 67 | +- [`phi`](@ref), [`cos_phi`](@ref), [`sin_phi`](@ref) |
85 | 68 |
|
86 |
| -| Optional Method | Description | |
87 |
| -| -------------------------------------------- | -------------------------------------------- | |
88 |
| -| `LorentzVectorBase.mass2(::MyLorentzVector)` | Square of the mass | |
89 |
| -| `LorentzVectorBase.rho2(::MyLorentzVector)` | ρ² = \|**p**\|² (squared momentum magnitude) | |
| 69 | +### Mass and Invariant Quantities |
90 | 70 |
|
91 |
| -Additionally, any method from another option (i.e., a method from Option Y when methods from Option X are provided) may also be implemented. |
| 71 | +- [`mass`](@ref), [`mass2`](@ref) |
| 72 | +- [`mt`](@ref), [`mt2`](@ref) |
| 73 | +- [`pt`](@ref), [`pt2`](@ref) |
| 74 | + |
| 75 | +### Rapidity and Related Quantities |
| 76 | + |
| 77 | +- [`eta`](@ref): pseudorapidity |
| 78 | +- [`rapidity`](@ref) |
| 79 | + |
| 80 | +### Boost Parameters |
| 81 | + |
| 82 | +- [`boost_beta`](@ref), [`boost_gamma`](@ref) |
| 83 | + |
| 84 | +### Light-Cone Coordinates |
| 85 | + |
| 86 | +- [`plus_component`](@ref), [`minus_component`](@ref) |
| 87 | + |
| 88 | +### Accessor Aliases |
| 89 | + |
| 90 | +To improve readability and interoperability, `LorentzVectorBase` provides a set of |
| 91 | +**aliases** for common physics terminology. These aliases map frequently used or |
| 92 | +alternative names to the canonical accessor functions. |
| 93 | + |
| 94 | +For example, `energy` is an alias for `t`, and `invariant_mass` maps to `mass`. |
| 95 | + |
| 96 | +```julia |
| 97 | +energy(lv) === t(lv) |
| 98 | +invariant_mass(lv) === mass(lv) |
| 99 | +transverse_momentum(lv) === pt(lv) |
| 100 | +``` |
| 101 | + |
| 102 | +This allows users to choose more descriptive or domain-specific terminology without losing compatibility. |
| 103 | + |
| 104 | +### Available Aliases |
| 105 | + |
| 106 | +| Alias | Canonical Function | |
| 107 | +| ---------------------- | ------------------ | |
| 108 | +| `energy` | `t` | |
| 109 | +| `invariant_mass` | `mass` | |
| 110 | +| `invariant_mass2` | `mass2` | |
| 111 | +| `transverse_momentum` | `pt` | |
| 112 | +| `transverse_momentum2` | `pt2` | |
| 113 | +| `perp` | `pt` | |
| 114 | +| `perp2` | `pt2` | |
| 115 | +| `transverse_mass` | `mt` | |
| 116 | +| `transverse_mass2` | `mt2` | |
| 117 | +| `azimuthal_angle` | `phi` | |
| 118 | +| `pseudorapidity` | `eta` | |
| 119 | + |
| 120 | +## Coordinate System Tags |
| 121 | + |
| 122 | +The following coordinate systems are supported via tags like `XYZT()`, `PtEtaPhiM()`, etc.: |
| 123 | + |
| 124 | +- `XYZT`, `PxPyPzE` — position/time or cartesian four-momentum |
| 125 | +- `PtEtaPhiM` — common in collider physics |
| 126 | + |
| 127 | +Each tag specifies which component names (`x`, `pt`, `eta`, etc.) you must implement. |
| 128 | + |
| 129 | +## Example |
| 130 | + |
| 131 | +```julia |
| 132 | +struct MyVector |
| 133 | + px::Float64 |
| 134 | + py::Float64 |
| 135 | + pz::Float64 |
| 136 | + E::Float64 |
| 137 | +end |
| 138 | +
|
| 139 | +LorentzVectorBase.coordinate_system(::Type{MyVector}) = XYZE() |
| 140 | +
|
| 141 | +LorentzVectorBase.px(v::MyVector) = v.px |
| 142 | +LorentzVectorBase.py(v::MyVector) = v.py |
| 143 | +LorentzVectorBase.pz(v::MyVector) = v.pz |
| 144 | +LorentzVectorBase.energy(v::MyVector) = v.E |
| 145 | +``` |
| 146 | + |
| 147 | +Now your type supports: |
| 148 | + |
| 149 | +```julia |
| 150 | +mass(MyVector(...)) |
| 151 | +eta(MyVector(...)) |
| 152 | +pt(MyVector(...)) |
| 153 | +phi(MyVector(...)) |
| 154 | +``` |
| 155 | + |
| 156 | +without implementing them manually. |
0 commit comments