Skip to content

I3Filters #792

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/graphnet/data/extractors/icecube/utilities/i3_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,66 @@ def _keep_frame(self, frame: "icetray.I3Frame") -> bool:
"FilterMask filters will not be applied."
)
return True


class TableFilter(I3Filter):
"""A filter that checks if a table is present in the frame."""

def __init__(self, table_name: str):
"""Initialize TableFilter.

Args:
table_name: str
The name of the table to check for.
"""
self._table_name = table_name

def _keep_frame(self, frame: "icetray.I3Frame") -> bool:
"""Check that the frame has a table.

Args:
frame: I3-frame
The I3-frame to check.
"""
return frame.Has(self._table_name)


class ChargeFilter(I3Filter):
"""A filter that checks the recorded charge and requires a lower limit.

This also requires that the charge table is present in the frame.
"""

def __init__(
self, min_charge: float, table_name: str = "Homogenized_QTot"
):
"""Initialize ChargeFilter.

Args:
min_charge: The minimum charge required to keep the frame.
table_name: The name of the charge table.
"""
self._min_charge = min_charge
self._table_name = table_name

def _keep_frame(self, frame: "icetray.I3Frame") -> bool:
"""Check that the frame has a charge and that it is within the limits.

Args:
frame: I3-frame
"""
if frame.Has(self._table_name):
try:
charge = frame[self._table_name].value
return charge >= self._min_charge
except AttributeError:
try:
charge = frame[self._table_name].charge
return charge >= self._min_charge
except AttributeError:
self.warning_once(
f"Charge table {self._table_name} has no attribute\
'value' or 'charge'."
)
return False
return False