Skip to content

Commit

Permalink
Return preferred pdgid in from_nucleus_info
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Sep 6, 2024
1 parent 0236134 commit 314d754
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/particle/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,10 @@ def from_nucleus_info(
pdgid = int(1e9 + l_strange * 1e5 + z * 1e4 + a * 10 + i)

if anti:
return cls.from_pdgid(-pdgid)
pdgid = -pdgid

# replace nucleon ids of single hadrons with quark version
pdgid = _PREFERRED_PDGID.get(pdgid, pdgid)

return cls.from_pdgid(pdgid)

Expand Down
4 changes: 4 additions & 0 deletions tests/particle/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def test_from_nucleus_info():
p = Particle.from_nucleus_info(1, 2, anti=True)
assert p.pdgid == -1000010020

# proton and neutron should return the preferred quark representation
assert Particle.from_nucleus_info(a=1, z=1).pdgid == 2212
assert Particle.from_nucleus_info(a=1, z=0).pdgid == 2112


def test_from_nucleus_info_ParticleNotFound():
with pytest.raises(ParticleNotFound):
Expand Down

0 comments on commit 314d754

Please sign in to comment.