Repository navigation
Conversation
…ivisionError rhophi_z divided z by rho with Python numbers, so rho == 0 raised instead of giving +-inf like the x-y-z form. Use lib.true_divide, as scikit-hep#754 does for rapidity.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With Python numbers,
etaandcotthetaof a rho-phi-z vector on the z axis raise, while the same vector in x-y-z form gives±inf:deltaRanddeltaetafail the same way, since they useeta.rhophi_zcomputesz / rhowith Python floats (or ints).xy_zdivides bylib.sqrt(x**2 + y**2), a NumPy float, so it getsinfinstead.This uses
lib.true_divide(z, rho)inspatial/eta.pyandspatial/cottheta.py.nan_to_numthen gives the same±inf(or0foretaat the origin) as the x-y-z form. It's the same approach as #754 forrapidity. The sympy backend needs atrue_dividemethod for this, and I've added it with exactly the same lines as #754, so either PR can merge first without a conflict.I found these by checking all properties for vectors with zero components in each coordinate system. The
to_beta3failures at exactly zero energy are a different case, so I left them out.Checklist
ruff formatis clean on the changed files;ruff checkonly reports existing findings in_methods.py)test_rhophi_z_on_z_axisintest_eta.pyandtest_cottheta.py(int and float zeros,znegative, zero and positive), all failing onmain. Full suite: 4884 passed. The one failure,test_issue_463, also fails onmain(thedeltaangleprecision issue in theta and deltaangle lose precision for small angles #759).AI usage
This PR was prepared with Claude Code (Anthropic's Claude). It found the failing cases, wrote the fix and tests, and ran the test suite. I directed the work and take responsibility for the change, and I'm happy to explain or rework any part of it.