cait.fit
- cait.fit.array_fit(args, sev, t, blcomp, trunclv, bs, no_bl_when_sat)[source]
The wrapper function which does the array fit for one event.
- Parameters:
args (list) – The arguments which we provide to the wrapper: (event, t0). The event is the event to fit (1D numpy array), t0 (in milli seconds) is either a float or None. If it is a float, the t0 value is not searched but this one is used.
sev (1D float array) – The standard event
t (1D float array) – The time grid on which the baseline model is evaluated, in ms.
blcomp (int) – The number of baseline components, i.e. (order+1) of the polynomial which is used as baseline.
trunclv (float) – The truncation level. Values higher than this are excluded from the fit.
bs (float) – The bounds for the t0 search, in milli seconds.
no_bl_when_sat (bool)
- Returns:
The fitted parameters: (height, t0, … polynomial baseline components …)
- Return type:
list
- cait.fit.baseline_template_cubic(t, c0, c1, c2, c3)[source]
Template for the baseline fit, with constant linear, quadratic and cubic component.
- Parameters:
t (1D array) – The time grid.
c0 (float) – Constant component.
c1 (float) – Linear component.
c2 (float) – Quadratic component.
c3 (float) – Cubic component.
- Returns:
The cubic polynomial evaluated on the time grid.
- Return type:
1D array
- cait.fit.baseline_template_quad(t, c0, c1, c2)[source]
Template for the baseline fit, with constant linear and quadratic component.
- Parameters:
t (1D array) – The time grid.
c0 (float) – Constant component.
c1 (float) – Linear component.
c2 (float) – Quadratic component.
- Returns:
The parabola evaluated on the time grid.
- Return type:
1D array
- cait.fit.doshift(arr, num, fill_value=nan)[source]
Shift an array by a number of samples. Attention, this function is deprecated, use numpy.roll instead!
- Parameters:
arr (1D numpy array) – The array that we want to shift.
num (float) – The number of samples to shift. This is automatically rounded to the closest integer.
fill_value (float) – The value with which we want to fill the boarders of the shifted sample.
- Returns:
The shifted array.
- Return type:
1D numpy array
- cait.fit.fit_pulse_shape(event, x0=None, sample_length=0.04, down=1, t0_start=-3, t0_bounds=(-10, 5), opt_start=False, lower_bound_tau=0.01, upper_bound_tau=3000.0)[source]
Fits the pulse shape model to a given event and returns the fit parameters.
- Parameters:
event (1D array) – The event to fit.
x0 (None or 1D array) – The start values for the fit: (t0, An, At, tau_n, tau_in, tau_t).
sample_length (float) – The length of one sample in milliseconds.
down (int) – Should be power of 2, downsample rate during the fit.
t0_start (float) – The start value for t0.
t0_bounds (tuple) – Lower and upper bound for the t0 value.
opt_start (bool) – If activated the start values are searched with a differential evolution algorithm.
lower_bound_tau (float) – The lower bound for all tau values in the fit.
upper_bound_tau (float) – The upper bound for all tau values in the fit.
- Returns:
The fitted parameters.
- Return type:
1D array length 6
- cait.fit.fit_quadratic_baseline(event)[source]
Fits a quadratic baseline template the to given event
- Parameters:
event – 1D array, the event to fit the baseline template
- Returns:
list of 3 floats (offset, linear_drift, quadratic_drift)
- cait.fit.fit_trigger_efficiency(binned_energies, survived_fraction, a1_0, a0_0=1, a2_0=0.01, plot=False, title=None, xlim=None)[source]
Fit and plot the trigger efficiency.
- Parameters:
binned_energies (list of length nmbr_bins + 1) – The bin edges, in keV.
survived_fraction (list) – The number of survived events per bin, in keV.
a0_0 (float) – Start Value for estimated constant survival probability above threshold.
a1_0 (float) – Start Value for estimated threshold value, in keV.
a2_0 (float) – Start Value for estimator for the energy resolution, in keV.
plot (bool) – Plot the fitted function.
title (str) – The title for the plot.
xlim (tuple) – The x limits for the plot.
- Returns:
The fitted values a0, a1, a2.
- Return type:
list
import cait as ai import numpy as np # create mock data X = np.random.uniform(low=0, high=1, size=10000) randoms = np.random.uniform(low=0.3, high=0.5, size=10000) surviving = np.empty(10000, dtype=bool) surviving[X < 0.3] = False surviving[X > 0.5] = True inbet = np.logical_and(X > 0.3, X < 0.5) surviving[inbet] = X[inbet] > randoms[inbet] hist, bins = np.histogram(X[surviving], bins=100, range=(0, 1)) hist_all, _ = np.histogram(X, bins=100, range=(0, 1)) # do the fit a0, a1, a2 = ai.fit.fit_trigger_efficiency(binned_energies=bins, survived_fraction=hist/hist_all, a1_0=0.4, a0_0=0.9, a2_0=0.1, plot=True, title='Trigger Efficiency', xlim=(0.2, 0.9))
Estimated constant survival probability: 1.0029709355728647 Estimated energy threshold (keV): 0.4002443060404336 Estimated energy resolution (keV): 0.06203246371547854
- cait.fit.fitfunc(pars, X, event_, sev, bs)[source]
The fit function for the array fit.
- Parameters:
pars (list) – List of length one, the shift that is to be applied.
X (2 dim numpy array) – The data matrix: (nmbr_samples, nmbr_features). The first column corresponds to the standard event, the others to baseline components.
event (1D numpy array) – The event that we want to fit.
sev (1D numpy array) – The standard event.
bs (int) – The maximum shift value, i.e. the bounds of the minimization problem.
- Returns:
The average rms value of the fit.
- Return type:
float
- cait.fit.generate_standard_event(events, main_parameters, labels=None, correct_label=1, pulse_height_interval=None, left_right_cutoff=None, rise_time_interval=None, decay_time_interval=None, onset_interval=None, remove_offset=True, verb=False, scale_fit_height=True, scale_to_unit=True, sample_length=0.04, t0_start=None, opt_start=False)[source]
Calculates the standard event and fits the pulse shape model.
- Parameters:
events (2D array of shape (nmbr_events, record_length)) – The events to calculate the SEV from.
main_parameters (2D array of shape (nmbr_events, nmbr_mp=10)) – The main parameters of the events.
labels (None or 1D array of shape (nmbr_events)) – The labels of the events, if set only the correct labels are included in the SEV generation.
correct_label (int) – The correct label to calc SEV from, 1==events, 2==testpulses.
pulse_height_interval (None or 2-tuple or list) – The interval in which the PH may be to be included.
left_right_cutoff (None or float) – The maximal abs(R - L) baseline difference of the event.
rise_time_interval (None or 2-tuple or list) – The interval in ms in which the rise time may be to be included.
decay_time_interval (None or 2-tuple or list) – The interval in ms in which the decay time may be to be included.
onset_interval (None or 2-tuple or list) – The interval in which the onset time in ms may be to be included.
remove_offset (bool) – If True the offset of the events is removed before building mean for SEV; highly recommended!
verb (bool) – If True verbal feedback about the progress of the program is provided.
scale_fit_height (bool) – If True the fitpar of the sev are scaled to height 1 after the fit.
sample_length (float) – The length of one sample in milliseconds –> needed for the fit!
t0_start (float) – The start value for t0.
opt_start (bool) – If activated the starting values are searched with a differential evolution algorithm.
- Returns:
The calculated sev, the fit parameters.
- Return type:
tuple of two 1D arrays with shape (record_length, nmbr_fitpar)
- cait.fit.get_noise_parameters_binned(counts, bins)[source]
Return the least squares fit parameters to the purely Gaussian noise model. You need to calculate a histogram of the maxima of the empty baselines before already, e.g. with np.hist.
- Parameters:
counts (1D array) – The counts within the bins.
bins (1D array) – The bin edges. This array is one number longer than the counts array.
- Returns:
The fitted parameters (d, sigma).
- Return type:
2-tuple
- cait.fit.get_noise_parameters_unbinned(events, model='gauss', sigma_x0=2)[source]
Find the maximum likelihood estimators of all noise trigger model parameters in an unbinned maximum likelihood fit.
- Parameters:
events (1D array) – The array of the unbinned noise baseline maxima.
model (string) – The model that is used to fit the noise maxima. - ‘gauss’: Purely Gaussian noise model. - ‘pollution_exponential’: Gaussian noise model with an exponentially distributed pollution. - ‘fraction_exponential’: Gaussian-exponential mixture noise model. - ‘pollution_gauss’: Gaussian noise model with an Gaussian distributed pollution. - ‘fraction_gauss’: Gaussian mixture noise model.
sigma_x0 (float) – The start value for the baseline resolution.
- Returns:
The fitted parameters. These are different for each model and compatible with the functions gauss_noise, pollution_exponential_noise, fraction_exponential_noise and pollution_gauss_noise.
- Return type:
1D array
- cait.fit.logistic_curve(x, A, K, C, Q, B, nu)[source]
Returns the evaluated logistics curve at x.
- Parameters:
x (scalar or 1D numpy array) – The x value or grid.
A (float) – A parameter of the generalized logistics curve.
K (float) – A parameter of the generalized logistics curve.
C (float) – A parameter of the generalized logistics curve.
Q (float) – A parameter of the generalized logistics curve.
B (float) – A parameter of the generalized logistics curve.
nu (float) – A parameter of the generalized logistics curve.
- Returns:
The evaluated log curve at x.
- Return type:
scalar or 1D numpy array
- cait.fit.lstsqsol(X, y)[source]
Solution to a least squares regression.
- Parameters:
X (2-dim numpy array) – The data matrix: (nmbr_samples, nmbr_features).
y (1-dim numpy array) – The regression objective.
- Returns:
The solution, i.e. the fitted coefficients of the features.
- Return type:
1D array
- cait.fit.noise_trigger_template(x_max, d, sigma)[source]
A template for purely Gaussian noise.
- Parameters:
x_max (1D array) – The maxima of the empty noise baselines.
d (float) – The number of independent samples.
sigma (float) – The baseline resolution.
- Returns:
The template.
- Return type:
1D array
- cait.fit.pulse_template(t, *par)[source]
Wrapper method for pulse_template_2 and pulse_template_n. Depending on the number of parameters par, either of them is chosen: If len(par)==6, the meaning of the parameters is assumed to be [t0, An, At, tau_n, tau_in, tau_t] and pulse_template_2 is called with those parameters. If len(par)==2k+2 with k=3,4,…, the method pulse_template_k is called and the parameters are assumed to be of the following order: [t0, A1, A2, …, Ak, tau_in, tau_2, …, tau_k, tau_n].
Important: Since the functions are pre-compiled, it is important to match the function signatures. In particular, all the parameters have to be floats. If you pass an integer, make sure to append a dot, e.g. 1 -> 1. or 1.0
- Parameters:
t (np.ndarray) – Time array to evaluate the pulse shape model on.
par (float) – Parameters of the pulse shape model. Either in order t0, An, At, tau_n, tau_in, tau_t for the regular 2-component pulse shape model or t0, A1, A2, …, Ak, tau_in, tau_2, …, tau_k, tau_n for the extended pulse shape model.
- Returns:
The pulse shape model evaluated on the time grid.
- Return type:
np.ndarray
- class cait.fit.sev_fit_template(pm_par, t, down=1, t0_bounds=(-20, 20), truncation_level=None, interval_restriction_factor=None, saturation_pars=None)[source]
Bases:
objectClass to store pulse fit models for individual detectors.
This method was described in “F. Reindl, Exploring Light Dark Matter With CRESST-II Low-Threshold Detector”, available via http://mediatum.ub.tum.de/?id=1294132 (accessed on the 9.7.2021).
- Parameters:
par (1D array with size 6) – 1D array with size 6, the fit parameter of the sev (t0, An, At, tau_n, tau_in, tau_t).
t (1D array) – The time grid on which the pulse shape model is evaluated.
down (int) – Power of 2, the downsample rate of the event for fitting.
t0_bounds (tuple) – The lower and upper bounds for the t0 value.
truncation_level (float) – All values above this are excluded from the fit.
interval_restriction_factor (float) – Value between 0 and 1, the inverval of the event is restricted around 1/4 by this factor.
saturation_pars – The fit parameter of the saturation curve (A, K, C, Q, B, nu).
- Rtype saturation_pars:
1D array with size 6
- fit_cubic(pars)[source]
Calculates the standard event fit parameters with a cubic baseline model.
- Parameters:
pars (list of (1D array, float, float)) – The event to fit, the fixed onset value, a start value for the onset.
- Returns:
The sev fit parameters.
- Return type:
1D array of length 6
- sef(h, t0, a0)[source]
Standard Event Model with Flat Baseline.
- Parameters:
h (float) – Height of pulse shape.
t0 (float) – Onset of pulse shape.
a0 (float) – Offset of the baseline.
- Returns:
The pulse model evaluated on the time grid.
- Return type:
1D array
- sel(h, t0, a0, a1)[source]
Standard Event Model with Linear Baseline.
- Parameters:
h (float) – Height of pulse shape.
t0 (float) – Onset of pulse shape.
a0 (float) – Offset of the baseline.
a1 (float) – Linear drift component of the baseline.
- Returns:
The pulse model evaluated on the time grid.
- Return type:
1D array
- seq(h, t0, a0, a1, a2)[source]
Standard Event Model with Quadradtic Baseline.
- Parameters:
h (float) – Height of pulse shape.
t0 (float) – Onset of pulse shape.
a0 (float) – Offset of the baseline.
a1 (float) – Linear drift component of the baseline.
a2 (float) – Quadratic drift component of the baseline.
- Returns:
The pulse model evaluated on the time grid.
- Return type:
1D array
- cait.fit.threshold_model(x, a0, a1, a2)[source]
Fit model for the threshold
- Parameters:
x (array) – The grid on which the model is evaluated.
a0 (float) – Estimated constant survival probability above threshold.
a1 (float) – Estimated threshold value.
a2 (float) – Estimator for the energy resolution.
- Returns:
The evaluated error function
- Return type:
array