Skip to content
Snippets Groups Projects
Commit 989de962 authored by Jack Christopher Hutchinson Rolph's avatar Jack Christopher Hutchinson Rolph
Browse files

Added 'truncate' option for spectra with pre-pedestal events.

Set truncate=True to remove events with PH = pedestal-statistical_gain/2.
parent b43560a5
Branches
Tags
No related merge requests found
......@@ -279,14 +279,15 @@ class PeakOTron:
"r_fast":None,
"tgate":None,
"pedestal":None,
"truncate":False,
"n_bootstrap": 1000,
"n_bootstrap_kde":100,
"bw":None,
"peak_dist_factor":0.8,
"peak_width_factor":0.5,
"peak_ppf":0.95,
"prominence": 0.0,
"min_n_peak_evts": 100,
"peak_prominence": 0.0,
"peak_min_n_evts": 100,
"kernel_kde":"gaussian",
"bandwidth_kde":"ISJ",
"ppf_mainfit":1 - 1e-6,
......@@ -1294,14 +1295,15 @@ class PeakOTron:
peak_dist_factor,
peak_width_factor,
peak_ppf,
peak_prominence,
peak_min_n_evts,
truncate,
pedestal,
prominence,
bin_method,
n_bootstrap,
n_bootstrap_kde,
bandwidth_kde,
kernel_kde,
min_n_peak_evts):
kernel_kde):
self.scaler = RobustScaler()
......@@ -1412,31 +1414,45 @@ class PeakOTron:
est_gain_lin = abs(f_lin_kde_s(est_gain) - f_lin_kde_s(0))
peaks, properties = find_peaks(y_kde_s,
distance=peak_dist_factor*est_gain_lin,
prominence=prominence
)
limit_s = pedestal_s - 0.5*est_gain
limit = limit_s*self.scaler.scale_[0] + self.scaler.center_[0]
if(truncate):
cond_limit = (x>limit)
cond_limit_s = (x_s>limit_s)
cond_limit_kde_s = (x_kde_s>limit_s)
x = x[cond_limit]
y = y[cond_limit]
y_err = y_err[cond_limit]
x_s = x_s[cond_limit_s]
y_s = y_s[cond_limit_s]
y_err_s = y_err_s[cond_limit_s]
x_kde_s = x_kde_s[cond_limit_kde_s]
y_kde_s = y_kde_s[cond_limit_kde_s]
y_kde_err_s = y_kde_err_s[cond_limit_kde_s]
if(len(peaks)<3):
if(self._verbose):
print("Not enough peaks found with distance criterion to fit. Removing distance criterion and finding all peaks...")
print("Truncated distributions to only fit PH > pedestal - statistical gain/2 ...")
peaks, properties = find_peaks(y_kde_s,
prominence=prominence
distance=peak_dist_factor*est_gain_lin,
prominence=peak_prominence
)
limit_s = pedestal_s - 0.5*est_gain
limit = pedestal - 0.5*est_gain*self.scaler.scale_[0]
cond_limit_s = (x_kde_s[peaks]>limit_s)
if(sum(cond_limit_s)<3):
if(self._verbose):
print("No peaks observed above pedestal - gain/2. Continuing without thresholding...")
else:
peaks = peaks[cond_limit_s]
if(len(peaks)<3):
print("Not enough peaks found with current distance criterion to fit. Setting fit fail status and continuing..")
self._failed=True
return
......@@ -1471,16 +1487,16 @@ class PeakOTron:
N_evt_peak = len(self.SelectRange(data_s, x_peak-x_width/2, x_peak+x_width/2))
if(x_i>peak_threshold and N_evt_peak<min_n_peak_evts):
if(x_i>peak_threshold and N_evt_peak<peak_min_n_evts):
if(self._verbose):
print("Peak {:d} has {:d} events. Less than event threshold {:d}. Ignoring...".format(x_i,
N_evt_peak,
min_n_peak_evts))
peak_min_n_evts))
else:
if(self._verbose):
print("Peak {:d} has {:d} events. Adding...".format(x_i,
N_evt_peak,
min_n_peak_evts))
peak_min_n_evts))
self._peak_data["x_peak_s"].append(x_peak)
self._peak_data["y_peak_s"].append(y_peak)
......@@ -1498,7 +1514,7 @@ class PeakOTron:
self._peak_data["x_width_s"] = np.asarray(self._peak_data["x_width_s"])
if(n_valid_peaks<3):
print("Minimum 3 peaks covering a threshold {0} events required. Too few events in peaks to proceed. Setting fit fail status and continuing...".format(min_n_peak_evts))
print("Minimum 3 peaks covering a threshold {0} events required. Too few events in peaks to proceed. Setting fit fail status and continuing...".format(peak_min_n_evts))
self._failed = True
return
......@@ -2001,8 +2017,9 @@ class PeakOTron:
peak_dist_factor,
peak_width_factor,
peak_ppf,
prominence,
min_n_peak_evts,
peak_prominence,
peak_min_n_evts,
truncate,
kernel_kde,
bandwidth_kde,
ppf_mainfit,
......@@ -2021,19 +2038,21 @@ class PeakOTron:
if(self._verbose):
print("Getting histogram and peak values...")
self.GetHistAndPeaks(data,
self.GetHistAndPeaks(
data,
bw,
peak_dist_factor,
peak_width_factor,
peak_ppf,
peak_prominence,
peak_min_n_evts,
truncate,
pedestal,
prominence,
bin_method,
n_bootstrap,
n_bootstrap_kde,
bandwidth_kde,
kernel_kde,
min_n_peak_evts)
kernel_kde)
if(not self._failed):
if(self._verbose):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment