scikit-hep / uproot3-methods

Pythonic behaviors for non-I/O related ROOT classes.
BSD 3-Clause "New" or "Revised" License
21 stars 28 forks source link

ROOT::Math::LorentzVector #54

Closed beojan closed 5 years ago

beojan commented 5 years ago

The documentation for ROOT master recommends using ROOT::Math::LorentzVector specializations instead of TLorentzVector (https://root.cern.ch/doc/master/classTLorentzVector.html). We can't do this with uproot until these are added to uproot_methods.

jpivarski commented 5 years ago

One of the advantages of the ROOT::Math::LorentzVector class is that it is split into branches. The relative disadvantage is that uproot doesn't see this as one branch, because it is split. However, the four branches are exactly what the TLorentzVectorArray constructor needs:

uproot_methods.TLorentzVectorArray.from_cartesian(
    *tree.arrays(["px", "py", "pz", "E"], outputtype=tuple))

with the appropriate branch names for "px", "py", "pz", "E". If you're using a Lorentz vector in cylindrical coordinates, use from_cylindrical, from_ptetaphim, etc. This constructor was added for users who make Lorentz vectors completely outside of ROOT, yet want to have the same interface. The arguments may be flat or jagged arrays (with the same jaggedness), and may be constants (useful if you need to set mass as a constant).

Ironically, the old TLorentzVector was much more difficult to deserialize (its non-split branches had to be presented to Numpy as a non-trivial stride), but the new classes require more manual intervention (because uproot doesn't see the branch as a unit).