Skip to content
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

Simplify match for pema issue #74

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion jobs/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ t_sleep = 1

[job]
container = xenonnt-development.simg
runids = 021952,022510,022776,022773,022738,022735,022732,022726,022723,022717,022694,022691,022685,028636,031661,031124,029866,027982,030329,025444,027513,030891,025416,025161,028945,031709,028239,030937,028510,028636,031661,031124,029866,027982,030329,025444,027513,030891,025416,025161,028945,031709,028239,030937,028510,027323,026550,025953,031657,029198,026577,028031,025719,029208,026624,031147,028426,030102,029144,029472,027705,031156,031802,026503,029139,028047,025579,030079,025953,028542,025413,031803,029938,030287,026603,028890,030128,029410,031761
runids = 021952,022510,022776,022773,022738,022735,022732,022726,022723,022717,022694,022691,022685,022682,022679,022676,022670,022667,028636,031661,031124,029866,027982,030329,025444,027513,030891,025416,025161,028945,031709,028239,030937,028510,028636,031661,031124,029866,027982,030329,025444,027513,030891,025416,025161,028945,031709,028239,030937,028510,027323,026550,025953,031657,029198,026577,028031,025719,029208,026624,031147,028426,030102,029144,029472,027705,031156,031802,026503,029139,028047,025579,030079,025953,028542,025413,031803,029938,030287,026603,028890,030128,029410,031761
output_folder = /project/lgrandi/yuanlq/salt/
saltax_mode = salt
faxconf_version = sr0_v4
Expand Down
37 changes: 17 additions & 20 deletions saltax/match/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from tqdm import tqdm


def filter_out_missing_s1_s2(truth, match):
def filter_out_missing_s1_s2(truth):
"""
Filter out simulated events that have no S1 or S2 or both
:param truth: truth from wfsim
:param match: match_acceptance_extended from pema
:return: filtered truth and match
:return: filtered truth
"""
bad_mask = np.zeros(len(truth), dtype=bool)
max_event_number = np.max(np.unique(truth['event_number']))
Expand All @@ -30,15 +29,14 @@ def filter_out_missing_s1_s2(truth, match):

print("Filter out %s percent of events due to missing S1 or S2 or both"\
% (np.sum(bad_mask)/len(truth)*100))
return truth[~bad_mask], match[~bad_mask]
return truth[~bad_mask]


def filter_out_multiple_s1_s2(truth, match):
def filter_out_multiple_s1_s2(truth):
"""
Filter out simulated events that have multiple S1 or S2 reconstructed from wfsim.
:param truth: truth from wfsim
:param match: match_acceptance_extended from pema
:return: filtered truth and match
:return: filtered truth
"""
bad_mask = np.zeros(len(truth), dtype=bool)
max_event_number = np.max(np.unique(truth['event_number']))
Expand All @@ -54,7 +52,7 @@ def filter_out_multiple_s1_s2(truth, match):

print("Filter out %s percent of events due to multiple S1 or S2"\
% (np.sum(bad_mask)/len(truth)*100))
return truth[~bad_mask], match[~bad_mask]
return truth[~bad_mask]


def filter_out_not_found(truth, match):
Expand Down Expand Up @@ -140,10 +138,10 @@ def pair_events_to_matched_simu(matched_simu, events):
j_selected_events = np.where((events['s1_endtime']>=e_simu['s1_time'])&
(e_simu['s1_endtime']>=events['s1_time']))[0]

j_selected_events = np.where((events['s1_endtime']>=e_simu['s1_time'])&
(e_simu['s1_endtime']>=events['s1_time'])&
(events['s2_endtime']>=e_simu['s2_time'])&
(e_simu['s2_endtime']>=events['s2_time']))[0]
#j_selected_events = np.where((events['s1_endtime']>=e_simu['s1_time'])&
# (e_simu['s1_endtime']>=events['s1_time'])&
# (events['s2_endtime']>=e_simu['s2_time'])&
# (e_simu['s2_endtime']>=events['s2_time']))[0]
assert len(j_selected_events) <= 1, "Multiple events found for one truth event!?"

# If no event is found, then we consider lost
Expand All @@ -156,17 +154,16 @@ def pair_events_to_matched_simu(matched_simu, events):
return matched_to


def pair_salt_to_simu(truth, match, events_simu, events_salt):
def pair_salt_to_simu(truth, events_simu, events_salt):
"""
Filter out bad simulation truth and then pair salted events to matched simulation events.
:param truth: filtered truth
:param match: match_acceptance_extended from pema
:param events_simu: events from wfsim
:param events_salt: events from saltax after reconstruction
:return: ind_salt_matched_to_simu, ind_simu_matched_to_truth, truth_filtered, match_filtered
:return: ind_salt_matched_to_simu, ind_simu_matched_to_truth, truth_filtered
"""
truth_filtered, match_filtered = filter_out_missing_s1_s2(truth, match)
truth_filtered, match_filtered = filter_out_multiple_s1_s2(truth_filtered, match_filtered)
truth_filtered = filter_out_missing_s1_s2(truth)
truth_filtered = filter_out_multiple_s1_s2(truth_filtered)
# Temporarily turn off this filter because of wfsim bug in s2 timing
#truth_filtered, match_filtered = filter_out_not_found(truth_filtered, match_filtered)

Expand All @@ -176,10 +173,10 @@ def pair_salt_to_simu(truth, match, events_simu, events_salt):
ind_salt_matched_to_simu = pair_events_to_matched_simu(events_simu_matched_to_truth,
events_salt)

return ind_salt_matched_to_simu, ind_simu_matched_to_truth, truth_filtered, match_filtered
return ind_salt_matched_to_simu, ind_simu_matched_to_truth, truth_filtered


def match(truth, match, events_simu, events_salt):
def match(truth, events_simu, events_salt):
"""
Match salted events to simulation events.
:param truth: truth from wfsim
Expand All @@ -190,7 +187,7 @@ def match(truth, match, events_simu, events_salt):
"""
ind_salt_matched_to_simu, \
ind_simu_matched_to_truth, \
_, _ = pair_salt_to_simu(truth, match, events_simu, events_salt)
_ = pair_salt_to_simu(truth, events_simu, events_salt)

events_simu_matched_to_truth = events_simu[ind_simu_matched_to_truth[ind_simu_matched_to_truth>=0]]
events_salt_matched_to_simu = events_salt[ind_salt_matched_to_simu[ind_salt_matched_to_simu>=0]]
Expand Down
Loading