particle

Package to deal with particles, the PDG particle data table, PDGIDs, etc.

https://github.com/scikit-hep/particle

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    6 of 20 committers (30.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.7%) to scientific vocabulary

Keywords

analysis hep high-energy-physics particle particle-physics pdg pid scikit-hep

Keywords from Contributors

histogram closember rdataframe apache-arrow cern-root columnar-format jagged-array ragged-array battery mesh
Last synced: 6 months ago · JSON representation ·

Repository

Package to deal with particles, the PDG particle data table, PDGIDs, etc.

Basic Info
  • Host: GitHub
  • Owner: scikit-hep
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 1.91 MB
Statistics
  • Stars: 158
  • Watchers: 6
  • Forks: 26
  • Open Issues: 8
  • Releases: 51
Topics
analysis hep high-energy-physics particle particle-physics pdg pid scikit-hep
Created over 7 years ago · Last pushed 6 months ago
Metadata Files
Readme Contributing License Citation Zenodo

README.md

Particle Logo

Particle: PDG particle data and identification codes

Scikit-HEP PyPI Package latest release Conda latest release Zenodo DOI

GitHub Actions Status: CI Code Coverage

Binder

Particle provides a pythonic interface to the Particle Data Group (PDG) particle data tables and particle identification codes, with extended particle information and extra goodies.

The PDG defines the standard particle identification (ID) numbering scheme. The package provides the PDGID class implementing queries on those PDG IDs. The queries are also accessible through free standing functions mimicking, and expanding from, the HepPID/HepPDT C++ interface.

The Particle class wraps the information in the PDG particle data tables and provides an object-oriented interface and powerful search and look-up utilities.

Installation

Install particle like any other Python package:

bash python -m pip install particle

or similar (use --user, virtualenv, etc. if you wish).

Strict dependencies

  • Python (3.9)
  • attrs provides classes without boilerplate (similar to DataClasses in Python 3.7)
  • hepunits_ provides units for the Scikit-HEP packages

Changelog

See the changelog for a history of notable changes.

Getting started: PDG IDs

```python

from particle import PDGID

pid = PDGID(211) pid pid.ismeson True pid = PDGID(99999999) pid <PDGID: 99999999 (isvalid==False)> ```

For convenience, all properties of the PDGID class are available as standalone functions that work on any SupportsInt (including Particle):

```python

from particle.pdgid import is_meson

is_meson(211) True ```

These composable functions qualifying PDG IDs make it easy to classify particles. For the sake of example, quarkonia can be specified with the following user-defined functions:

```python

isheavyflavor = lambda x: hascharm(x) or hasbottom(x) or hastop(x) isquarkonium = lambda x: ismeson(x) and isheavyflavor(x) and Particle.frompdgid(x).isselfconjugate ```

PDG ID literals provide (PDGID class) aliases for all particles loaded, with easily recognisable names. For example:

```python

from particle.pdgid import literals as lid

lid.pi_plus

from particle.pdgid.literals import Lambdab0 Lambdab0 Lambdab0.has_bottom True ```

You can quickly display PDGID info from the command line with:

bash $ python -m particle pdgid 323 <PDGID: 323> A None J 1.0 L 0 S 1 Z None abspid 323 charge 1.0 has_bottom False ...

Similarly, classes exist to express identification codes used by MC programs, see information on converters below.

Getting started: Particles

You can use a variety of methods to get particles. If you know the PDG ID number or, say, the name used in EvtGen, you can get a particle directly.

```python

from particle import Particle Particle.from_pdgid(211)

Particle.fromevtgenname("J/psi")

Particle.fromnucleusinfo(a=12, z=6) ```

A similar method exists to get a list of particles from a PDG style name:

```python

Particle.findall(pdg_name="pi") ```

returns the list of matching particles whose PDG name is "pi", which in this case comprises the three charged states of the pseudoscalar pion.

Else, and more generally, you can use a search. A basic example is the following:

```python

next(Particle.finditer('pi')) # first item in iterator of particles

Particle.findall('pi')[0] # Same as above but returning a list of particles ```

You can search for the properties using keyword arguments, which include pdg_name, name, mass, width, charge, three_charge, anti_flag, rank, I, J, G, P, quarks, status, mass_upper, mass_lower, width_upper, and width_lower. You can pass a callable or an exact match for any property. The argument particle can be set to True/False, as well, to limit the search to particles or antiparticles.

You can also build the search yourself with the first positional argument, which accepts a callable that is given the particle object itself. If the first positional argument is a string, that will match against the particle's name.

Here are possible sophisticated searches, all of which work with either Particle.findall or Particle.finditer, where the former method provides a list whereas the latter returns an iterator.

```python

Print out all particles with asymmetric decay width uncertainties

ps = Particle.finditer(lambda p: p.widthlower != p.widthupper) for p in ps: ... print(p.name, p.pdgid, p.widthlower, p.widthupper)

Find all antiparticles with 'Omega' in the name

Particle.finditer('Omega', particle=False) # several found

Find all antiparticles of name=='Omega'

Particle.finditer(name='Omega', particle=False) # none found

Find all antiparticles of pdg_name=='Omega'

Particle.findall(pdg_name='Omega', particle=False) # only 1, of course []

Find all neutral beauty hadrons

Particle.findall(lambda p: p.pdgid.has_bottom and p.charge==0)

Find all strange mesons with c*tau > 1 meter

from hepunits import meter Particle.findall(lambda p: p.pdgid.ismeson and p.pdgid.hasstrange and p.ctau > 1 * meter, particle=True) [, ] ```

Once you have a particle, any of the properties can be accessed, along with several methods. Though they are not real properties, you can access is_name_barred, and spin_type. You can also .invert() a particle.

There are lots of printing choices for particles: describe(), programmatic_name, latex_name, html_name, HTML printing outs in notebooks, and of course repr and str support.

You can get the .pdgid from a particle, as well. Sorting particles will put lowest abs(PDGID) first.

Particle literals provide (Particle class) aliases for the particles loaded, with easily recognisable names. For example:

```python

from particle import literals as lp lp.pi_plus

from particle.literals import Lambdab0 Lambdab0 Lambdab0.J 0.5 ```

You can quickly search for particles from the command line with (note: quotes may be used/needed but only double quotes work as expected on Windows):

bash $ python -m particle search "K*0" <Particle: name="K*(892)0", pdgid=313, mass=895.55 ± 0.20 MeV> <Particle: name="K*(1680)0", pdgid=30313, mass=1718 ± 18 MeV> <Particle: name="K*(1410)0", pdgid=100313, mass=1421 ± 9 MeV>

If you only select one particle, either by a search or by giving the PDG ID number, you can see more information about the particle:

```bash $ python -m particle search 311 Name: K0 ID: 311 Latex: $K^{0}$ Mass = 497.611 ± 0.013 MeV Width = -1.0 MeV Q (charge) = 0 J (total angular) = 0.0 P (space parity) = - C (charge parity) = ? I (isospin) = 1/2 G (G-parity) = ? SpinType: SpinType.PseudoScalar Quarks: dS Antiparticle name: K~0 (antiparticle status: Barred)

```

Advanced: Loading custom tables

You can control the particle data tables if you so desire. You can append a new data table using the following syntax:

```python

from particle import Particle Particle.loadtable('newparticles.csv', append=True) ```

You can also replace the particle table entirely with append=False (the default).

If you want a non-default data file distributed with the package just proceed as follows:

```python

from particle import data Particle.loadtable(data.basepath / "particle2024.csv")) Particle.loadtable(data.basepath / "nuclei2022.csv"), append=True) # I still want nuclei info Particle.table_names() # list the loaded tables ```

Advanced: how to create user-defined particles

There are situations where it may be handy to create user-defined particles. But do so with care and having in mind the limitations, many of which are discussed or exemplified below!

The simplest "particle" one may create is effectively a placeholder with no real information stored:

```python

A Particle instance the simplest possible. Contains basically no info

p = Particle.empty() p

print(p.describe()) Name: Unknown ```

