scikit-hep / particle

Package to deal with particles, the PDG particle data table, PDGIDs, etc.
BSD 3-Clause "New" or "Revised" License
151 stars 24 forks source link

Make sure neutron, proton and their anti-particles compare equal #622

Closed maxnoe closed 2 months ago

maxnoe commented 2 months ago

I added two dicts that are build at import time, one mapping one pdgid to the alternative representation to implement the comparison and one with the "preferred" pdgid used for __hash__ and to make from_name work and always return the same pdgid.

I chose the "bag of quarks" ids for the "preferred" options, for no particular reason.

Edit: that's actually the official recommendation:

To avoid ambiguities, nuclear codes should not be applied to a single hadron, like p, n or Λ0, where quark-contents-based codes already exist.

From that I infer though, that neutron and proton are not the only cases, also the delta resonance at least.

Closes https://github.com/scikit-hep/particle/issues/620.

codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.20%. Comparing base (4f8e0cb) to head (bb574cc). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #622 +/- ## ========================================== + Coverage 96.07% 96.20% +0.13% ========================================== Files 32 32 Lines 1324 1343 +19 ========================================== + Hits 1272 1292 +20 + Misses 52 51 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

eduardo-rodrigues commented 2 months ago

Thanks very much @maxnoe for the speedy action 👍! I've got something urgent to finish today but will get back to this really soon.

I hope this also handles the feature https://github.com/scikit-hep/particle/issues/620.

Oh, I see you got those quotes from the docstring for nuclei, which I probably got from somewhere such as periodictable when including the nuclei. It would be easier if no nucleus codes existed for the proton and neutron, but ...

Indeed the scheme can also handle hypernuclei with a p or n being replaced by a Lambda. Some are known, and for example have been studied by ALICE and LHCb :-).

maxnoe commented 2 months ago

I hope this also handles the feature https://github.com/scikit-hep/particle/issues/620.

Yes, see the tests

maxnoe commented 2 months ago

Yes, from my side this is ready

eduardo-rodrigues commented 2 months ago

Thank you again.

eduardo-rodrigues commented 2 months ago

@all-contributors please add @maxnoe for code

allcontributors[bot] commented 2 months ago

@eduardo-rodrigues

I've put up a pull request to add @maxnoe! :tada: