From 371e82cb73faaf57399cd2205ed1a8a58bc0cc38 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Thu, 10 Sep 2020 12:38:27 +0200 Subject: [PATCH 1/5] Remove awkward Particle.__init__ --- src/particle/particle/particle.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/particle/particle/particle.py b/src/particle/particle/particle.py index 9dcae19d..0adca451 100644 --- a/src/particle/particle/particle.py +++ b/src/particle/particle/particle.py @@ -608,11 +608,6 @@ def __hash__(self): # type: () -> int return hash(self.pdgid) - # Integer == PDGID - def __int__(self): - # type: () -> int - return int(self.pdgid) - # Shared with PDGID @property From 7054a0f8ef768f7b31a9f5a2226c7a8583fbb514 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Thu, 10 Sep 2020 13:22:17 +0200 Subject: [PATCH 2/5] Demo notebook updated accordingly --- notebooks/ParticleDemo.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/ParticleDemo.ipynb b/notebooks/ParticleDemo.ipynb index 824acd3b..daef7d5a 100644 --- a/notebooks/ParticleDemo.ipynb +++ b/notebooks/ParticleDemo.ipynb @@ -559,7 +559,7 @@ "metadata": {}, "outputs": [], "source": [ - "[int(p) for p in all_particles]" + "[int(p.pdgid) for p in all_particles]" ] }, { From 370a73c9cdb4535d2a270f4119b19bcfa2264f8a Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Thu, 10 Sep 2020 13:33:53 +0200 Subject: [PATCH 3/5] Adapt Particle class accordingly --- src/particle/particle/particle.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/particle/particle/particle.py b/src/particle/particle/particle.py index 0adca451..81575dae 100644 --- a/src/particle/particle/particle.py +++ b/src/particle/particle/particle.py @@ -590,11 +590,11 @@ def __le__(self, other): # Sort by absolute particle numbers # The positive one should come first if type(self) == type(other): - return abs(int(self) - 0.25) < abs(int(other) - 0.25) + return abs(int(self.pdgid) - 0.25) < abs(int(other.pdgid) - 0.25) # Comparison with anything else should produce normal comparisons. else: - return int(self) < other + return int(self.pdgid) < other def __eq__(self, other): # type: (Any) -> bool @@ -1038,9 +1038,9 @@ def findall( # particle=True is particle, False is antiparticle, and None is both if particle is not None: - if particle and int(item) < 0: + if particle and int(item.pdgid) < 0: continue - elif (not particle) and int(item) > 0: + elif (not particle) and int(item.pdgid) > 0: continue # If a filter function is passed, evaluate and skip if False From 2d4f398b69057fcb3fef8d980974169b8164e075 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Thu, 10 Sep 2020 13:34:26 +0200 Subject: [PATCH 4/5] Adapt tests accordingly --- tests/particle/test_particle.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/particle/test_particle.py b/tests/particle/test_particle.py index 10655a6b..f2374929 100644 --- a/tests/particle/test_particle.py +++ b/tests/particle/test_particle.py @@ -149,8 +149,8 @@ def test_pdg(): def test_pdg_convert(): p = Particle.from_pdgid(211) assert isinstance(p.pdgid, PDGID) - assert int(p) == 211 - assert PDGID(p) == 211 + assert p.pdgid == 211 + assert int(p.pdgid) == 211 def test_sorting(): @@ -576,7 +576,6 @@ def test_to_list(): def test_ampgen_style_names(name, pid): particle = Particle.from_string(name) - assert int(particle) == pid assert particle.pdgid == pid assert particle == pid From 2c0c1f3985bde74d3a21589d1dafff0d570c7026 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Thu, 10 Sep 2020 16:36:06 +0200 Subject: [PATCH 5/5] Fix notebook demo --- notebooks/ParticleDemo.ipynb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/notebooks/ParticleDemo.ipynb b/notebooks/ParticleDemo.ipynb index daef7d5a..5ce14e25 100644 --- a/notebooks/ParticleDemo.ipynb +++ b/notebooks/ParticleDemo.ipynb @@ -620,15 +620,6 @@ "p.pdgid" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "PDGID(p)" - ] - }, { "cell_type": "markdown", "metadata": {