A more useful particle definition will likely involve at least a name and a PDG ID. It is important to keep in mind that a meaningful PDG ID encodes by construction internal quantum numbers and other information. As such, the definition of a particle with a "random" PDG ID will result in a particle with undefined and/or wrong properties such as quantum numbers or the quality of being a meson.

```python

p2 = Particle(9912345, 'MyPentaquark') p2

p2.pdgid.is_pentaquark False print(p2.describe()) # J=2 is an example of something effectively encoded in the PDG ID. Name: MyPentaquark ID: 9912345 Latex: $Unknown$ Mass = None Width = None Q (charge) = None J (total angular) = 2.0 P (space parity) = None C (charge parity) = None I (isospin) = None G (G-parity) = None Antiparticle name: MyPentaquark (antiparticle status: Same) ```

A yet more sophisticated definition:

```python

p3 = Particle(pdgid=9221132,pdgname='Theta',threecharge=3,latex_name='\Theta^{+}') p3

print(p3.describe()) Name: Theta ID: 9221132 Latex: $\Theta^{+}$ Mass = None Width = None Q (charge) = + J (total angular) = 0.5 P (space parity) = None C (charge parity) = None I (isospin) = None G (G-parity) = None SpinType: SpinType.NonDefined Antiparticle name: Theta (antiparticle status: Same) ```

Advanced: Conversion

You can convert and update the particle tables with the utilities in particle.particle.convert. This requires the pandas package, and is only tested with Python 3. Run the following command for more help:

bash $ python3 -m particle.particle.convert --help

Getting started: Converters

You can use mapping classes to convert between particle MC identification codes and particle names. See the particle.converters modules for the available mapping classes. For example:

```python

from particle.converters import Pythia2PDGIDBiMap from particle import PDGID, PythiaID

pyid = Pythia2PDGIDBiMap[PDGID(9010221)] pyid

pdgid = Pythia2PDGIDBiMap[PythiaID(10221)] pdgid ```

This code makes use of classes similar to PDGID, which hold particle identification codes used by MC programs. Possible use cases are the following:

```python

from particle import Particle from particle import Corsika7ID, Geant3ID, PythiaID

g3id = Geant3ID(8) p = Particle.frompdgid(g3id.topdgid())

(p,) = Particle.finditer(pdgid=g3id.to_pdgid()) # syntax (p,) throws an error if < 1 or > 1 particle is found p.name 'pi+'

pythiaid = PythiaID(211) p = Particle.frompdgid(pythiaid.topdgid())

(p,) = Particle.finditer(pdgid=pythiaid.to_pdgid()) p.name 'pi+'

cid = Corsika7ID(5) p = Particle.frompdgid(cid.topdgid()) p.name 'mu+' ```

Corsika7

The Corsika7ID class implements features to make it easier to work with Corsika7 output. For a full feature set, please refer to the particle.corsika submodule.

Corsika7ID.from_particle_description(from_particle_description: int) returns (Corsika7ID, bool) to automatically parse the particle_description from the Corsika7 particle data sub-block.

Corsika7ID.is_particle() checks if the ID refers to an actual particle or something else (like additional information).

Corsika7ID.to_pdgid() converts the Corsika7ID to a PDGID if possible.

Getting started: experiment-specific modules

Experiment-specific submodules are welcome if they tie in nicely with the functionality of the package while providing add-ons of particular relevance to experiments.

LHCb-specific module

Available via

```python

from particle import lhcb ```

it contains the following converter and functions:

```python

dir(lhcb) ['LHCbName2PDGIDBiMap', 'fromlhcbname', 'tolhcbname'] ```

```python

n, e, l = Particle.frompdgid(-531).name, Particle.frompdgid(531).evtgenname, lhcb.tolhcbname(Particle.frompdgid(-531)) print(f"Name: {n}\nEvtGen name: {e}\nLHCb name: {l}") Name: B(s)~0 EvtGen name: Bs0 LHCb name: Bs~0

p = Particle.frompdgid(-531) p tolhcbname(p) 'Bs~0' ```

Conversions PDG ID <-> LHCb name are available via a predefined bidirectional map similarly to what is available in the standard (i.e. non-experiment-specific) converters:

```python

name = LHCbName2PDGIDBiMap[PDGID(-531)] name 'B_s~0'

pdgid = LHCbName2PDGIDBiMap['B_s~0'] pdgid ```

Contributors

We hereby acknowledge the contributors that made this project possible (emoji key): <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable -->

Eduardo Rodrigues
Eduardo Rodrigues

🚧 💻 📖
Henry Schreiner
Henry Schreiner

🚧 💻 📖
Hans Dembinski
Hans Dembinski

💻
Ludwig Neste
Ludwig Neste

💻 📖
Tamas Gal
Tamas Gal

💻
Matthew Feickert
Matthew Feickert

💻
Jost Migenda
Jost Migenda

📖
Jonas Eschle
Jonas Eschle

💻
Chris Burr
Chris Burr

💻
Adam Morris
Adam Morris

💻
Doron Behar
Doron Behar

📖
Alexander Puck Neuwirth
Alexander Puck Neuwirth

💻 📖
Aman Desai
Aman Desai

💻
Jonathan Tellechea
Jonathan Tellechea

📖
Remco de Boer
Remco de Boer

💻
Maximilian Linhoff
Maximilian Linhoff

💻

This project follows the all-contributors specification.

Acknowledgements

The UK Science and Technology Facilities Council (STFC) and the University of Liverpool provide funding for Eduardo Rodrigues (2020-) to work on this project part-time.

Support for this work was provided by the National Science Foundation cooperative agreement OAC-1450377 (DIANA/HEP) in 2016-2019 and has been provided by OAC-1836650 (IRIS-HEP) since 2019. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.

Owner

  • Name: Scikit-HEP Project
  • Login: scikit-hep
  • Kind: organization
  • Email: scikit-hep-forum@googlegroups.com

A community project for High Energy Physics data analysis in Python

Citation (CITATION.cff)

cff-version: 1.2.0
title: Particle
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
abstract: "Particle is a Python library for PDG particle data and identification codes."
authors:
  - family-names: Rodrigues
    given-names: Eduardo
    affiliation: University of Liverpool
    orcid: "https://orcid.org/0000-0003-2846-7625"
  - family-names: Schreiner
    given-names: Henry
    affiliation: Princeton University
    orcid: "https://orcid.org/0000-0002-7833-783X"
doi: 10.5281/zenodo.2552429
repository-code: "https://github.com/scikit-hep/particle"
keywords:
  - python
  - PDG particle data
  - MC identification codes
  - scikit-hep
license: "BSD-3-Clause"

GitHub Events

Total
  • Issues event: 3
  • Watch event: 8
  • Delete event: 44
  • Issue comment event: 48
  • Push event: 70
  • Pull request review comment event: 2
  • Pull request review event: 43
  • Pull request event: 90
  • Fork event: 3
  • Create event: 44
Last Year
  • Issues event: 3
  • Watch event: 8
  • Delete event: 44
  • Issue comment event: 48
  • Push event: 70
  • Pull request review comment event: 2
  • Pull request review event: 43
  • Pull request event: 90
  • Fork event: 3
  • Create event: 44

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 676
  • Total Committers: 20
  • Avg Commits per committer: 33.8
  • Development Distribution Score (DDS): 0.49
Past Year
  • Commits: 81
  • Committers: 7
  • Avg Commits per committer: 11.571
  • Development Distribution Score (DDS): 0.444
Top Committers
Name Email Commits
Eduardo Rodrigues e****s@c****h 345
pre-commit-ci[bot] 6****] 160
Henry Schreiner h****r@c****h 101
dependabot[bot] 4****] 29
allcontributors[bot] 4****] 17
Hans Dembinski H****i 4
Ludwig Neste 3****g 3
Tamas Gal t****l@m****m 2
Alexander Puck Neuwirth A****y 2
Maximilian Linhoff m****f@t****e 2
sourcery-ai[bot] 5****] 2
Adam Morris a****s@c****h 1
Aman Desai 9****i 1
Chris Burr c****r 1
Doron Behar d****r@g****m 1
Jonathan Tellechea y****b@v****u 1
Jost Migenda j****a@k****k 1
Matthew Feickert m****t@g****m 1
Remco de Boer 2****r 1
azure-pipelines[bot] a****] 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 19
  • Total pull requests: 385
  • Average time to close issues: 3 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 13
  • Total pull request authors: 11
  • Average comments per issue: 5.89
  • Average comments per pull request: 1.07
  • Merged pull requests: 349
  • Bot issues: 0
  • Bot pull requests: 250
