{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![Particle](../docs/ParticleLogo300.png)\n", "\n", "### Henry Schreiner and Eduardo Rodrigues\n", "\n", "Some of the demos assume you have run `python -m pip install particle` or `pixi run lab`. You can [view the demo here](https://nbviewer.jupyter.org/github/scikit-hep/particle/blob/master/notebooks/ParticleDemo.ipynb) or [run it here](https://mybinder.org/v2/gh/scikit-hep/particle/master?urlpath=lab/tree/notebooks/ParticleDemo.ipynb) on Binder." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Demo 1: Command line usage\n", "\n", "There are two modules in `Particle`:\n", "\n", "* PDGID - Find out as much as possible from the PDG ID number. **No table lookup**.\n", "* Particle - Loads **PDG data tables** and implements search and manipulations / display." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### General usage" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "!python -m particle -h" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!python -m particle --version" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### PDGID" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!python -m particle pdgid 211" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Particle" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!python -m particle search 211" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!python -m particle search \"pi+\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!python -m particle search \"pi(1400)+\"" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "#### Bonus feature: ZipApp\n", "\n", "We also have released a new ZipApp version - **one file** that runs on **any computer with Python**, no other dependencies! Find it [attached to releases](https://github.com/scikit-hep/particle/releases) starting with version 0.4.4." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Example:\n", "\n", "```bash\n", "./particle.pyz search gamma\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All dependencies (including the two backports) are installed inside the ZipApp, and the data lookup is handled in a zip-safe way inside particle.\n", "\n", "The command line mode could be enhanced to make it a useful tool in bash scripts! Stay tuned..." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Demo 2: Python usage\n", "\n", "### PDGID\n", "\n", "Let's start with `PDGID` again." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "from particle import PDGID, Particle, Charge" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = PDGID(211)\n", "p" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(p.info())" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "#### Literals\n", "\n", "`Particle` has literals, as well; these are dynamically generated on import for **both PDGID and Particle** classes!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import particle.pdgid.literals as pdgid_literals" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pdgid_literals.phi_1020" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Particle\n", "\n", "There are lots of ways to create a particle:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### From PDGID" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Particle.from_pdgid(211)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "#### Literals" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import particle.literals as particle_literals" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "particle_literals.phi_1020" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "#### Searching\n", "\n", "The most powerful methods: `findall` and `finditer`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(p,) = Particle.finditer(\n", " \"phi(1020)\"\n", ") # syntax (p,) throws an error if < 1 or > 1 particle is found\n", "p" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can specify search terms as keywords - any particle property:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = Particle.finditer(latex_name=r\"\\phi(1020)\")\n", "next(p)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Some properties have enums available. For example, you can directly check the numeric charge:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Particle.findall(\"pi\", charge=-1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or you can use the enum (for charge, this is 3 times the charge, hence the name `three_charge`)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Particle.findall(\"pi\", three_charge=Charge.p)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Or use a **lambda function** for the ultimate in generality! For example, to find all the neutral particles with a bottom quark between 5.2 and 5.3 GeV:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from hepunits import GeV, s # Units are good. Use them." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Particle.findall(\n", " lambda p: p.pdgid.has_bottom and p.charge == 0 and 5.2 * GeV < p.mass < 5.3 * GeV\n", ")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Another lambda function example: You can use the width or the lifetime:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Particle.findall(lambda p: p.lifetime > 1000 * s)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "If you want infinite lifetime, you could just use the keyword search instead:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Particle.findall(lifetime=float(\"inf\"))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Display" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Nice display in Jupyter notebooks, as well as `str` and `repr` support:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = particle_literals.D_0\n", "p" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(p)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(repr(p))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Full descriptions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(p.describe())" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "You may find LaTeX or HTML to be more useful in your program, both are supported:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(p.latex_name, p.html_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is easy to get hold of the whole list of particle (instances) as a list:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "all_particles = Particle.all()\n", "print(f'The package \"DB\" contains {len(all_particles)} particles:')\n", "all_particles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And it is just as easy to rather get a list of PDG IDs (as `int`s):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "[int(p.pdgid) for p in all_particles]" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Properties\n", "\n", "You can do things to particles, like **invert** them:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "~p" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are a plethora of properties you can access:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p.spin_type" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "You can quickly access the PDGID of a particle:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p.pdgid" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Advanced usage\n", "\n", "You can:\n", "\n", "* Extend or replace the default table in `Particle`\n", "* Adjust properties for a particle\n", "* Make custom particles" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Now let's look at one of the users of `Particle`: the [DecayLanguage](https://github.com/scikit-hep/decaylanguage\n", ") package!" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 4 }