diff --git a/saltax/instructions/generator.py b/saltax/instructions/generator.py index b2439d5..b32aa77 100644 --- a/saltax/instructions/generator.py +++ b/saltax/instructions/generator.py @@ -381,64 +381,6 @@ def generator_ambe( return instr -def generator_ybe( - runid, - n_tot=None, - rate=1e9 / SALT_TIME_INTERVAL, - time_mode="uniform", - ybe_instructions_file=YBE_INSTRUCTIONS_FILE, - **kwargs -): - """ - Generate instructions for a run with YBe source. YBe instruction was first generated by full-chain - simulation, and then passing the post-epix instruction to feed this function. Each event with a certain - event_id in the fed instructions will be shifted in time based on the time_mode you specified. - :param runid: run number in integer - :param n_tot: total number of events to generate, default: None i.e. generate events until end_time - :param rate: rate of events in Hz, default: 1e9/SALT_TIME_INTERVAL - :param time_mode: 'uniform' or 'realistic', default: 'uniform' - :param ybe_instructions_file: file containing ybe instructions, default: YBE_INSTRUCTIONS_FILE - :return: instructions in numpy array - """ - # determine time offsets to shift ybe instructions - start_time, end_time = get_run_start_end(runid) - times_offset = generate_times(start_time, end_time, size=n_tot, - rate=rate, time_mode=time_mode) - n_tot = len(times_offset) - - # bootstrap instructions - ybe_instructions = pd.read_csv(ybe_instructions_file) - ybe_event_numbers = np.random.choice(np.unique(ybe_instructions.event_number), - n_tot, - replace=True) - - # assign instructions - instr = np.zeros(0, dtype=wfsim.instruction_dtype) - for i in tqdm(range(n_tot)): - # bootstrapped ybe instruction - selected_ybe = ybe_instructions[ybe_instructions['event_number'] - == ybe_event_numbers[i]] - # instruction for i-th event - instr_i = np.zeros(len(selected_ybe), dtype=wfsim.instruction_dtype) - instr_i["time"] = times_offset[i] + selected_ybe["time"] - instr_i["event_number"] = i + 1 - instr_i["type"] = selected_ybe["type"] - instr_i["x"] = selected_ybe["x"] - instr_i["y"] = selected_ybe["y"] - instr_i["z"] = selected_ybe["z"] - instr_i["recoil"] = selected_ybe["recoil"] - instr_i["e_dep"] = selected_ybe["e_dep"] - instr_i["amp"] = selected_ybe["amp"] - instr_i["n_excitons"] = selected_ybe["n_excitons"] - - # concatenate instr - instr = np.concatenate((instr, instr_i)) - - # Filter out 0 amplitudes - instr = instr[instr["amp"] > 0] - - return instr - def generator_ybe( runid, diff --git a/saltax/match/utils.py b/saltax/match/utils.py index 71a40eb..e6c4cf5 100644 --- a/saltax/match/utils.py +++ b/saltax/match/utils.py @@ -670,13 +670,7 @@ def get_cut_eff( bins = np.linspace(-145, -13, n_bins) else: raise NotImplementedError - - if indv_cut_type == "n_minus_1": - cut_func = apply_n_minus_1_cuts - elif indv_cut_type == "single": - cut_func = apply_single_cut - else: - raise NotImplementedError + result_dict = {} for cut in all_cut_list: @@ -698,13 +692,24 @@ def get_cut_eff( result_dict["all_cuts"][i] = len(selected_events_all_cut) / len(selected_events) result_dict["all_cuts_upper"][i] = interval.high result_dict["all_cuts_lower"][i] = interval.low + for cut_oi in all_cut_list: - selected_events_cut_oi = selected_events[apply_single_cut(selected_events, cut_oi)] - # Efficiency curves with Clopper-Pearson uncertainty estimation - interval = binomtest(len(selected_events_cut_oi), len(selected_events)).proportion_ci() - result_dict[cut_oi][i] = len(selected_events_cut_oi) / len(selected_events) - result_dict[cut_oi + "_upper"][i] = interval.high - result_dict[cut_oi + "_lower"][i] = interval.low + if indv_cut_type == 'n_minus_1': + selected_events_cut_oi = selected_events[apply_n_minus_1_cuts(selected_events, cut_oi, all_cut_list)] + # Efficiency curves with Clopper-Pearson uncertainty estimation + interval = binomtest(len(selected_events_all_cut), len(selected_events_cut_oi)).proportion_ci() + result_dict[cut_oi][i] = len(selected_events_all_cut)/len(selected_events_cut_oi) + result_dict[cut_oi+'_upper'][i] = interval.high + result_dict[cut_oi+'_lower'][i] = interval.low + elif indv_cut_type == 'single': + selected_events_cut_oi = selected_events[apply_single_cut(selected_events, cut_oi)] + # Efficiency curves with Clopper-Pearson uncertainty estimation + interval = binomtest(len(selected_events_cut_oi), len(selected_events)).proportion_ci() + result_dict[cut_oi][i] = len(selected_events_cut_oi) / len(selected_events) + result_dict[cut_oi + "_upper"][i] = interval.high + result_dict[cut_oi + "_lower"][i] = interval.low + else: + raise NotImplementedError if plot: colors = plt.cm.rainbow(