196 def preselection_cut(self, candidate, IP_cut: float = 250, show_table: bool = False) -> bool:
197 """
198 Umbrella method to apply the pre-selection cuts on the candidate.
199
200 show_table=True tabulates the pre-selection parameters.
201 """
202 flag = True
203
204 if len(self.tree.Particles) != 1:
205 flag = False
206 if not (self.is_in_fiducial(candidate)):
207 flag = False
208 if self.dist_to_innerwall(candidate) <= 5 * u.cm:
209 flag = False
210 if self.dist_to_vesselentrance(candidate) <= 100 * u.cm:
211 flag = False
212 if self.impact_parameter(candidate) >= IP_cut * u.cm:
213 flag = False
214 if self.DOCA(candidate) >= 1 * u.cm:
215 flag = False
216 if np.any(self.nDOF(candidate) <= 25):
217 flag = False
218 if np.any(self.chi2nDOF(candidate) >= 5):
219 flag = False
220 if np.any(self.daughtermomentum(candidate) <= 1 * u.GeV):
221 flag = False
222
223 if show_table:
224 table = [
225 [
226 "Number of candidates in event",
227 len(self.tree.Particles),
228 "==1",
229 len(self.tree.Particles) == 1,
230 ],
231 [
232 "Time @ decay vertex (ns)",
233 self.define_candidate_time(candidate),
234 "",
235 "",
236 ],
237 [
238 "Impact Parameter (cm)",
239 self.impact_parameter(candidate),
240 f"IP < {IP_cut * u.cm} cm",
241 self.impact_parameter(candidate) < IP_cut * u.cm,
242 ],
243 [
244 "DOCA (cm)",
245 self.DOCA(candidate),
246 "DOCA < 1 cm",
247 self.DOCA(candidate) < 1 * u.cm,
248 ],
249 [
250 "Is within Fiducial Volume?",
251 self.is_in_fiducial(candidate),
252 "True",
253 self.is_in_fiducial(candidate),
254 ],
255 [
256 "Dist2InnerWall (cm)",
257 self.dist_to_innerwall(candidate),
258 "> 5 cm",
259 self.dist_to_innerwall(candidate) > 5 * u.cm,
260 ],
261 [
262 "Dist2VesselEntrance (cm)",
263 self.dist_to_vesselentrance(candidate),
264 "> 100 cm",
265 self.dist_to_vesselentrance(candidate) > 100 * u.cm,
266 ],
267 ["Invariant Mass (GeV)", self.invariant_mass(candidate), "", ""],
268 [
269 "Daughter Momentum [d1, d2] (GeV)",
270 self.daughtermomentum(candidate),
271 "> 1 GeV",
272 np.all(self.daughtermomentum(candidate) > 1 * u.GeV),
273 ],
274 [
275 "Degrees of Freedom [d1, d2]",
276 self.nDOF(candidate),
277 "> 25",
278 np.all(self.nDOF(candidate) > 25),
279 ],
280 [
281 "Reduced Chi^2 [d1, d2]",
282 self.chi2nDOF(candidate),
283 "< 5",
284 np.all(self.chi2nDOF(candidate) < 5),
285 ],
286 ["\033[1mPre-selection passed:\033[0m", "", "", flag],
287 ]
288
289 for row in table:
290 row[3] = (
291 f"\033[1;32m{row[3]}\033[0m" if row[3] else f"\033[1;31m{row[3]}\033[0m"
292 )
293
294 print(
295 tabulate(
296 table,
297 headers=[
298 "Parameter",
299 "Value",
300 "Pre-selection cut",
301 "Pre-selection Check",
302 ],
303 tablefmt="grid",
304 )
305 )
306 return flag
307
308