Problem with reading (awkward) TClonesArray of TLorentzVectors #462
-
I've refrained from asking a question about this since my understanding of the ROOT data structure is fairly limited, but I work with TTrees which contain branches that have TClonesArrays of TLorentzVectors, and they don't seem to read properly when I use the usual Uproot methods. I noticed in one of the recent pull requests (442) that something related to TClonesArrays was implemented, but I'm still having the same problem, so I was wondering if it is an issue with my usage of Uproot or if it's an issue with how my collaboration generates the TTrees. For some context, we have a single TTree with multiple branches. However, for each event, in our branches of 4-vectors, we have a TClonesArray object that doesn't necessarily contain the same number of vectors for each event (we say there are multiple "combos" or combinations of particles which can constitute each event, and this is the way they're stored). Unfortunately, I believe this is the cause of a problem when I try to load one of these branches into an array, since I get the error:
Is there some simple thing I can do about this? I can see the data in a single event easily with
So this event appears to have a TClonesArray with two entries, or two combos, but other events might have one, or three, or more. Originally I thought my problem was just something about Uproot not playing well with TClonesArrays, but now I'm fairly certain it has to do with the arrays having different sizes. I'm admittedly out of my depth here, if there's no solution, or no easy solution to this, please let me know. Edit: For those curious, I there is a simple method (in ROOT or PyROOT) for flattening these structures such that each branch contains one event per combo, which is simply looping over all events, and sublooping over each combo and writing a new event to a new branch for each combo. If there's a way to do this using uproot, that would also be of interest to me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Sorry that I didn't get back to this earlier, but maybe try The error message is saying that it can't convert the data into an Awkward Array. Your array contains a TObjArray, which is a dynamically typed list: it can contain any TObject; you don't know what types are in it until you read it. Awkward Arrays have to be statically typed so that we can split up the data into columnar buffers, which requires knowing which fields all nested records contain. Maybe I need to expand upon that error message. I'm not guaranteeing that it will work with |
Beta Was this translation helpful? Give feedback.
Sorry that I didn't get back to this earlier, but maybe try
library="np"
? Since this is not strictly numerical data, that NumPy array would havedtype="O"
and it would effectively be a Python list. Iteration over it would run at Python speeds, but slow access is better than no access.The error message is saying that it can't convert the data into an Awkward Array. Your array contains a TObjArray, which is a dynamically typed list: it can contain any TObject; you don't know what types are in it until you read it. Awkward Arrays have to be statically typed so that we can split up the data into columnar buffers, which requires knowing which fields all nested records contain. Maybe I need to…