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

Feature/sensitivity curve link rf background and detection efficiency to snr #73

Open
wants to merge 28 commits into
base: feature/sensitivity_curve
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3e331d3
add function det_efficiency_tau(self, threshold)
Dec 11, 2024
640d723
adjust the indent
Dec 11, 2024
d7123df
add function background_rate(self, threshold)
Dec 11, 2024
1b30c87
import modules ncx2, chi2, and quad
Dec 11, 2024
b89717e
How do we know if the result of the rf_background_rate_cavity(self) i…
Dec 13, 2024
25d42e9
run methods self.assign_background_rate_from_threshold() and self.ass…
Dec 18, 2024
36645b8
after debugging the processor is running with the configure file http…
Dec 19, 2024
0d6f1ee
after debugging, the script runs for the configuration file https://g…
Dec 19, 2024
57594d9
Make the configuration use_threshold = True used in the code
Dec 23, 2024
8673801
Merge fix
taliaweiss Dec 25, 2024
fadd74f
Implement three of my comments on PR #73
taliaweiss Dec 25, 2024
db044b2
Debugged, cleaned code, used cyclotron radius for unusable distance f…
taliaweiss Dec 25, 2024
59c1b71
move assign_detection_efficiency_from_threshold() above the two backg…
Dec 26, 2024
0475a34
add comments to the det_efficiency_tau() and rf_background_rate_cavit…
Dec 26, 2024
04c147f
add reference to the antenna paper
Dec 26, 2024
982c5c7
adjust the variable names in det_efficiency_track_duration track_dura…
Dec 26, 2024
bd379e2
Have consistent order of printing SNR values and efficiency factors
taliaweiss Dec 28, 2024
85a6da3
Print detection efficiency integration error
taliaweiss Dec 28, 2024
25a6d76
Change parameter name threshold->detection_threshold. Remove the try-…
Dec 29, 2024
61f3b76
modify the script so only runs on the configuration Config_LFA_Experi…
Dec 29, 2024
ba4a895
Preparing to test Yu-Hao's new changes
taliaweiss Dec 30, 2024
8eb26a9
Merge branch 'feature/sensitivity_curve_link_rf_background_and_detect…
taliaweiss Dec 30, 2024
cf8b2e9
Fixed problem of detection efficiency not being re-calculated for eac…
taliaweiss Dec 31, 2024
3aff343
Added 2 more x-axis exposure-type options, added option to mark an op…
taliaweiss Jan 8, 2025
9b0b012
Legend position (bbox to anchor) can now be configured by user
taliaweiss Jan 8, 2025
af2e075
Added ncav*eff*time plotting option; changed some straggler 1.64 fact…
taliaweiss Jan 27, 2025
ee94c38
Changed back to 1.64 (I got confused about the direction of the change)
taliaweiss Jan 27, 2025
801a151
Added function to calculate trap_length from cavity L/D, assumes 80% …
benanator77 Feb 4, 2025
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
4 changes: 4 additions & 0 deletions mermithid/misc/CRESFunctions_numericalunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def frequency(kin_energy, magnetic_field):
# cyclotron frequency
return e/(2*np.pi*me)/gamma(kin_energy)*magnetic_field

def cyclotron_radius(freq, kin_energy):
v = beta(kin_energy)*c0
return v/freq/(2*np.pi)

def wavelength(kin_energy, magnetic_field):
return c0/frequency(kin_energy, magnetic_field)

Expand Down
381 changes: 223 additions & 158 deletions mermithid/processors/Sensitivity/CavitySensitivityCurveProcessor.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import matplotlib.pyplot as plt
import numpy as np
import os
import concurrent.futures



Expand Down Expand Up @@ -182,12 +183,20 @@ def InternalRun(self):
except KeyError as e:
logger.error(f"Parameter {param} not found in {category}")
raise e

self.sens_main.__dict__[category].__dict__[param] = parameter_value
read_back = self.sens_main.__dict__[category].__dict__[param]
#setattr(self.sens_main, self.scan_parameter_name, parameter_value)
#read_back = getattr(self.sens_main, self.scan_parameter_name)
logger.info(f"Setting {self.scan_parameter_name} to {parameter_value/self.scan_parameter_unit} and reading back: {read_back/ self.scan_parameter_unit}")

