Replies: 1 comment
-
The hepconvert package contains high-level functions to do this sort of thing, so that you don't have to write scripts like the above anymore. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Edit: See the next comment below. Now there's a package that provides a convenience function for this!
This is such a common request that there ought to be a simple function that just copies TBranches. (Does anyone have time to write such a function?) Meanwhile, this is a rough guide.
If you just try to read from Uproot into an Awkward Array and write that same Awkward Array back, it doesn't work:
and now writing:
It was a giant usability oversight for me to not realize that someone might want to write the same array they just read, without modification.
The error here is because the output-writer (assigning to
outfile["tree"]
) is expecting adict
, andarrays
is anak.Array
.Okay, we can make a$p_T$ ) with ak.unzip.
dict
. We can get all of the record field names (e.g."Jet_Px"
) with ak.fields and all of the field values (e.g. the array corresponding to jetThis is able to write...
...but it's probably not what you want.
It's because the Awkward Array doesn't know that all jet attributes have the same number of values per event and all muon attributes have the same number of values per event, and so Uproot has to make a separate counter for each.
You can inform Uproot that these arrays should share counters by putting them into the same records:
(If they were not compatible, the ak.zip would fail.) The important thing now is that the
var
is outside the record in the type descriptor: all of these attributes have the same raggedness (and different between jets and muons).Now Uproot has enough information to make only one counter for each particle type.
and that's probably what you want.
Beta Was this translation helpful? Give feedback.
All reactions