scikit-hep / scikit-hep/vector
Initiatlize a 4 vector with pt, rapidity, phi, m
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 99
- Forks
- 42
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 6
Description
Describe the potential feature
Hi ! Is there a way to make a 4 vector with rapidity instead of pseudo rapidity?
I'm including a "minimal example" of what would be nice :)
pt = [2,1]
rap = [-1,2]
phi=[0,1]
m=[.139,.139]
arr = ak.zip(
{
"pt": pt,
"rapidity": rap,
"phi": phi,
"m": m,
},
with_name="Momentum4D",
)
ak.sum(arr).mass
Right now, the error message is:
ValueError Traceback (most recent call last)
Cell In[238], [line 1](vscode-notebook-cell:?execution_count=238&line=1)
----> [1](vscode-notebook-cell:?execution_count=238&line=1) ak.sum(arr).mass
File ~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:38, in named_high_level_function.<locals>.dispatch(*args, **kwargs)
[35](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:35) @wraps(func)
[36](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:36) def dispatch(*args, **kwargs):
[37](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:37) # NOTE: this decorator assumes that the operation is exposed under `ak.`
---> [38](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:38) with OperationErrorContext(name, args, kwargs):
[39](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:39) gen_or_result = func(*args, **kwargs)
[40](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:40) if isgenerator(gen_or_result):
File ~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:80, in ErrorContext.__exit__(self, exception_type, exception_value, traceback)
[78](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:78) self._slate.__dict__.clear()
[79](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:79) # Handle caught exception
---> [80](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:80) raise self.decorate_exception(exception_type, exception_value)
[81](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:81) else:
[82](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:82) # Step out of the way so that another ErrorContext can become primary.
[83](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_errors.py:83) if self.primary() is self:
File ~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:64, in named_high_level_function.<locals>.dispatch(*args, **kwargs)
[62](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:62) # Failed to find a custom overload, so resume the original function
[63](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:63) try:
---> [64](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/awkward/_dispatch.py:64) next(gen_or_result)
...
[259](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/vector/backends/awkward.py:259) "array does not have longitudinal coordinates (z/pz or theta or eta): "
[260](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/vector/backends/awkward.py:260) f"{', '.join(fields)}"
[261](https://file+.vscode-resource.vscode-cdn.net/Users/nicolehartman/Programming/Jet-Clustering/pythia/~/miniforge3/lib/python3.12/site-packages/vector/backends/awkward.py:261) )
ValueError: array does not have longitudinal coordinates (z/pz or theta or eta): pt, rapidity, phi, m
Motivation
As the message suggests, the above code snippet works if I pass eta instead of rapidity, but I'd like to pass rapidity instead in some cases w/o doing the variable transform first to pz or theta.
1802.05356 motivates using rapidity instead of pseudorapidity for HEP :)
Possible Implementation
If you guys give me a pointer where to edit the package, I think I could implement this myself too.
Thank you so much for all the great work on this package, I've loved using it in my workflows, and I'm very enthusiastic supporter of you all!!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the coordinate validation shown in vector/backends/awkward.py around line 259, then reproduce the issue's ak.zip and ak.sum example. The work is done when Momentum4D accepts pt, rapidity, phi, and m and the summed vector's mass can be computed, with coverage for the demonstrated inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100