Skip to content

Initiatlize a 4 vector with pt, rapidity, phi, m #586

@nhartman94

Description

@nhartman94

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!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions