Calculate all configurations of leptons with opposite charge #1285
Replies: 1 comment 9 replies
-
Hi @cesarecazzaniga My understanding of your problem is:
If I've correctly described your problem, then at a high-level it sounds like you want to generate an array of proposal = ...
metric = np.sum(proposal.slot0.deltaR2(proposal.slot1), axis=-1)
i_best = ak.argmin(metric, keepdims=True, axis=-1)
best = proposal[i_best] The difficulty here is, I imagine, generating your proposals. One option is to take all of the permutations over the sequence, and then the valid pairs within that sequence. We don't have a built-in method for generating random permutations, but you could implement Heap's algorithm to compute them with Numba. Still, this is likely not a good solution - for a start, it is explosively combinatorial, so I'd like to clarify that this is what you're trying to do first! Here's an example of generating the permutations. I probably would not do this in actual code, because of how quick it is to consume all of your RAM https://gist.github.com/agoose77/0c4ef3ee7582aebf75871e5974f4af72 Note that generating the permutations this way includes repeats - this doesn't account for the fact that the order between pairs does not matter, or that (a, b) is the same pair as (b, a) |
Beta Was this translation helpful? Give feedback.
-
Dear experts,
I have a question regarding the implementation of the following calculation with awkward arrays.
Let's say I have an array with electrons for each event (with pt, phi, eta, pdgid, charge, etc...), and I want to calculate the invariant mass of all the di-electron pairs with the correct charge configurations. Since the choice of the correct charge configuration is not unique, then I would like to pick up the configuration which minimise a metric f. Let's say the metric f could be the sum of the distances delta R ^2 for each given couple in a given charge configuration (not sure about this metric choice, but I had a try on a c++ code and seems to reasonably work .... but maybe there can be better possibilities).
So, let' say I have 4 electrons: e1+, e2-, e3+, e4- , first I would like to have all the allowed couples (+,-): {(1+,2-) , (3+,4-)} or {(1+,4-),(2-,3+)}.
After that I want to calculate for each of charge configuration the metric f, eg. : f({(1+,2-) , (3+,4-)}) = deltaR(1,2)^2 + deltaR(3,4)^2.
Finally, I want to find the unique charge configuration that minimise the given metric.
Could you please guide me a bit on how to implement this ?
Let me know, and thanks in advance for the help !
Beta Was this translation helpful? Give feedback.
All reactions