Past Year
  • Issues: 5
  • Pull requests: 108
  • Average time to close issues: 8 days
  • Average time to close pull requests: 1 day
  • Issue authors: 4
  • Pull request authors: 7
  • Average comments per issue: 4.6
  • Average comments per pull request: 0.93
  • Merged pull requests: 99
  • Bot issues: 0
  • Bot pull requests: 83
Top Authors
Issue Authors
  • eduardo-rodrigues (4)
  • APN-Pucky (2)
  • redeboer (2)
  • maxnoe (2)
  • Starwarskust (1)
  • MartinTum (1)
  • The-Ludwig (1)
  • amanmdesai (1)
  • TanmayPani (1)
  • HDembinski (1)
  • JacekHoleczek (1)
  • ntadej (1)
  • yorkiva (1)
Pull Request Authors
  • pre-commit-ci[bot] (188)
  • eduardo-rodrigues (85)
  • dependabot[bot] (38)
  • henryiii (34)
  • allcontributors[bot] (34)
  • maxnoe (4)
  • APN-Pucky (3)
  • The-Ludwig (3)
  • JOTELLECHEA (2)
  • redeboer (2)
  • amanmdesai (1)
Top Labels
Issue Labels
⚙️ enhancement (6) help wanted (3) ❔ question (2) 💫 good first issue (1) 🐛 bug (1) data files (1)
Pull Request Labels
CI (189) 📝 documentation (43) dependencies (40) data files (40) ⚙️ enhancement (31) release (20) tests (8) bug fix (7) github_actions (6) chore (2)

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 288,118 last-month
  • Total docker downloads: 183
  • Total dependent packages: 28
    (may contain duplicates)
  • Total dependent repositories: 47
    (may contain duplicates)
  • Total versions: 68
  • Total maintainers: 3
pypi.org: particle

Extended PDG particle data and MC identification codes

  • Versions: 51
  • Dependent Packages: 23
  • Dependent Repositories: 43
  • Downloads: 288,118 Last month
  • Docker Downloads: 183
Rankings
Dependent packages count: 0.6%
Downloads: 2.2%
Dependent repos count: 2.2%
Docker downloads count: 2.5%
Average: 3.6%
Stargazers count: 6.0%
Forks count: 8.1%
Maintainers (2)
Last synced: 6 months ago
spack.io: py-particle

Particle provides a pythonic interface to the Particle Data Group (PDG) particle data tables and particle identification codes, with extended particle information and extra goodies.

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 16.9%
Forks count: 20.8%
Average: 23.8%
Dependent packages count: 57.3%
Maintainers (1)
Last synced: 10 months ago
conda-forge.org: particle
  • Versions: 13
  • Dependent Packages: 5
  • Dependent Repositories: 4
Rankings
Dependent packages count: 10.4%
Dependent repos count: 16.2%
Average: 23.8%
Stargazers count: 31.1%
Forks count: 37.4%
Last synced: 7 months ago

Dependencies

pyproject.toml pypi
  • attrs >=19.2
  • hepunits >=2.0.0
  • importlib-resources >=2.0;python_version<"3.9"
  • typing-extensions python_version<"3.8"
.github/workflows/cd.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v2 composite
  • actions/download-artifact v3 composite
  • actions/upload-artifact v3 composite
  • actions/upload-release-asset v1 composite
  • pypa/gh-action-pypi-publish v1.6.4 composite
  • wntrblm/nox 2022.11.21 composite
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • codecov/codecov-action v3 composite
  • pre-commit/action v3.0.0 composite
  • wntrblm/nox 2022.11.21 composite
environment.yml conda
  • attrs >=19.0
  • jupyterlab >=1.0
  • numpy >=1.16
  • pandas >=0.24
  • pip >=10.0
  • python >=3.7
  • rise
  • tabulate