Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: generate particle property table from database #55

Merged
merged 18 commits into from
Aug 2, 2024
Merged
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
147 changes: 62 additions & 85 deletions docs/ampform/LambdaKpi0.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"import os\n",
"import warnings\n",
"from collections import defaultdict\n",
"from fractions import Fraction\n",
"from textwrap import dedent\n",
"\n",
"import ampform\n",
"import graphviz\n",
Expand All @@ -46,7 +48,7 @@
"import qrules\n",
"from ampform.dynamics.builder import RelativisticBreitWignerBuilder\n",
"from ampform.io import aslatex, improve_latex_rendering\n",
"from IPython.display import Math\n",
"from IPython.display import Markdown, Math\n",
"from qrules.particle import Particle, Spin, create_particle, load_pdg\n",
"from tensorwaves.data import (\n",
" SympyDataTransformer,\n",
Expand Down Expand Up @@ -81,101 +83,76 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"mystnb": {
"code_prompt_show": "Lambda"
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"particle_db[\"Lambda\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"mystnb": {
"code_prompt_show": "K+"
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"particle_db[\"K+\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"mystnb": {
"code_prompt_show": "pi0"
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"particle_db[\"pi0\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"mystnb": {
"code_prompt_show": "gamma"
},
"tags": [
"hide-cell"
]
},
"outputs": [],
"source": [
"particle_db[\"gamma\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"mystnb": {
"code_prompt_show": "p"
},
"tags": [
"hide-cell"
"scroll-output",
"full-width",
"hide-input"
]
},
"outputs": [],
"source": [
"particle_db[\"p\"]"
"def generate_markdown_table(particles: list[str]):\n",
" src = dedent(r\"\"\"\n",
" | Particle | Name | PID | $J^{PC} (I^G)$ | $I_3$ | $M$ | $\\Gamma$ | $Q$ | $S$ | $B$ |\n",
" | :------- |------|-----|----------------|-------|-----|----------|-----|-----|-----|\n",
" \"\"\")\n",
" for name in particles:\n",
" p = particle_db[name]\n",
" src += f\"| ${p.latex}$ | `{p.name}` | {p.pid} | {jpc_ig(p)} | {i_3(p)} | {p.mass:.3g}| {p.width:g} | {p.charge} |{p.strangeness} | {p.baryon_number}|\\n\"\n",
" return src\n",
"\n",
"\n",
"def jpc_ig(particle: Particle) -> str:\n",
" j = format_fraction(particle.spin)\n",
" p = format_parity(particle.parity)\n",
" c = format_parity(particle.c_parity)\n",
" if particle.isospin is None:\n",
" return f\"${j}^{{{p}{c}}}$\"\n",
" i = format_fraction(particle.isospin.magnitude)\n",
" g = format_parity(particle.g_parity)\n",
" return rf\"${j}^{{{p}{c}}} \\; ({i}^{{{g}}})$\"\n",
"\n",
"\n",
"def i_3(particle: Particle) -> str:\n",
" if particle.isospin is None:\n",
" return \"N/A\"\n",
" return f\"${format_fraction(particle.isospin.projection)}$\"\n",
"\n",
"\n",
"def format_fraction(value: float) -> str:\n",
" value = Fraction(value)\n",
" if value.denominator == 1:\n",
" return str(value.numerator)\n",
" return rf\"\\frac{{{value.numerator}}}{{{value.denominator}}}\"\n",
"\n",
"\n",
"def format_parity(parity: int | None) -> str:\n",
" if parity is None:\n",
" return \" \"\n",
" if parity == -1:\n",
" return \"-\"\n",
" if parity == 1:\n",
" return \"+\"\n",
" raise NotImplementedError\n",
"\n",
"\n",
"particles = [\"Lambda\", \"K+\", \"pi0\", \"gamma\", \"p\"]\n",
"src = generate_markdown_table(particles)\n",
"Markdown(src)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"| Particle | Lambda | K+ | pi0 | gamma | p |\n",
"|------------------|-------------------|------------------|------------------|------------------|------------------|\n",
"| **Name** | Lambda | K+ | pi0 | gamma | p |\n",
"| **PID** | 3122 | 321 | 111 | 22 | 2212 |\n",
"| **Latex** | \\(\\Lambda\\) | \\(K^{+}\\) | \\(\\pi^{0}\\) | \\(\\gamma\\) | \\(p\\) |\n",
"| **Spin** | 0.5 | 0.0 | 0.0 | 1.0 | 0.5 |\n",
"| **Mass** | 1.115683 | 0.49367700000000003 | 0.1349768 | 0.0 | 0.93827208816 |\n",
"| **Width** | 2.501e-15 | 5.317e-17 | 7.81e-09 | | |\n",
"| **Charge** | | 1 | | | 1 |\n",
"| **Isospin** | Spin(0, 0) | Spin(1/2, +1/2) | Spin(1, 0) | | Spin(1/2, +1/2) |\n",
"| **Strangeness** | -1 | 1 | | | |\n",
"| **Baryon Number**| 1 | | | | 1 |\n",
"| **Parity** | +1 | -1 | -1 | -1 | +1 |\n",
"| **C Parity** | | | +1 | -1 | |\n",
"| **G Parity** | | | -1 | | |\n"
"In the table above, PID is the PDG ID from PDG particle numbering scheme,\n",
"$J$ is the spin, $P$ is the parity, $C$ is the C parity, $I$ is the isospin (magnitude), $G$ is the G parity.\n",
"$I_3$ is the isospin projection (or the 3rd component),\n",
"$M$ is the mass,\n",
"$\\Gamma$ is the width,\n",
"$Q$ is the charge,\n",
"$S$ is the strangeness number,\n",
"and $B$ is the baryon number."
]
},
{
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
nb_execution_mode = "cache" if os.environ.get("EXECUTE_NB") else "off"
nb_execution_show_tb = True
nb_execution_timeout = -1
nb_render_markdown_format = "myst"
nitpicky = True
project = "GlueX N-Star"
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"*.ipynb" = [
"ANN",
"B018",
"D100",
"D103",
"E303",
"E501",
redeboer marked this conversation as resolved.
Show resolved Hide resolved
"T201",
]
"docs/conf.py" = [
Expand Down