-
Notifications
You must be signed in to change notification settings - Fork 11
/
agc_schema.py
35 lines (31 loc) · 2.2 KB
/
agc_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from coffea.nanoevents.schemas.base import BaseSchema, zip_forms
from coffea.nanoevents.methods import base, vector
from coffea.nanoevents import transforms
class AGCSchema(BaseSchema):
def __init__(self, base_form):
super().__init__(base_form)
self._form["contents"] = self._build_collections(self._form["contents"])
def _build_collections(self, branch_forms):
names = set([k.split('_')[0] for k in branch_forms.keys() if not (k.startswith('number'))])
# Remove n(names) from consideration. It's safe to just remove names that start with n, as nothing else begins with n in our fields.
# Also remove GenPart, PV and MET because they deviate from the pattern of having a 'number' field.
names = [k for k in names if not (k.startswith('n') | k.startswith('met') | k.startswith('GenPart') | k.startswith('PV'))]
output = {}
for name in names:
offsets = transforms.counts2offsets_form(branch_forms['number' + name])
content = {k[len(name)+1:]: branch_forms[k] for k in branch_forms if (k.startswith(name + "_") & (k[len(name)+1:] != 'e'))}
# Add energy separately so its treated correctly by the p4 vector.
content['energy'] = branch_forms[name+'_e']
# Check for LorentzVector
output[name] = zip_forms(content, name, 'PtEtaPhiELorentzVector', offsets=offsets)
# Handle GenPart, PV, MET. Note that all the nPV_*'s should be the same. We just use one.
output['met'] = zip_forms({k[len('met')+1:]: branch_forms[k] for k in branch_forms if k.startswith('met_')}, 'met')
output['GenPart'] = zip_forms({k[len('GenPart')+1:]: branch_forms[k] for k in branch_forms if k.startswith('GenPart_')}, 'GenPart', offsets=transforms.counts2offsets_form(branch_forms['numGenPart']))
output['PV'] = zip_forms({k[len('PV')+1:]: branch_forms[k] for k in branch_forms if (k.startswith('PV_') & ('npvs' not in k))}, 'PV', offsets=transforms.counts2offsets_form(branch_forms['nPV_x']))
return output
@property
def behavior(self):
behavior = {}
behavior.update(base.behavior)
behavior.update(vector.behavior)
return behavior