Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/usage/particle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
"source": [
"````{margin}\n",
"> [!NOTE]\n",
"> By convention, {mod}`qrules` uses $\\mathrm{GeV}/c^2$ as energy unit.\n",
"> By convention, {mod}`qrules` uses $\\mathrm{GeV}/c^2$ as energy unit (see {class}`.Particle`). The [`hepunits`](https://pypi.org/project/hepunits) package makes unit conversions explicit.\n",
"````"
]
},
Expand All @@ -294,14 +294,15 @@
"metadata": {},
"outputs": [],
"source": [
"from hepunits import GeV, MeV\n",
"\n",
"energies_mev = {4180, 4220, 4420, 4600}\n",
"template_particle = particle_db[\"J/psi(1S)\"]\n",
"for energy_mev in energies_mev:\n",
" energy_gev = energy_mev / 1e3\n",
" new_particle = create_particle(\n",
" template_particle,\n",
" name=f\"EpEm ({energy_mev} MeV)\",\n",
" mass=energy_gev,\n",
" mass=energy_mev * MeV / GeV,\n",
" )\n",
" particle_db.add(new_particle)\n",
"len(particle_db)"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies = [
"PyYAML",
"attrs>=20.1.0", # on_setattr and https://www.attrs.org/en/stable/api.html#attrs.define
"frozendict",
"hepunits>=2.4.7",
"jsonschema",
"particle",
"python-constraint2",
Expand Down
11 changes: 10 additions & 1 deletion src/qrules/particle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _to_spin(value: Spin | tuple[Fraction, Fraction] | tuple[float, float], /) -
@total_ordering
@frozen(kw_only=True, order=False, repr=True)
class Particle:
"""Immutable container of data defining a physical particle.
r"""Immutable container of data defining a physical particle.

A `Particle` is defined by the minimum set of the quantum numbers that every
possible instances of that particle have in common (the "static" quantum numbers of
Expand All @@ -132,6 +132,15 @@ class Particle:
labels that are not taken into account when checking if two `Particle` instances are
equal.

The `~Particle.mass` and `~Particle.width` are expressed in :math:`\mathrm{GeV}`
(with :math:`c=1`). To convert values from another unit, use the `hepunits
<https://pypi.org/project/hepunits>`_ package, in which :math:`\mathrm{MeV}=1`:

>>> from hepunits import GeV, MeV
>>> phi = Particle(name="phi(1020)", pid=333, spin=1, mass=1019.461 * MeV / GeV)
>>> phi.mass
1.019461

.. note::

As opposed to classes such as `.EdgeQuantumNumbers` and `.NodeQuantumNumbers`,
Expand Down
3 changes: 2 additions & 1 deletion src/qrules/particle/_adapter/scikit_hep.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from math import copysign
from typing import TYPE_CHECKING

from hepunits import GeV
from particle import Particle as PdgDatabase

from qrules.particle import Particle, ParticleCollection, Spin
Expand Down Expand Up @@ -53,7 +54,7 @@ def __convert_pdg_instance(pdg_particle: PdgDatabase) -> Particle:
def convert_mass_width(value: float | None) -> float:
if value is None:
return 0.0
return float(value) / 1e3 # https://github.com/ComPWA/qrules/issues/14
return float(value) / GeV

def convert_spin(value: Fraction | float | None) -> float:
if value is None:
Expand Down
2 changes: 2 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading