From 8de00ffca02921e6f5220f14f448f543d252c200 Mon Sep 17 00:00:00 2001 From: Zineb Aly <zaly@km3net.de> Date: Thu, 12 Nov 2020 12:29:06 +0100 Subject: [PATCH] add is_CC function --- km3io/tools.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/km3io/tools.py b/km3io/tools.py index c4b6c0d..300da0e 100644 --- a/km3io/tools.py +++ b/km3io/tools.py @@ -763,3 +763,34 @@ def _find_in_set_single(rec_stages, stages, builder): else: builder.append(0) builder.end_list() + + +def is_CC(fobj): + """Determin if an event (or events) are a result of a Charged Curent interaction (CC) + or a Neutral Curent interaction (NC). + + Parameters + ---------- + fobj : km3io.offline.OfflineReader + offline neutrino file object. + """ + program = fobj.header.simul.program + w2list = fobj.events.w2list + len_w2lists = ak1.num(w2list, axis=1) + + if all(len_w2lists <= 7): # old nu file have w2list of len 7. + usr = fobj.events.mc_tracks.usr_names + cc_flag = usr[:, 0][:, 3] + out = (cc_flag == b'cc') # not very reliable, found NC files with cc flag! + + else: + if "gseagen" in program.lower(): + cc_flag = w2list[:, kw2gsg.W2LIST_GSEAGEN_CC] + out = (cc_flag > 0) + if "genhen" in program.lower(): + cc_flag = w2list[:, kw2gen.W2LIST_GENHEN_CC] + out = (cc_flag > 0) + else: + raise ValueError(f"simulation program {fobj.header.simul.program} is not implemented.") + + return out \ No newline at end of file -- GitLab