From 30cc2a90880f670ede4f5ccc647469c82ba9596e Mon Sep 17 00:00:00 2001 From: Husheng Guan Date: Fri, 3 May 2024 10:12:25 -0500 Subject: [PATCH 1/9] Add YBe Generator --- .singularity_inner | 20 +++++++++ jobs/config.ini | 31 -------------- jobs/config_ybe.ini | 31 ++++++++++++++ saltax/instructions/.singularity_inner | 20 +++++++++ saltax/instructions/generator.py | 59 ++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 31 deletions(-) create mode 100755 .singularity_inner delete mode 100644 jobs/config.ini create mode 100644 jobs/config_ybe.ini create mode 100755 saltax/instructions/.singularity_inner diff --git a/.singularity_inner b/.singularity_inner new file mode 100755 index 0000000..5663488 --- /dev/null +++ b/.singularity_inner @@ -0,0 +1,20 @@ +#!/bin/bash +JUP_HOST=$(hostname -i) +## print tunneling instructions +echo -e " + Copy/Paste this in your local terminal to ssh tunnel with remote + ----------------------------------------------------------------- + ssh -N -f -L localhost:17871:$JUP_HOST:17871 ghusheng@midway2.rcc.uchicago.edu + ----------------------------------------------------------------- + + Then open a browser on your local machine to the following address + ------------------------------------------------------------------ + localhost:17871 + ------------------------------------------------------------------ + and use the token that appears below to login. + + OR replace "" in the address below with "localhost" and copy + to your local browser. + " 2>&1 + +jupyter lab --no-browser --port=17871 --ip=$JUP_HOST --notebook-dir /home/ghusheng 2>&1 diff --git a/jobs/config.ini b/jobs/config.ini deleted file mode 100644 index d65e4f2..0000000 --- a/jobs/config.ini +++ /dev/null @@ -1,31 +0,0 @@ -[utilix] -max_num_submit = 200 -t_sleep = 1 - -[job] -container = xenonnt-montecarlo-development.simg -runids = 48692,48693,48699,49028,49077,49079,49080,49432,49433 -output_folder = /scratch/midway2/yuanlq/salt/rn220 -package = fuse -saltax_mode = salt -simu_config_version = sr1_dev -generator_name = flat -recoil = 8 -simu_mode = all -rate = 100 -en_range = 0.2,15 -process_data = False -process_simu = True -skip_records = False -delete_records = False -storage_to_patch = /project/lgrandi/yuanlq/salt/raw_records,/scratch/midway2/yuanlq/salt/raw_records,/scratch/midway3/yuanlq/salt/raw_records - -[slurm] -username = yuanlq -account = pi-lgrandi -job_title = sprinkling -partition = lgrandi -qos = lgrandi -mem_per_cpu = 45000 -cpus_per_task = 1 -log_dir = /home/yuanlq/.tmp_job_submission/saltax/rn220 diff --git a/jobs/config_ybe.ini b/jobs/config_ybe.ini new file mode 100644 index 0000000..671f4c3 --- /dev/null +++ b/jobs/config_ybe.ini @@ -0,0 +1,31 @@ +[utilix] +max_num_submit = 200 +t_sleep = 1 + +[job] +container = xenonnt-montecarlo-development.simg +runids = 47880, 47881, 47882, 47883, 47884, 47885 +output_folder = /scratch/midway2/ghusheng/salt/ybe_fuse +package = fuse +saltax_mode = salt +simu_config_version = sr1_dev +generator_name = ybe +recoil = 0 +simu_mode = all +rate = 50 +en_range = 0.2,15 +process_data = False +process_simu = True +skip_records = False +delete_records = False +storage_to_patch = /scratch/midway2/ghusheng + +[slurm] +username = ghusheng +account = pi-lgrandi +job_title = sprinkling_ybe_fuse +partition = xenon1t +qos = xenon1t +mem_per_cpu = 45000 +cpus_per_task = 1 +log_dir = /home/ghusheng/tmp_job_submission/saltax/ybe diff --git a/saltax/instructions/.singularity_inner b/saltax/instructions/.singularity_inner new file mode 100755 index 0000000..a4e4561 --- /dev/null +++ b/saltax/instructions/.singularity_inner @@ -0,0 +1,20 @@ +#!/bin/bash +JUP_HOST=$(hostname -i) +## print tunneling instructions +echo -e " + Copy/Paste this in your local terminal to ssh tunnel with remote + ----------------------------------------------------------------- + ssh -N -f -L localhost:15854:$JUP_HOST:15854 ghusheng@midway2.rcc.uchicago.edu + ----------------------------------------------------------------- + + Then open a browser on your local machine to the following address + ------------------------------------------------------------------ + localhost:15854 + ------------------------------------------------------------------ + and use the token that appears below to login. + + OR replace "" in the address below with "localhost" and copy + to your local browser. + " 2>&1 + +jupyter lab --no-browser --port=15854 --ip=$JUP_HOST --notebook-dir /home/ghusheng 2>&1 diff --git a/saltax/instructions/generator.py b/saltax/instructions/generator.py index 1ae9331..1be3919 100644 --- a/saltax/instructions/generator.py +++ b/saltax/instructions/generator.py @@ -25,6 +25,7 @@ ) SE_INSTRUCTIONS_DIR = "/project/lgrandi/yuanlq/salt/se_instructions/" AMBE_INSTRUCTIONS_FILE = "/project/lgrandi/yuanlq/salt/ambe_instructions/minghao_aptinput.csv" +YBE_INSTRUCTIONS_FILE = "/project2/lgrandi/ghusheng/ybe_instrutions/ybe_wfsim_instructions_6806_events_time_modified.csv" # BASE_DIR = "/project2/lgrandi/yuanlq/shared/saltax_instr/" BASE_DIR = os.path.abspath(__file__)[:-12] + "../../generated/" @@ -380,6 +381,64 @@ 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_flat( runid, From b09744bbc45c94b53927f8cb670a9e03e9ac26b9 Mon Sep 17 00:00:00 2001 From: Husheng Guan Date: Mon, 6 May 2024 12:25:10 -0500 Subject: [PATCH 2/9] Fix Cut Acceptance Plotting --- saltax/instructions/generator.py | 58 -------------------------------- saltax/match/utils.py | 31 ++++++++++------- 2 files changed, 18 insertions(+), 71 deletions(-) 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( From 593d4abb9fb4282d0ecdc806a47d789afecb922a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 17:28:11 +0000 Subject: [PATCH 3/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- saltax/match/utils.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/saltax/match/utils.py b/saltax/match/utils.py index e6c4cf5..9783a51 100644 --- a/saltax/match/utils.py +++ b/saltax/match/utils.py @@ -670,7 +670,6 @@ def get_cut_eff( bins = np.linspace(-145, -13, n_bins) else: raise NotImplementedError - result_dict = {} for cut in all_cut_list: @@ -692,19 +691,25 @@ 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: - 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)] + 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': + 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() + 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 From d5e5269958f49a3cf29a1147ef025bee78eb93c4 Mon Sep 17 00:00:00 2001 From: Husheng Guan Date: Mon, 6 May 2024 15:30:23 -0500 Subject: [PATCH 4/9] clean mess --- .singularity_inner => jobs/.singularity_inner | 6 ++-- jobs/config.ini | 31 +++++++++++++++++++ jobs/config_ybe.ini | 31 ------------------- saltax/instructions/.singularity_inner | 20 ------------ 4 files changed, 34 insertions(+), 54 deletions(-) rename .singularity_inner => jobs/.singularity_inner (82%) create mode 100644 jobs/config.ini delete mode 100644 jobs/config_ybe.ini delete mode 100755 saltax/instructions/.singularity_inner diff --git a/.singularity_inner b/jobs/.singularity_inner similarity index 82% rename from .singularity_inner rename to jobs/.singularity_inner index 5663488..560df9d 100755 --- a/.singularity_inner +++ b/jobs/.singularity_inner @@ -4,12 +4,12 @@ JUP_HOST=$(hostname -i) echo -e " Copy/Paste this in your local terminal to ssh tunnel with remote ----------------------------------------------------------------- - ssh -N -f -L localhost:17871:$JUP_HOST:17871 ghusheng@midway2.rcc.uchicago.edu + ssh -N -f -L localhost:19646:$JUP_HOST:19646 ghusheng@midway2.rcc.uchicago.edu ----------------------------------------------------------------- Then open a browser on your local machine to the following address ------------------------------------------------------------------ - localhost:17871 + localhost:19646 ------------------------------------------------------------------ and use the token that appears below to login. @@ -17,4 +17,4 @@ echo -e " to your local browser. " 2>&1 -jupyter lab --no-browser --port=17871 --ip=$JUP_HOST --notebook-dir /home/ghusheng 2>&1 +jupyter lab --no-browser --port=19646 --ip=$JUP_HOST --notebook-dir /home/ghusheng 2>&1 diff --git a/jobs/config.ini b/jobs/config.ini new file mode 100644 index 0000000..d65e4f2 --- /dev/null +++ b/jobs/config.ini @@ -0,0 +1,31 @@ +[utilix] +max_num_submit = 200 +t_sleep = 1 + +[job] +container = xenonnt-montecarlo-development.simg +runids = 48692,48693,48699,49028,49077,49079,49080,49432,49433 +output_folder = /scratch/midway2/yuanlq/salt/rn220 +package = fuse +saltax_mode = salt +simu_config_version = sr1_dev +generator_name = flat +recoil = 8 +simu_mode = all +rate = 100 +en_range = 0.2,15 +process_data = False +process_simu = True +skip_records = False +delete_records = False +storage_to_patch = /project/lgrandi/yuanlq/salt/raw_records,/scratch/midway2/yuanlq/salt/raw_records,/scratch/midway3/yuanlq/salt/raw_records + +[slurm] +username = yuanlq +account = pi-lgrandi +job_title = sprinkling +partition = lgrandi +qos = lgrandi +mem_per_cpu = 45000 +cpus_per_task = 1 +log_dir = /home/yuanlq/.tmp_job_submission/saltax/rn220 diff --git a/jobs/config_ybe.ini b/jobs/config_ybe.ini deleted file mode 100644 index 671f4c3..0000000 --- a/jobs/config_ybe.ini +++ /dev/null @@ -1,31 +0,0 @@ -[utilix] -max_num_submit = 200 -t_sleep = 1 - -[job] -container = xenonnt-montecarlo-development.simg -runids = 47880, 47881, 47882, 47883, 47884, 47885 -output_folder = /scratch/midway2/ghusheng/salt/ybe_fuse -package = fuse -saltax_mode = salt -simu_config_version = sr1_dev -generator_name = ybe -recoil = 0 -simu_mode = all -rate = 50 -en_range = 0.2,15 -process_data = False -process_simu = True -skip_records = False -delete_records = False -storage_to_patch = /scratch/midway2/ghusheng - -[slurm] -username = ghusheng -account = pi-lgrandi -job_title = sprinkling_ybe_fuse -partition = xenon1t -qos = xenon1t -mem_per_cpu = 45000 -cpus_per_task = 1 -log_dir = /home/ghusheng/tmp_job_submission/saltax/ybe diff --git a/saltax/instructions/.singularity_inner b/saltax/instructions/.singularity_inner deleted file mode 100755 index a4e4561..0000000 --- a/saltax/instructions/.singularity_inner +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -JUP_HOST=$(hostname -i) -## print tunneling instructions -echo -e " - Copy/Paste this in your local terminal to ssh tunnel with remote - ----------------------------------------------------------------- - ssh -N -f -L localhost:15854:$JUP_HOST:15854 ghusheng@midway2.rcc.uchicago.edu - ----------------------------------------------------------------- - - Then open a browser on your local machine to the following address - ------------------------------------------------------------------ - localhost:15854 - ------------------------------------------------------------------ - and use the token that appears below to login. - - OR replace "" in the address below with "localhost" and copy - to your local browser. - " 2>&1 - -jupyter lab --no-browser --port=15854 --ip=$JUP_HOST --notebook-dir /home/ghusheng 2>&1 From 462b9edbbee2bccfa2795a05188f6dff21256da9 Mon Sep 17 00:00:00 2001 From: Husheng Guan Date: Mon, 6 May 2024 15:31:15 -0500 Subject: [PATCH 5/9] clean more mess --- jobs/.singularity_inner | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100755 jobs/.singularity_inner diff --git a/jobs/.singularity_inner b/jobs/.singularity_inner deleted file mode 100755 index 560df9d..0000000 --- a/jobs/.singularity_inner +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -JUP_HOST=$(hostname -i) -## print tunneling instructions -echo -e " - Copy/Paste this in your local terminal to ssh tunnel with remote - ----------------------------------------------------------------- - ssh -N -f -L localhost:19646:$JUP_HOST:19646 ghusheng@midway2.rcc.uchicago.edu - ----------------------------------------------------------------- - - Then open a browser on your local machine to the following address - ------------------------------------------------------------------ - localhost:19646 - ------------------------------------------------------------------ - and use the token that appears below to login. - - OR replace "" in the address below with "localhost" and copy - to your local browser. - " 2>&1 - -jupyter lab --no-browser --port=19646 --ip=$JUP_HOST --notebook-dir /home/ghusheng 2>&1 From c2e579bb8f6fd55ff3ea5774c507a685f292d6a0 Mon Sep 17 00:00:00 2001 From: Lanqing Yuan Date: Tue, 7 May 2024 04:35:12 -0500 Subject: [PATCH 6/9] cut ac --- saltax/match/utils.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/saltax/match/utils.py b/saltax/match/utils.py index 9783a51..79eeb3e 100644 --- a/saltax/match/utils.py +++ b/saltax/match/utils.py @@ -671,6 +671,13 @@ def get_cut_eff( 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: result_dict[cut] = np.zeros(n_bins - 1) @@ -693,28 +700,12 @@ def get_cut_eff( result_dict["all_cuts_lower"][i] = interval.low for cut_oi in all_cut_list: - 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 + selected_events_cut_oi = selected_events[cut_func(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 plot: colors = plt.cm.rainbow( From 16dd98daa51c3f3e0bc3b472610780b102e97089 Mon Sep 17 00:00:00 2001 From: Lanqing Yuan Date: Tue, 7 May 2024 04:49:35 -0500 Subject: [PATCH 7/9] debug --- saltax/match/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saltax/match/utils.py b/saltax/match/utils.py index 79eeb3e..1c0a77f 100644 --- a/saltax/match/utils.py +++ b/saltax/match/utils.py @@ -702,8 +702,8 @@ def get_cut_eff( for cut_oi in all_cut_list: selected_events_cut_oi = selected_events[cut_func(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) + 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 From 4c40353d4d33da676e83eef2ffc31c8330de8c25 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 09:49:45 +0000 Subject: [PATCH 8/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- saltax/match/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/saltax/match/utils.py b/saltax/match/utils.py index 1c0a77f..ce8fa83 100644 --- a/saltax/match/utils.py +++ b/saltax/match/utils.py @@ -702,7 +702,9 @@ def get_cut_eff( for cut_oi in all_cut_list: selected_events_cut_oi = selected_events[cut_func(selected_events, cut_oi)] # Efficiency curves with Clopper-Pearson uncertainty estimation - interval = binomtest(len(selected_events_all_cut), len(selected_events_cut_oi)).proportion_ci() + 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 From f7aa1250068f3f9e68441e4a5475d07d8bcb630a Mon Sep 17 00:00:00 2001 From: Lanqing Yuan Date: Tue, 7 May 2024 05:07:57 -0500 Subject: [PATCH 9/9] revert (#136) --- saltax/match/utils.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/saltax/match/utils.py b/saltax/match/utils.py index ce8fa83..9783a51 100644 --- a/saltax/match/utils.py +++ b/saltax/match/utils.py @@ -671,13 +671,6 @@ def get_cut_eff( 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: result_dict[cut] = np.zeros(n_bins - 1) @@ -700,14 +693,28 @@ def get_cut_eff( result_dict["all_cuts_lower"][i] = interval.low for cut_oi in all_cut_list: - selected_events_cut_oi = selected_events[cut_func(selected_events, cut_oi)] - # 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 + 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(