uproot3-methods icon indicating copy to clipboard operation
uproot3-methods copied to clipboard

Store additional information in TLorentzVector

Open dguest opened this issue 6 years ago • 5 comments

I asked earlier about constructing the Lorentz vector objects directly from numpy arrays. That works really well! But I'd also like to be able to add additional information to the objects, i.e. in some cases we have other jet characteristics like b-tagging scores. Is there some method to append additional information (which is stored in another array) to each object?

dguest avatar Feb 07 '19 21:02 dguest

Yes. A TLorentzVectorArray contains a Table, so you should be able to attach or remove any other arrays to it, as long as they fit (same number of elements, and if jagged, same number in each subarray).

a = TLorentzVectorArray.from_ptetaphim(pt, eta, phi, mass)
a["isolation"] = isolation

and so on.

jpivarski avatar Feb 07 '19 21:02 jpivarski

OK, that's ridiculously easy.

dguest avatar Feb 07 '19 23:02 dguest

OK, while this obviously isn't the recommended way to do things, I noticed that when I looped over the jets the iterator seemed to return a regular TLorentzVector without the isolation attached. Is there some way to get both together? I noticed that the following seems to work:

for vec, iso in zip(vecarray, vecarray.content['isolation']):
    print(vec, iso)

but it's a bit clunky.

dguest avatar Feb 08 '19 00:02 dguest

To get that to work, I should have made the TLorentzVector object (singular) a mixin of Table.Row, instead of a separate class. At some point, I should do that so that you can get isolation from vec["isolation"].

I'll reopen this to remind myself to go back and do that.

jpivarski avatar Feb 08 '19 00:02 jpivarski

Another approach is to nest the ObjectArray inside a Table, e.g.

import awkward as ak
jets = ak.Table(
    p4=TLorentzVectorArray.from_ptetaphim(pt, eta, phi, mass),
    iso=isolation_vec,
)

Then it should carry around the fields, with the small inconvenience of having to access the lorentz vector properties through the name: jets.p4.pt, etc.

nsmith- avatar Oct 30 '19 17:10 nsmith-