@@ -155,3 +155,66 @@ def _keep_frame(self, frame: "icetray.I3Frame") -> bool:
155155 "FilterMask filters will not be applied."
156156 )
157157 return True
158+
159+
160+ class TableFilter (I3Filter ):
161+ """A filter that checks if a table is present in the frame."""
162+
163+ def __init__ (self , table_name : str ):
164+ """Initialize TableFilter.
165+
166+ Args:
167+ table_name: str
168+ The name of the table to check for.
169+ """
170+ self ._table_name = table_name
171+
172+ def _keep_frame (self , frame : "icetray.I3Frame" ) -> bool :
173+ """Check that the frame has a table.
174+
175+ Args:
176+ frame: I3-frame
177+ The I3-frame to check.
178+ """
179+ return frame .Has (self ._table_name )
180+
181+
182+ class ChargeFilter (I3Filter ):
183+ """A filter that checks the recorded charge and requires a lower limit.
184+
185+ This also requires that the charge table is present in the frame.
186+ """
187+
188+ def __init__ (
189+ self , min_charge : float , table_name : str = "Homogenized_QTot"
190+ ):
191+ """Initialize ChargeFilter.
192+
193+ Args:
194+ min_charge: The minimum charge required to keep the frame.
195+ table_name: The name of the charge table.
196+ """
197+ self ._min_charge = min_charge
198+ self ._table_name = table_name
199+
200+ def _keep_frame (self , frame : "icetray.I3Frame" ) -> bool :
201+ """Check that the frame has a charge and that it is within the limits.
202+
203+ Args:
204+ frame: I3-frame
205+ """
206+ if frame .Has (self ._table_name ):
207+ try :
208+ charge = frame [self ._table_name ].value
209+ return charge >= self ._min_charge
210+ except AttributeError :
211+ try :
212+ charge = frame [self ._table_name ].charge
213+ return charge >= self ._min_charge
214+ except AttributeError :
215+ self .warning_once (
216+ f"Charge table { self ._table_name } has no attribute\
217+ 'value' or 'charge'."
218+ )
219+ return False
220+ return False
0 commit comments