How to obtain matched genJets into an matching array with Jet #1223
-
Hello, I am trying to double check that delta_r of Jet and GenJet saved in Jet.genJetIdx is indeed less than 0.4. However, I am having a hard time writing this in code. What I would like to do is something like:
However, I get errors in the indexing of the genjets something to the effect of:
I am 95% certain that I am missing some neat awkward array trick, but I couldn't find them in the documentation. Some hints would be much appreciated! Thank you in advance, Hyeon-Seo |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I believe your problem is in the What I would personally use is something that is alreayd built in coffea. And that is In [6]: events = NanoEventsFactory.from_root({"../../coffea_dev/coffea/tests/samples/nano_dy.root": "Events"}, delayed=False).events()
/Users/iason/miniforge3/envs/egamma_dev/lib/python3.10/site-packages/coffea/nanoevents/schemas/nanoaod.py:264: RuntimeWarning: Missing cross-reference index for LowPtElectron_electronIdx => Electron
warnings.warn(
/Users/iason/miniforge3/envs/egamma_dev/lib/python3.10/site-packages/coffea/nanoevents/schemas/nanoaod.py:264: RuntimeWarning: Missing cross-reference index for LowPtElectron_genPartIdx => GenPart
warnings.warn(
/Users/iason/miniforge3/envs/egamma_dev/lib/python3.10/site-packages/coffea/nanoevents/schemas/nanoaod.py:264: RuntimeWarning: Missing cross-reference index for LowPtElectron_photonIdx => Photon
warnings.warn(
/Users/iason/miniforge3/envs/egamma_dev/lib/python3.10/site-packages/coffea/nanoevents/schemas/nanoaod.py:264: RuntimeWarning: Missing cross-reference index for FatJet_genJetAK8Idx => GenJetAK8
warnings.warn(
In [7]: events.Jet
Out[7]: <JetArray [[Jet, ..., Jet], ...] type='40 * var * Jet[area: float32[paramet...'>
In [8]: events.Jet.matched_gen
Out[8]: <PtEtaPhiMCollectionArray [[{eta: 1.55, ...}, ..., None], ...] type='40 * v...'>
In [9]: events.GenJet
Out[9]: <PtEtaPhiMCollectionArray [[{eta: 1.55, ...}, ..., {...}], ...] type='40 * ...'>
In [10]: events.Jet.delta_r(events.Jet.matched_gen)
Out[10]: <Array [[0.011, 0.085, 0.152, None, None], ...] type='40 * var * ?float32'> And with this In [11]: ak.all(events.Jet.delta_r(events.Jet.matched_gen) < 0.4)
Out[11]: True |
Beta Was this translation helpful? Give feedback.
I believe your problem is in the
matched_gjets = genjets.eta[matched_jets.genJetIdx]
line.matched_jets.genJetIdx
has the same dimensionality asevents.Jet
so you can't maskevents.GenJet
with it, onlyevents.Jet
.What I would personally use is something that is alreayd built in coffea. And that is
events.Jet.matched_gen
. This will give you an awkward array ofGenJet
s with the same dimensionality asevents.Jet
whereJet
s that are associated with aGenJet
through thegenJetIdx
index are replaced by the correspondingGenJet
andNone
otherwise. That way you can skip doing all that yourself.Then you could calculate the deltaR between the matched genjets and jet like
events.Jet.delta_r(events…