-
(I name this issue as the task I need to do, but there is probably a better more technical name for this) I'm using awkward arrays as spit out by uproot4 from "flat" ROOT files. The problem is the following:
For the js, bs = ak.unzip(ak.cartesian((l1jets, genbs)))
dR = js.deltaR(bs) A small "snippet" is in this screenshot (don't know how to insert that here otherwise) Now what I would like to do is to create a new array/feauture e.g. If I'd knew there are always e.g. 2 gen particles in an event (like in the selection above), I could in principle just slice the dR_b1 = dR[:,0::2]
dR_b2 = dR[:,1::2] Given that I actually care about the dR being smaller than some threshold, I thought could then just do: (dR_b1 < 0.4) & (dR_b2 < 0.4) but that gives error This will in general not work when I have an a-priori unknown length of both of the input arrays. So I was wondering whether it would be possible to somehow slice/reshape the arrays using the per-event number of input objects, etc to create a smallest deltaR array for the reco jets. Alternatively, the Are there any built-in features that would allow this? Or an elegant way to achieve it without too much hacking. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A few weeks after that tutorial, I gave another tutorial that answered your question. (When writing it, I decided to go into more detail on these sorts of examples, but when I was presenting it, I didn't get to that part, so it's not in the video.) Something that I was going to do when presenting it live and didn't get a chance to: try swapping the The idea is that you pass That extra level of nesting gives you structure to "reduce" over. In this case, you want to reduce by ak.min or ak.argmin; i.e. find the jet-gen pair with the smallest ΔR. If instead of finding the "best match," you were only interested in whether there was "any match within a ΔR cut," the reducer you'd use would be ak.any. Reducing these nested lists, of which there is one for each of the So that's the idea; hopefully, the notebook will be a help. If that's too difficult to follow, I also worked through the same question again using Numba instead of Awkward array-at-a-time functions. If might be easier to read the nested "for" loops in Numba, and since it's JIT-compiled, it's feasible to use at large scales. |
Beta Was this translation helpful? Give feedback.
A few weeks after that tutorial, I gave another tutorial that answered your question. (When writing it, I decided to go into more detail on these sorts of examples, but when I was presenting it, I didn't get to that part, so it's not in the video.)
This is the relevant section.
Something that I was going to do when presenting it live and didn't get a chance to: try swapping the
abs(g.pdgId) == 13
withabs(g.pdgId) != 13
and see how the distribution of ΔR changes, once you have this notebook loaded and have evaluated cells up to this point.The idea is that you pass
nested=True
when computing ak.cartesian, which creates a new level of nesting in which the combinations are grouped by the l…