# pitch angle set equal
if(param == "min_pitch_used_in_analysis"):
self.sens_main.__dict__["FrequencyExtraction"].__dict__["minimum_angle_in_bandwidth"] = parameter_value

# If the scanned param isn't trap length, calc trap length for cavity L/D
if (param != "trap_length"):
self.sens_main.TrapLength()

logger.info("Calculating cavity experiment radius, volume, effective volume, power")
self.sens_main.CavityRadius()
Expand Down
176 changes: 126 additions & 50 deletions mermithid/sensitivity/SensitivityCavityFormulas.py
taliaweiss marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions mermithid/sensitivity/SensitivityFormulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, config_path):
# SENSITIVITY
def SignalRate(self):
"""signal events in the energy interval before the endpoint, scale with DeltaE**3"""
self.EffectiveVolume()
signal_rate = self.Experiment.number_density*self.effective_volume*self.last_1ev_fraction/self.tau_tritium
if not self.Experiment.atomic:
if hasattr(self.Experiment, 'gas_fractions'):
Expand All @@ -105,7 +106,7 @@ def BackgroundRate(self):
Currently, RF noise and cosmic ray backgrounds are included.
Assumes that background rate is constant over considered energy / frequency range."""
self.cosmic_ray_background = self.Experiment.cosmic_ray_bkgd_per_tritium_particle*self.Experiment.number_density*self.effective_volume
self.background_rate = self.Experiment.RF_background_rate_per_eV + self.cosmic_ray_background
self.background_rate = self.RF_background_rate_per_eV + self.cosmic_ray_background
return self.background_rate

def SignalEvents(self):
Expand All @@ -123,15 +124,17 @@ def DeltaEWidth(self):
+ 8*np.log(2)*(np.sum(sigmas**2)))

def StatSens(self):
"""Pure statistic sensitivity assuming Poisson count experiment in a single bin"""
"""Pure statistic sensitivity assuming Poisson count experiment in a single bin
As defined, it needs to be squared before being added to the systematic component"""
sig_rate = self.SignalRate()
DeltaE = self.DeltaEWidth()
sens = 2/(3*sig_rate*self.Experiment.LiveTime)*np.sqrt(sig_rate*self.Experiment.LiveTime*DeltaE
+self.BackgroundRate()*self.Experiment.LiveTime/DeltaE)
return sens

def SystSens(self):
"""Pure systematic componenet to sensitivity"""
"""Pure systematic component to sensitivity
As defined, it needs to be squared before being added to the statistical component"""
labels, sigmas, deltas = self.get_systematics()
sens = 4*np.sqrt(np.sum((sigmas*deltas)**2))
return sens
Expand Down
58 changes: 30 additions & 28 deletions test_analysis/Cavity_Sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"exposure_range": [1e-11, 1e4],
"main_curve_upper_label": r"Phase IV scenario", #"Molecular, conservative",
#"main_curve_lower_label": r"$\sigma^\bar{B}_\mathrm{reco} = 0.07\,\mathrm{eV}$",
"goals": {"Phase IV (0.04 eV)": (0.04**2/1.64)},
"goals": {"Phase IV (0.04 eV)": 0.04},
"comparison_curve": False,
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_PhaseIII_325MHz_Experiment.cfg",
"/termite/sensitivity_config_files/Config_atomic_325MHz_Experiment_conservative.cfg",
Expand Down Expand Up @@ -150,34 +150,36 @@
sens_config_dict = {
# required
"config_file_path": "/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg", #"/termite/sensitivity_config_files/Config_LFA_Experiment_1GHz.cfg", #Config_atomic_325MHz_Experiment_conservative.cfg",
"plot_path": "./LFA_and_PhaseIV_sensitivity_vs_density_LFA-sensitivity-branch_Dec-20-2024.pdf",
"plot_path": "./LFA_and_PhaseIV_sensitivity_vs_density_threshold_KPPs_Jan-10-2025.pdf",
# optional
"figsize": (7.0,6),
"fontsize": 15,
"track_length_axis": False,
"legend_location": "upper left",
"legend_bbox_to_anchor": (0.17,-0.01,1.1,0.87),
"molecular_axis": False,
"atomic_axis": True,
"density_axis": True,
"track_length_axis": True,
"cavity": True,
"y_limits": [2e-2, 4],
"density_range": [1e13,1e19],
"main_curve_upper_label": r"Phase III scenario: 560 MHz", #Phase III scenario: 1 GHz",
"goals": {"Phase III (0.4 eV)": 0.4, "Phase IV (0.04 eV)": 0.04}, #"Pilot T goal (0.1 eV)": 0.1,
"comparison_curve": True,
"density_range": [5e13,3e18],
"main_curve_upper_label": r"LFA (Phase III): 560 MHz", #Phase III scenario: 1 GHz",
"goals": {"LFA (0.4 eV)": 0.4, "Phase IV (0.04 eV)": 0.04}, #"Pilot T goal (0.1 eV)": 0.1,
"comparison_curve": False,
"main_curve_color": "blue",
"comparison_curve_colors": ["red"], # "black"],
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_atomic_150MHz_minpitch_87deg.cfg"],
"comparison_curve_label": [r"Phase IV scenario: 150 MHz"],
"comparison_curve_colors": ["red", "black"],
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_atomic_150MHz_minpitch_87deg.cfg", "/termite/sensitivity_config_files/Config_PIVmodule1_150MHz_minpitch_87deg.cfg"],
"comparison_curve_label": [r"Phase IV scenario: 150 MHz", r"One Phase IV cavity"],
"comparison_label_y_position": [2, 0.105, 0.046], #[2, 0.105, 0.046],
"comparison_label_x_position": [4.5e15, 7e14, 7e14], #[4.5e15, 2.2e16, 1e15],
#"sigmae_theta_r": 0.159,
"lower_label_y_position": 0.17,
"upper_label_y_position": 0.7,
"label_x_position": 4e14, #4e14, #0.02, #1e14,
"goals_x_position": 3e13, #0.0002
"plot_key_parameters": True
"goals_x_position": 5.5e13, #0.0002
"plot_key_parameters": True,
"goals_y_rel_position": 0.755
}
sens_curve = CavitySensitivityCurveProcessor("sensitivity_curve_processor")
sens_curve.Configure(sens_config_dict)
Expand All @@ -186,42 +188,41 @@

sens_config_dict = {
# required
"config_file_path": "/termite/sensitivity_config_files/Config_LFA_Experiment_1GHz.cfg", #"/termite/sensitivity_config_files/Config_LFA_Experiment.cfg",
"plot_path": "./lfa_and_PhaseIV_sensitivity_vs_livetime_curve_Oct-22-2024.pdf",
"config_file_path": "/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg", #"/termite/sensitivity_config_files/Config_LFA_Experiment.cfg",
"plot_path": "./lfa_and_PhaseIV_sensitivity_vs_ncav-eff-time_curve_Jan-8-2025.pdf",
"exposure_axis": True,
# optional
"figsize": (10,6),
"figsize": (8.5, 6), #(10,6),
"fontsize": 15,
"legend_location": "upper right",
"legend_bbox_to_anchor": (-0.,0,0.86,0.955),
"track_length_axis": False,
"molecular_axis": False,
"atomic_axis": False,
"exposure_axis": False,
"density_axis": False,
"livetime_axis": True,
"ncav_eff_time_axis": True,
"cavity": True,
"add_PhaseII": True,
"PhaseII_config_path": "/termite/sensitivity_config_files/Config_PhaseII_Experiment.cfg",
"add_1year_1cav_point_to_last_ref": False,
"add_1year_1cav_point_to_last_ref": True,
"y_limits": [1.5e-2, 1],
#"density_range": [1e12,1e19],
"year_range": [0.1,10**3],
#"main_curve_upper_label": r"LFA (atomic T)$\,-\,$1 GHz",
"main_curve_upper_label": r"Phase III scenario: 1 GHz, V = 0.25 m$^3$",
#"main_curve_lower_label": r"$\sigma^\bar{B}_\mathrm{reco} = 0.16\,\mathrm{eV}$",
"goals": {"Phase IV (0.04 eV)": (0.04**2/1.64)},
"main_curve_upper_label": r"LFA (Phase III): 560 MHz, V = 1.7 m$^3$",
"goals": {"LFA (0.4 eV)": 0.4, "Phase IV (0.04 eV)": 0.04},
"comparison_curve": True,
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg",
"/termite/sensitivity_config_files/Config_atomic_150MHz_minpitch_87deg.cfg"],
"comparison_curve_label": [r"Phase III scenario: 560 MHz, V = 1.2 m$^3$", r"Phase IV scenario: 150 MHz, V = 74 m$^3 \times 10$"],
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_atomic_150MHz_minpitch_87deg.cfg"], #"/termite/sensitivity_config_files/Config_PIVmodule1_150MHz_minpitch_87deg.cfg",
"comparison_curve_label": [r"Phase IV scenario: 150 MHz, V = 94 m$^3 \times 10$"], #"One Phase IV cavity",
"main_curve_color": "blue",
"comparison_curve_colors": ["red", "black"],
"comparison_curve_colors": ["red"], #"black",
"optimize_main_density": False,
"optimize_comparison_density": False,
"lower_label_y_position": 0.17,
"upper_label_y_position": 0.7,
"label_x_position": 0.115, #1.5e15, #0.02, #1e14,
"goals_x_position": 0.115, #2e12 #0.0002
"goals_y_rel_position": 0.65,
"label_x_position": 0.115,
"goals_x_position": 1.13e-3, #0.11, <-- Number for ncavities*livetime
"goals_y_rel_position": 0.84, #0.81, <-- Number for ncavities*livetime
}
#sens_curve = CavitySensitivityCurveProcessor("sensitivity_curve_processor")
#sens_curve.Configure(sens_config_dict)
Expand Down Expand Up @@ -253,7 +254,7 @@
#"main_curve_upper_label": r"LFA (atomic T)$\,-\,$1 GHz",
"main_curve_upper_label": r"Phase III scenario: 1 GHz",
#"main_curve_lower_label": r"$\sigma^\bar{B}_\mathrm{reco} = 0.16\,\mathrm{eV}$",
"goals": {"Phase IV (0.04 eV)": (0.04**2/1.64)},
"goals": {"Phase IV (0.04 eV)": (0.04)},
"comparison_curve": True,
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg",
"/termite/sensitivity_config_files/Config_atomic_150MHz_minpitch_87deg.cfg"],
Expand Down Expand Up @@ -403,6 +404,7 @@
"goals_x_position": 1.2e12, #0.0002
"plot_key_parameters": True
}

#sens_curve = CavitySensitivityCurveProcessor("sensitivity_curve_processor")
#sens_curve.Configure(sens_config_dict)
#sens_curve.Run()
Expand Down
6 changes: 3 additions & 3 deletions test_analysis/LFA_Sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

sens_config_dict = {
# required
"config_file_path": "/termite/sensitivity_config_files/Config_LFA_Experiment_1GHz.cfg", #"/termite/sensitivity_config_files/Config_LFA_Experiment.cfg",
"config_file_path": "/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg", #"/termite/sensitivity_config_files/Config_LFA_Experiment.cfg",
"plot_path": "./lfa_with_BNL_constraints_sensitivity_vs_exposure_curve_PhaseIV.pdf",
"exposure_axis": True,
# optional
Expand All @@ -81,8 +81,8 @@
"main_curve_upper_label": r"Phase III scenario: 1 GHz, L/D=9",
#"main_curve_lower_label": r"$\sigma^\bar{B}_\mathrm{reco} = 0.16\,\mathrm{eV}$",
"goals": {"Phase III (0.4 eV)": (0.4**2/1.64), "Phase IV (0.04 eV)": (0.04**2/1.64)},
"comparison_curve": True,
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_LFA_Experiment_500MHz.cfg",
"comparison_curve": False,
"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg",
"/termite/sensitivity_config_files/Config_LFA_Experiment_max_BNL_diam.cfg"],
# "/termite/sensitivity_config_files/Config_atomic_find_factor_22_Experiment_conservative.cfg"],
#"comparison_config_file_path": ["/termite/sensitivity_config_files/Config_PhaseIII_325MHz_Experiment_conservative.cfg",
Expand Down