-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/object collection #22
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import numpy as np | ||
import awkward as ak | ||
|
||
class CollectObject: | ||
|
||
def __init__(self, events): | ||
self.events = events | ||
|
||
def CreateMask(self, variable, cut): | ||
loaded = self.objects[variable] | ||
sign = cut[0] | ||
value = cut[1] | ||
if sign == "==": | ||
self.mask = self.mask & (loaded == value) | ||
elif sign == ">=": | ||
self.mask = self.mask & (loaded >= value) | ||
elif sign == ">": | ||
self.mask = self.mask & (loaded > value) | ||
elif sign == "<=": | ||
self.mask = self.mask & (loaded <= value) | ||
elif sign == "<": | ||
self.mask = self.mask & (loaded < value) | ||
elif sign == "!=": | ||
self.mask = self.mask & (loaded != value) | ||
else: | ||
pass | ||
|
||
def Electron(self, cuts): | ||
self.objects = self.events["Electron"] | ||
self.mask = ak.ones_like(self.objects["pt"], dtype=bool) | ||
for variable, cut in cuts.items(): | ||
self.CreateMask(variable, cut) | ||
return self.objects[self.mask] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not implemented yet but
So we can keep all object selection issues here |
||
|
||
def Muon(self, cuts): | ||
self.objects = self.events["Muon"] | ||
self.mask = ak.ones_like(self.objects["pt"], dtype=bool) | ||
for variable, cut in cuts.items(): | ||
self.CreateMask(variable, cut) | ||
return self.objects[self.mask] | ||
|
||
def Tau(self, cuts): | ||
self.objects = self.events["Tau"] | ||
self.mask = ak.ones_like(self.objects["pt"], dtype=bool) | ||
for variable, cut in cuts.items(): | ||
self.CreateMask(variable, cut) | ||
return self.objects[self.mask] | ||
|
||
def Jet(self, cuts): | ||
self.objects = self.events["Jet"] | ||
self.mask = ak.ones_like(self.objects["pt"], dtype=bool) | ||
for variable, cut in cuts.items(): | ||
self.CreateMask(variable, cut) | ||
return self.objects[self.mask] | ||
|
||
def FatJet(self, cuts): | ||
self.objects = self.events["FatJet"] | ||
self.mask = ak.ones_like(self.objects["pt"], dtype=bool) | ||
for variable, cut in cuts.items(): | ||
self.CreateMask(variable, cut) | ||
return self.objects[self.mask] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import dask.array as da | ||
import dask_awkward as dak | ||
from coffea.analysis_tools import PackedSelection | ||
from CollectObject import CollectObject | ||
import time | ||
import re | ||
|
||
|
@@ -175,8 +176,15 @@ def process(self, events): | |
# OBJECT SELECTION # | ||
#################### | ||
|
||
# muon and electron selections are broken out into standalone functions | ||
tightElectrons, looseElectrons = selectElectrons(events) | ||
coll = CollectObject(events) | ||
tightElectrons = coll.Electron({ | ||
"pt" : (">", 53), | ||
"eta" : ("<", 2.4), | ||
}) | ||
looseElectrons = coll.Electron({ | ||
"pt" : (">", 53), | ||
"eta" : ("<", 2.4), | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just demonstrating how it could be used, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you want more userfirendly approach, we can add
but maybe not worth it? not sure |
||
nTightElectrons = ak.num(tightElectrons) | ||
|
||
tightMuons, looseMuons = selectMuons(events) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part i am not so proud of but didn't find a way to better configure this in a generic way. any ideas?
but because dask already optimizes the pipeline, it won't disturb the computing performance too much