πŸ“š LIBRARIES#

ANA#

SUMMARY

Waveforms related functions.

  • General analysis. Insert a new variable in the dictionary (insert_variable), generate the cut array, get the units of the variables stored in the dictionary.

  • Peak/pedestal variables. Compute the peak and pedestal variables of the raw waveforms (compute_peak_variables, compute_pedestal_variables, compute_pedestal_variables_sliding_window, compute_pedestal_sliding_windows). We can also compute the processed waveforms with the pedestal subtracted as well as computing the power spectrum of the waveforms (compute_ana_wvfs, compute_power_spec). Finally, we are trying to optimize the functions by introducing numba libraries. The shift_ADCs function is used to shift the ADCs of the waveforms to the pedestal value. The shift4_numba function is used to shift the ADCs of the waveforms to the pedestal value using numba library.

  • Average waveforms. The following functions compute the average waveforms of the processed individual events.

  • Integration. Then we can use these average waveform reference values to choose an integration (or other criteria) to get the pC and PE.


CAL#

SUMMARY

These functions are used to perform calibration.

lib.cal_functions.calibrate(my_runs, info, keys, OPT={}, save=False, debug=False)[source]#

Computes calibration hist of a collection of runs. A fit is performed (train of gaussians) and we have as a return the popt, pcov, perr for the best fitted parameters. Not only that but a plot is displayed.

Parameters
  • my_runs (dict) – run(s) we want to check.

  • info (dict) – dictionary with the information of the run.

  • keys (list) – variables we want to plot as histograms.

  • OPT (dict) – several options that can be True or False. (a) LOGY: True if we want logarithmic y-axis (b) SHOW: if True, it will show the calibration plot

  • save (bool) – if True, it will save the plot in the images folder.

  • debug (bool) – if True, it will display the debug messages.

Returns

calibration

Return type

dict

lib.cal_functions.calibration_fit_plot(ax_cal, counts, bins, OPT, debug=False)[source]#

This function performs the calibration fit and plots the results.

Parameters
  • ax_cal (matplotlib axis) – axis to plot the calibration fit.

  • counts (nparray) – counts of the histogram.

  • bins (nparray) – bins of the histogram.

  • OPT (dict) – several options that can be True or False.

  • debug (bool) – if True, it will display the debug messages.

Returns

popt, pcov

Return type

tuple

lib.cal_functions.calibration_txt(run, ch, key, popt, pcov, info, debug=False) bool[source]#

Computes calibration parameters.

Parameters
  • run (int) – run number.

  • ch (int) – channel number.

  • key (str) – key of the histogram.

  • popt (nparray) – best fit parameters.

  • pcov (nparray) – covariance matrix.

  • info (dict) – dictionary with the information of the run.

  • debug (bool) – if True, it will display the debug messages.

Returns

export

Return type

bool

lib.cal_functions.charge_fit(my_runs, keys, OPT={})[source]#

Computes charge hist of a collection of runs. A fit is performed (1 gaussian) and we have as a return the popt, pcov, perr for the best fitted parameters. Not only that but a plot is displayed.

Parameters
  • my_runs (dict) – run(s) we want to check.

  • keys (list) – variables we want to plot as histograms.

  • OPT (dict) – several options that can be True or False. (a) LOGY: True if we want logarithmic y-axis (b) SHOW: if True, it will show the calibration plot

Returns

all_popt, all_pcov, all_perr

Return type

list, list, list

lib.cal_functions.export_txt(data: dict, info: dict, debug: bool = False) None[source]#

This function exports the calibration and xtalk data to a txt file.

Parameters
  • data (dict) – data to be exported.

  • info (dict) – dictionary with the information of the run.

  • debug (bool) – if True, it will display the debug messages.

Returns

None

lib.cal_functions.get_gains(run, channels, folder_path='TUTORIAL', debug=False)[source]#

This function reads the gains from the txt files.

Parameters
  • run (int) – run number.

  • channels (list) – channels to read the gains from.

  • folder_path (str) – path to the folder where the gains are stored.

  • debug (bool) – if True, it will display the debug messages.

Returns

gains, Dgain

Return type

dict, dict

lib.cal_functions.save_figures(fig_cal, fig_xt, labels, save_path, debug=False)[source]#

Saves the figures in the images folder.

Parameters
  • fig_cal (matplotlib figure) – figure of the calibration.

  • fig_xt (matplotlib figure) – figure of the xtalk.

  • labels (tuple) – labels of the histogram.

  • save_path (str) – path to the folder where the images are stored.

  • debug (bool) – if True, it will display the debug messages.

Returns

None

lib.cal_functions.scintillation_txt(run, ch, key, popt, pcov, filename, info)[source]#

Computes charge parameters. Given popt and pcov which are the output for the best parameters when performing the Gaussian fit.

Parameters
  • run (int) – run number.

  • ch (int) – channel number.

  • key (str) – key of the histogram.

  • popt (nparray) – best fit parameters.

  • pcov (nparray) – covariance matrix.

  • filename (str) – name of the file to save the parameters.

  • info (dict) – dictionary with the information of the run.

Returns

export

Return type

bool

lib.cal_functions.vis_persistence(my_run, info, OPT, save=False, debug=False)[source]#

This function plot the PERSISTENCE histogram of the given runs&ch. It perfoms a cut in 20<”PeakTime”(bins)<50 so that all the events not satisfying the condition are removed. Binning is fixed (x=5000, y=1000) [study upgrade]. X_data (time) and Y_data (waveforms) are deleted after the plot to save space. WARNING! flattening long arrays leads to MEMORY problems :/.

Parameters
  • my_run (dict) – run(s) we want to check.

  • info (dict) – dictionary with the information of the run.

  • OPT (dict) – several options that can be True or False.

  • save (bool) – if True, it will save the plot in the images folder.

  • debug (bool) – if True, it will display the debug messages.

lib.cal_functions.xtalk_fit_plot(ax_xt, popt, labels, OPT, debug=False)[source]#

This function performs the xtalk fit and plots the results.

Parameters
  • ax_xt (matplotlib axis) – axis to plot the xtalk fit.

  • popt (nparray) – best fit parameters.

  • labels (tuple) – labels of the histogram.

  • OPT (dict) – several options that can be True or False.

  • debug (bool) – if True, it will display the debug messages.

Returns

xt_popt, xt_pcov

Return type

tuple

lib.cal_functions.xtalk_txt(run, ch, key, xt_popt, xt_pcov, info, debug=False) bool[source]#

Computes xtalk parameters.

Parameters
  • run (int) – run number.

  • ch (int) – channel number.

  • key (str) – key of the histogram.

  • xt_popt (nparray) – best fit parameters.

  • xt_pcov (nparray) – covariance matrix.

  • info (dict) – dictionary with the information of the run.

  • debug (bool) – if True, it will display the debug messages.

Returns

export

Return type

bool


CUT#

SUMMARY

These functions are used to perform cuts.

lib.cut_functions.cut_df(my_runs, cut_dict={}, debug=False)[source]#

This function cuts the data using a dictionary with the cuts.

Parameters
  • my_runs (dict) – dictionary containing the data

  • cut_dict (dict, optional) – dictionary containing the cuts, defaults to {}. It must follow the format {(key, logic, value, inclusive): channels}

  • debug (bool) – boolean to print debug messages, defaults to False

Returns

None

lib.cut_functions.cut_lin_rel(my_runs, keys, compare='NONE', percentile=[0.1, 99.9])[source]#

This is a function to cut manually with a polygonal figure on two variables. You can do any polygonal figure (avoid strange figures with crossed lines). β€œLeft click” chooses vertexes, β€œright click” deletes the last vertex and β€œmiddle click” finishes the figure.

Parameters
  • my_runs (dict) – dictionary containing the data

  • keys (list) – list of variables you want to plot and cut

  • compare (str, optional) – NONE, RUNS, CHANNELS to decide the histogram to use, defaults to β€œNONE”

  • percentile (list, optional) – the percentile used to reject outliers in the histogram, defaults to [0.1, 99.9]

Returns

None

lib.cut_functions.cut_min_max(my_runs, keys, limits, ranges=[0, 0], chs_cut=[], apply_all_chs=False, debug=False)[source]#

This is a fuction for cuts of min - max values. It takes a variable(s) and checks whether its value is between the specified limits. Important! Each key works independently. If one key gives True and the other False, it remains False. Example: keys = [β€œPeakAmp”, β€œPeakTime”], limits = {β€œPeakAmp”: [20,50], β€œPeakTime”: [4e-6, 5e-6]}

Parameters
  • my_runs (dict) – dictionary containing the data

  • keys (list) – list of variables you want to constrain

  • limits (dict) – dictionary with same keys than variable β€œkeys” and a list of the min and max values you want

  • ranges (list, optional) – list with the range where we want to check the key value. If [0,0] it uses the whole window. Time in sec, defaults to [0,0]

  • chs_cut (list, optional) – list with the affected channels, defaults to []

  • apply_all_chs (bool, optional) – boolean to decide if we want to reject each cut event for ALL loaded channels, defaults to False

  • debug (bool) – boolean to print debug messages, defaults to False

Returns

None

lib.cut_functions.cut_min_max_sim(my_runs, keys, limits, debug=False)[source]#

This is a fuction for cuts of min - max values. It takes a variable(s) and checks whether its value is between the specified limits. Important! Keys are related, so all keys must be False to cut the event. If any of the conditions is True, the event is not cutted. Example: keys = [β€œPeakAmp”], limits = {β€œPeakAmp”: [20,50]}

Parameters
  • my_runs (dict) – dictionary containing the data

  • keys (list) – list of variables you want to constrain

  • limits (dict) – dictionary with same keys than variable β€œkeys” and a list of the min and max values you want

  • debug (bool) – boolean to print debug messages, defaults to False

Returns

None

lib.cut_functions.cut_peak_finder(my_runs, number_peaks, wdth=4, prom=0.01, dist=30)[source]#

This is a peak finder (aprox) and cuts events with more than β€œnumber_peaks” in the window. It checks if AveWvfSPE exists (for calibration runes) and set the threshold in 3/4 of the SPE max. Other way it takes into account the Max value in Pedestal (this works well for laser runes). WARNING! Maybe the values of width, prominence and distance may be changed.

Parameters
  • my_runs (dict) – dictionary containing the data

  • number_peaks (int) – number of peaks to cut

  • wdth (int, optional) – width of the peaks, defaults to 4

  • prom (float, optional) – prominence of the peaks, defaults to 0.01

  • dist (int, optional) – distance between peaks, defaults to 30

Returns

None

lib.cut_functions.cut_ped_std(my_runs, n_std=2, chs_cut=[], apply_all_chs=False, debug=False)[source]#

This is a fuction for a cut in the PedSTD. It uses the median as reference and eliminates events with PedSTD > median + n_std*std, where std is the Standard Deviation of the PedSTD distribution (previously filtered with percentiles).

Parameters
  • my_runs (dict) – dictionary containing the data

  • n_std (int, optional) – number of standard deviations to cut, defaults to 2

  • chs_cut (list, optional) – list with the affected channels, defaults to []

  • apply_all_chs (bool, optional) – boolean to decide if we want to reject each cut event for ALL loaded channels, defaults to False

  • debug (bool) – boolean to print debug messages, defaults to False

Returns

None

lib.cut_functions.cut_selector(my_runs, user_input, debug=False)[source]#
lib.cut_functions.generate_cut_array(my_runs, ref='TimeStamp', debug=False)[source]#

This function generates an array of bool = True. If cuts are applied and then you run this function, it resets the cuts.

Parameters
  • my_runs (dict) – dictionary containing the data

  • ref (str, optional) – reference variable to generate the cut array, defaults to β€œβ€

  • debug (bool, optional) – boolean to print debug messages, defaults to False

Returns

my_runs

Return type

dict

lib.cut_functions.print_cut_info(my_cuts, stage='partial', debug=False)[source]#

DEC#

SUMMARY

These functions are used to perform deconvolution.


FIG CONFIG#

lib.fig_config.add_grid(ax, lines=True, locations=None)[source]#

Add a grid to the current plot.

Parameters
  • ax (Axis) – axis object in which to draw the grid.

  • lines (bool, optional) – add lines to the grid, defaults to True

  • locations (tuple, optional) – (xminor, xmajor, yminor, ymajor), defaults to None

lib.fig_config.figure_features(tex=True, font='serif', dpi=600)[source]#

Customize figure settings.

Parameters
  • tex (bool, optional) – use LaTeX, defaults to tex_installed

  • font (str, optional) – font type, defaults to β€œserif”

  • dpi (int, optional) – dots per inch, defaults to 600

lib.fig_config.format_coustom_plotly(fig: plotly.graph_objs._figure.Figure, title: Optional[str] = None, legend: dict = {}, fontsize: int = 16, figsize: Optional[int] = None, ranges: tuple = (None, None), matches: tuple = ('x', 'y'), tickformat: tuple = ('.s', '.s'), log: tuple = (False, False), margin: dict = {'auto': True}, add_units: bool = True, debug: bool = False)[source]#

Format a plotly figure

Parameters
  • fig (go.Figure) – plotly figure

  • title (str, optional) – title of the figure, defaults to None

  • legend (dict, optional) – legend options, defaults to dict()

  • fontsize (int, optional) – font size, defaults to 16

  • figsize (tuple, optional) – figure size, defaults to None

  • ranges (tuple, optional) – axis ranges, defaults to (None,None)

  • matches (tuple, optional) – axis matches, defaults to (β€œx”,”y”)

  • tickformat (tuple, optional) – axis tick format, defaults to (β€˜.s’,’.s’)

  • log (tuple, optional) – axis log scale, defaults to (False,False)

  • margin (dict, optional) – figure margin, defaults to {β€œauto”:True}

  • add_units (bool, optional) – True to add units to axis labels, False otherwise, defaults to True

  • debug (bool, optional) – True to print debug statements, False otherwise, defaults to False

Returns

plotly figure

Return type

go.Figure

lib.fig_config.get_run_units(var, debug=False)[source]#

Returns the units of a variable based on the variable name

Parameters
  • var (str) – variable name

  • debug (bool) – True to print debug statements, False otherwise, defaults to False

Returns

units

Return type

str

lib.fig_config.unicode(x)[source]#

Returns the unicode character for a given string

Parameters

x (str) – string to convert to unicode

Returns

unicode character

Return type

str


FIT#

SUMMARY

These functions are used to perform fits.

lib.fit_functions.B(i, k, debug=False)[source]#

Factorial factor of F

lib.fit_functions.F(K, p, L, debug=False)[source]#

Computes prob of the kth point in a convoluted poisson+binomial distribution. L is the mean value of the poisson, p is the binomial coef, i.e. the crosstalk we want to compute

lib.fit_functions.PoissonPlusBinomial(x, N, p, L, debug=False)[source]#
lib.fit_functions.chi_squared(x, y, popt)[source]#
lib.fit_functions.cut_threshold(raw, thld)[source]#
lib.fit_functions.dec_gauss(f, fc, n)[source]#
lib.fit_functions.fit_dec_gauss(f, fc, n)[source]#
lib.fit_functions.fit_gaussians(x, y, *p0)[source]#
lib.fit_functions.fit_wvfs(my_runs, info, signal_type, thld, fit_range=[0, 200], i_param={}, in_key=['ADC'], out_key='', OPT: Optional[dict] = None, save: bool = True, debug: bool = True)[source]#

DOC

lib.fit_functions.func(t, t0, sigma, a, tau)[source]#
lib.fit_functions.func2(t, p, t0, sigma, a1, tau1, sigma2, a2, tau2)[source]#
lib.fit_functions.func3(t, p, t0, sigma, a1, tau1, a2, tau2, a3, tau3)[source]#
lib.fit_functions.gauss(x, a, x0, sigma)[source]#
lib.fit_functions.gaussian(x, center, height, width)[source]#
lib.fit_functions.gaussian_fit(counts, bins, bars, thresh, fit_function='gaussian', custom_fit=[0])[source]#

This function fits the histogram, to a gaussians.

Params counts

counts of the histogram

Params bins

bins of the histogram

Params bars

bars of the histogram

Params thresh

threshold value (for height of peaks and valleys)

Params fit_function

function to fit to, defaults to β€œgaussian”

Params custom_fit

custom fit, defaults to [0]

Returns

x, popt, pcov, perr – x values, fit parameters, covariance matrix and errors

Return type

tuple

lib.fit_functions.gaussian_train(x, *params)[source]#
lib.fit_functions.gaussian_train_fit(fig, x, y, y_intrp, peak_idx, valley_idx, params, debug=False)[source]#

This function fits the histogram, to a train of gaussians.

lib.fit_functions.get_initial_parameters(params)[source]#
DOC

This function checks the input parameters dictionary and sets default values for the scintillation fit parameters if they are not provided.

Parameters
paramsdict

A dictionary containing input parameters for the fit.

Returns
paramsdict

The input parameters dictionary with default values set for missing keys.

lib.fit_functions.lmfit_models(function)[source]#
lib.fit_functions.log_scint_profile(x, const, a_f, tau_f, tau_s)[source]#
lib.fit_functions.log_tau_slow_profile(x, a_s, tau_s)[source]#
lib.fit_functions.logfunc2(t, p, t0, sigma1, a1, tau1, sigma2, a2, tau2)[source]#
lib.fit_functions.logfunc3(t, p, t0, sigma, a1, tau1, a2, tau2, a3, tau3)[source]#
lib.fit_functions.loggaussian(x, center, height, width)[source]#
lib.fit_functions.loggaussian_train(x, *params)[source]#
lib.fit_functions.logpurity(t, p, t0, a1, a3, sigma, quenching)[source]#
lib.fit_functions.logsimple_purity(t, p, t0, a0, a1, sigma, quenching)[source]#
lib.fit_functions.peak_fit(fit_raw, raw_x, buffer, thld, sigma_fast=1e-09, a_fast=1, tau_fast=1e-08, OPT={})[source]#

This function fits the peak to a gaussian function, and returns the parameters

lib.fit_functions.peak_valley_finder(x, y, params)[source]#

This function finds the alternating peaks and valleys of the histogram.

lib.fit_functions.pmt_spe_fit(counts, bins, bars, thresh)[source]#

This function fits the histogram, to a train of gaussians

[es muy parecida a gaussian_train_fit; hay algunas cosas que las coge en log pero igual se pueden unificar]

[se le puede dedicar un poco mas de tiempo para tener un ajuste mas fino pero parece que funciona]

lib.fit_functions.pure_scint(time, t0, a1, a2, tau1, tau2)[source]#
lib.fit_functions.purity(t, p, t0, a1, a3, sigma, quenching)[source]#
lib.fit_functions.purity_fit(info, labels, raw, raw_x, fit_range, thld=1e-06, i_param={}, OPT: Optional[dict] = None, save: bool = True, debug: bool = False)[source]#

DOC

lib.fit_functions.sc_fit(info, labels, raw, raw_x, fit_range, thld=1e-06, OPT: Optional[dict] = None, save: bool = True, debug: bool = False)[source]#
lib.fit_functions.scfunc(t, a, b, c, d, e, f)[source]#
lib.fit_functions.scint_fit(info, labels, raw, raw_x, fit_range, thld=1e-06, i_param={}, OPT: Optional[dict] = None, save: bool = True, debug: bool = False)[source]#

DOC

lib.fit_functions.scint_profile(x, const, a_f, tau_f, tau_s)[source]#
lib.fit_functions.show_fit(info, raw, raw_x, func, labels, raw_max, buffer1, buffer2, param, thld=1e-06, OPT: Optional[dict] = None, save: bool = True, debug: bool = True)[source]#
DOC

This function shows the fit of the waveform and saves the figure if required.

Parameters
infodict

Dictionary containing information about the run and channel.

labelstuple

Tuple containing run, channel, and key information.

rawnp.ndarray

The raw waveform data to be fitted.

raw_xnp.ndarray

The x-axis values corresponding to the raw waveform data.

funcfunction

The fitting function to be used.

raw_maxint

The index of the maximum value in the raw waveform.

buffer1int

The number of points before the maximum to include in the fit.

buffer2int

The number of points after the maximum to include in the fit.

paramlist

The parameters obtained from the fit.

thldfloat, optional

Threshold value for the waveform, default is 1e-6.

OPTdict, optional

Dictionary containing options for the fit, such as filtering and logging.

savebool, optional

Whether to save the figure, default is False.

debugbool, optional

Whether to print debug information, default is False.

Returns

None

lib.fit_functions.simple_purity(t, p, t0, a0, a1, sigma, quenching)[source]#
lib.fit_functions.simple_purity_fit(info, labels, raw, raw_x, fit_range, thld=1e-06, i_param={}, OPT: Optional[dict] = None, save: bool = True, debug: bool = True)[source]#

DOC

lib.fit_functions.simple_scint_fit(info, labels, raw, raw_x, fit_range, i_param={}, OPT: Optional[dict] = None, save: bool = True, debug: bool = False)[source]#

DOC

lib.fit_functions.sipm_fit(info, labels, raw, raw_x, fit_range, thld=1e-06, OPT: Optional[dict] = None, save: bool = True, debug: bool = False)[source]#

DOC

lib.fit_functions.tau_fit(info, labels, raw, raw_x, fit_range, i_param={}, OPT: Optional[dict] = None, save: bool = True, debug: bool = False)[source]#

DOC

lib.fit_functions.tau_slow_profile(x, a_s, tau_s)[source]#
lib.fit_functions.test_gaussian(x, center, width)[source]#

GROUP#



IO#

SUMMARY

  • Read/write. Input files stored in the config/input folder (read_input_file). After deconvolution, new input files generated and can be used to re-run the workflow (list_to_string + generate_input_file).

  • Conversion. From raw(.root or .dat) data files to .npy or .npz files. For example, with raw data stored as run00/wave0.dat after running binary2npy we will create folders run00/ch0 where we will store the .npy files. Each .npy file will have the name of the variable we are storing (i.e ADC.npy, AveWvf.npy, PedSTD.npy, Sampling.npy).

  • [DEPRECATING] Check and delete the keys of a dictionary. The keys are the names of the variables stored in the dictionary that correspond to the names of the .npy files stored before.

  • Load/save .npy files. Get the list of preset names that we want to load or save. This output list is used then in the load/save functions.

lib.io_functions.binary2npy(runs, channels, info, compressed=True, header_lines=6, force=False, debug=False)[source]#

Dumper from binary format to npy tuples. Input are binary input file path and npy outputfile as strings. Depends numpy.

Parameters
  • runs (np.array) – array with the run numbers

  • channels (np.array) – array with the channel numbers

  • info (dict) – dictionary with the information stored in the input file

  • compressed (bool, optional) – if True, save the file as .npz, defaults to True

  • header_lines (int, optional) – number of header lines, defaults to 6

  • force (bool, optional) – if True, overwrite the file, defaults to False

  • debug (bool) – if True, print debug messages, defaults to False

lib.io_functions.binary2npy_express(in_file: str, header_lines: int = 6, debug: bool = False) tuple[source]#

Dumper from binary format to npy tuples. Input are binary input file path and npy outputfile as strings.

Parameters
  • in_file (str) – binary input file path

  • header_lines (int, optional) – number of header lines, defaults to 6

  • debug (bool) – if True, print debug messages, defaults to False

Returns

ADC, TIMESTAMP

Return type

tuple

lib.io_functions.check_key(OPT, key) bool[source]#

Checks if the given key is included in the dictionary OPT. Returns True if it finds the key.

Parameters
  • OPT (dict) – dictionary

  • key (str) – key to be checked

Returns

bool

lib.io_functions.cuts_info2dict(user_input: dict, info: dict, debug: bool = False) dict[source]#

Convert the information stored in the input file to a dictionary with the cuts information.

Parameters
  • user_input (dict) – dictionary with the user input

  • info (dict) – dictionary with the information stored in the input file

  • debug (bool) – if True, print debug messages, defaults to False

Returns

cuts_dict

Return type

dict

lib.io_functions.delete_keys(my_runs: dict, keys: list, debug: bool = False)[source]#

Delete the keys list introduced as 2nd variable

Parameters
  • my_runs (dict) – dictionary with the runs and channels

  • keys (list) – list with the keys to be deleted

  • debug (bool) – if True, print debug messages, defaults to False

lib.io_functions.generate_input_file(input_file, info, path: str = '/home/docs/checkouts/readthedocs.org/user_builds/scint/checkouts/latest/config/input/', label: str = '', debug: bool = False)[source]#

Generate a .txt file with the information needed to load the runs and channels. Used when deconvolving signals to be able to re-start the analysis workflow with the deconvolved waveforms.

Parameters
  • input_file (str) – name of the input file

  • info (dict) – dictionary with the information stored in the input file

  • path (str, optional) – path to the input file, defaults to f”{root}/config/input/”

  • label (str, optional) – label to be added to the input file, defaults to β€œβ€

  • debug (bool) – if True, print debug messages, defaults to False

lib.io_functions.get_preset_list(my_run: dict, path: str, folder: str, preset: str, option: str, debug: bool = False)[source]#

Return as output presets lists for load/save npy files. :param my_run: dictionary with the runs and channels (my_runs[run][ch]) :type my_run: dict :param path: path to the folder :type path: str :param folder: folder name :type folder: str :param preset: preset to be used (ALL, RAW, ANA, EVA, DEC, CAL, WVF) :type preset: str :param option: option to be used (LOAD, SAVE) :type option: str :param debug: if True, print debug messages, defaults to False :type debug: bool

Returns

branch_list

Return type

list

lib.io_functions.list_to_string(input_list: list) str[source]#

Convert a list to a string to be written in a .txt file. Used in generate_input_file.

Parameters

input_list (list) – list to be converted to string

Returns

string

Return type

str

lib.io_functions.load_npy(runs, channels, info, preset=None, branch_list=[], debug: bool = False, compressed: bool = True)[source]#

Loads the selected channels and runs, for simplicity, all runs must have the same number of channels. Presets can be used to only load a subset of desired branches.

Parameters
  • runs (list) – list of runs to load

  • channels (list) – list of channels to load

  • info (dict) – dictionary with the info of the run

  • preset (str, optional) – preset to be used (ALL, RAW, ANA, EVA, DEC, CAL, WVF), defaults None

  • branch_list (list) – list of branches to load, defaults []

  • debug (bool) – if True, print debug info, defaults False

  • compressed (bool, optional) – if True, load the file as .npz, defaults to True

Returns

my_runs with structure: run_dict[runs][channels][BRANCH]

Return type

dict

lib.io_functions.npy2df(my_runs, debug: bool = False) pandas.core.frame.DataFrame[source]#

Converts the npy files to a pandas dataframe.

Parameters
  • my_runs (dict) – dictionary with the runs and channels to be saved

  • debug (bool) – if True, print debug messages, defaults to False

Returns

df

Return type

pd.DataFrame

lib.io_functions.npy2root(my_runs, debug: bool = False)[source]#

Converts the npy files to root TTree files by converting the dictionaries to a RDataFrame from ROOT & using the snapshot method.

Parameters
  • my_runs (dict) – dictionary with the runs and channels to be saved

  • debug (bool) – if True, print debug messages, defaults to False

lib.io_functions.read_input_file(input: str, NUMBERS=[], DOUBLES=[], STRINGS=[], BOOLEAN=[], path: str = '/home/docs/checkouts/readthedocs.org/user_builds/scint/checkouts/latest/config/input/', debug: bool = False) dict[source]#

Obtain the information stored in a .txt input file to load the runs and channels needed.

Parameters
  • input (str) – name of the input file

  • NUMBERS (list, optional) – list of variables that are expected to be integers, defaults to []

  • DOUBLES (list, optional) – list of variables that are expected to be floats, defaults to []

  • STRINGS (list, optional) – list of variables that are expected to be strings, defaults to []

  • BOOLEAN (list, optional) – list of variables that are expected to be booleans, defaults to []

  • path (str, optional) – path to the input file, defaults to f”{root}/config/input/”

  • debug (bool, optional) – if True, print debug messages, defaults to False

Returns

info

Return type

dict

lib.io_functions.read_yaml_file(input: str, path: str = '/home/docs/checkouts/readthedocs.org/user_builds/scint/checkouts/latest/config/input/', debug: bool = False) dict[source]#

Obtain the information stored in a .yml input file to load the runs and channels needed.

Parameters
  • input (str) – name of the input file

  • path (str) – path to the input file, defaults to f”{root}/config/input/”

  • debug (bool) – if True, print debug messages, defaults to False

Returns

data

Return type

dict

lib.io_functions.root2npy(runs, channels, info: dict = {}, debug: bool = False)[source]#

[DEPRECATED - NEEDS UPDATE!! (see binary2npy)] Dumper from .root format to npy tuples. Input are root input file path and npy outputfile as strings. Depends on uproot, awkward and numpy. Size increases x2 times.

Parameters
  • runs (np.array) – array with the run numbers

  • channels (np.array) – array with the channel numbers

  • info (dict) – dictionary with the information stored in the input file

  • debug (bool) – if True, print debug messages, defaults to False

lib.io_functions.save_figure(fig, path, run, ch, label, debug: bool = True)[source]#

Saves the figure in the desired path with the desired name.

Parameters
  • fig (matplotlib.figure.Figure) – figure to be saved

  • path (str) – path to save the figure

  • run (int) – run number

  • ch (int) – channel number

  • label (str) – label of the figure

  • debug (bool) – if True, print debug messages, defaults to False

lib.io_functions.save_proccesed_variables(my_runs, info, preset='', branch_list=None, force=False, compressed=True, debug=False)[source]#

Saves the processed variables an npx file.

Parameters
  • my_runs (dict) – dictionary with the runs and channels to be saved

  • info (dict) – dictionary with the path and month to be used

  • preset (str) – preset to be used to save the variables

  • branch_list (list) – list of branches to be saved

  • force (bool, optional) – if True, the files will be overwritten, defaults to False

  • compressed (bool, optional) – if True, the files will be saved as npz, if False, as npy, defaults to True

  • debug (bool) – if True, the function will print the branches that are being saved, defaults to False

lib.io_functions.write_output_file(run, ch, output, filename, info: dict, header_list: list, write_mode: str = 'w', not_saved: list[int] = [2, 3], debug: bool = False) bool[source]#

General function to write a txt file with the outputs obtained. The file name is defined by the given β€œfilename” variable + _chX. If the file existed previously it appends the new fit values (it save the run for each introduced row). By default we dont save the height of the fitted gaussian in the txt.

Parameters
  • run (int) – run number

  • ch (int) – channel number

  • output (list) – output to be written in the file

  • filename (str) – name of the file

  • info (dict) – dictionary with the information stored in the input file

  • header_list (list) – list with the header to be written in the file

  • write_mode (str, optional) – mode to write the file, defaults to β€œw”

  • not_saved (list, optional) – list of columns that are not saved in the file, defaults to [2, 3]

  • debug (bool) – if True, print debug messages, defaults to False

Returns

bool

Return type

bool


MINUIT#

SUMMARY

These functions are used to perform fits.


PLY#


SIM#


STY#

lib.sty_functions.get_color(number, even=True, style='prism', debug=False)[source]#
lib.sty_functions.get_even_color(number)[source]#
lib.sty_functions.get_prism_colors()[source]#
lib.sty_functions.style_selector(OPT: Optional[dict] = None)[source]#

UNIT#

lib.unit_functions.calibrate_charges(my_runs, info, user_input, debug=False)[source]#
lib.unit_functions.get_run_units(my_runs, debug=False)[source]#

Computes and store in a dictionary the units of each variable.

Parameters
  • my_runs (dict) – dictionary containing the data

  • debug (bool, optional) – boolean to print debug messages, defaults to False

Returns

None

lib.unit_functions.get_unit(key, debug=False)[source]#

VIS#

SUMMARY

These functions are used to visualize the data.

  • Individual evts. We can compare them with the computed AveWaveform is computed, and also we can plot several average waveforms in the same plot (vis_npy, vis_compare_wvf).

  • Histograms. 1D and 2D histograms of the chosen variables. In principle these histograms are used to generate cuts of outlying events (vis_var_hist, vis_two_var_hist).

  • Statistics. we can print the statistics of the variables stored in the dictionary (print_stats).

lib.vis_functions.plot_compare_wvf(my_run, info, run, ch, key, fig, axs, idx, OPT, ref_max_idx=None, stats=False)[source]#

This function plots the waveform of the selected key. It allows to compare between runs or channels.

Parameters
  • my_run (dict) – run(s) we want to check

  • info (dict) – info dictionary

  • run (int) – run we want to check

  • ch (int) – channel we want to check

  • key (str) – key we want to plot

  • fig (matplotlib.figure.Figure) – figure to plot

  • axs (matplotlib.axes._subplots.AxesSubplot) – axis to plot

  • idx (int) – index to plot

  • OPT (dict) – several options that can be True or False (a) MICRO_SEC: if True we multiply Sampling by 1e6 (b) NORM: True if we want normalized waveforms (c) LOGY: True if we want logarithmic y-axis (d) STATS: True if we want to print statistics

  • ref_max_idx (int) – index to align the waveforms

  • stats (bool) – True if we want to print statistics

Returns

ref_max_idx

Return type

int

lib.vis_functions.print_stats(my_run, labels, ax, data, info, save=False, debug=False)[source]#

This function prints the statistics of the data.

Parameters
  • my_run (dict) – run(s) we want to check

  • labels (tuple) – labels of the data

  • ax (matplotlib axis) – axis to plot

  • data (list) – data to analyze

  • info (dict) – info dictionary

  • save (bool) – True if we want to save the statistics

  • debug (bool) – True if we want to print debug messages

Returns

None

lib.vis_functions.print_stats_terminal(my_run, labels, data)[source]#

This function prints the statistics of the data in the terminal.

Parameters
  • my_run (dict) – run(s) we want to check

  • labels (tuple) – labels of the data

  • data (list) – data to analyze

Returns

rate

Return type

float

lib.vis_functions.vis_compare_wvf(my_run, info, keys, OPT={}, save=False, debug=False)[source]#

This function is a waveform visualizer. It plots the selected waveform with the key and allow comparisson between runs/channels.

Parameters
  • my_run (dict) – run(s) we want to check

  • info (dict) – info dictionary

  • keys (list) – waveform to plot (AveWvf, AveWvdSPE, …)

  • OPT (dict) – several options that can be True or False (a) MICRO_SEC: if True we multiply Sampling by 1e6 (b) NORM: True if we want normalized waveforms (c) LOGY: True if we want logarithmic y-axis (d) COMPARE: β€œRUNS” to get a plot for each channel and the selected runs, β€œCHANNELS” to get a plot for each run and the selected channels (e) STATS: True if we want to print statistics

  • save (bool) – True if we want to save the plot

  • debug (bool) – True if we want to print debug messages

Returns

None

lib.vis_functions.vis_npy(my_run, info, keys, OPT={}, save=False, debug=False)[source]#

This function is a event visualizer. It plots individual events of a run, indicating the pedestal level, pedestal std and the pedestal calc limit. We can interact with the plot and pass through the events freely (go back, jump to a specific event…)

Parameters
  • my_run (dict) – run(s) we want to check

  • info (dict) – info dictionary

  • keys (list) – choose between ADC or AnaADC to see raw (as get from ADC) or Analyzed events (starting in 0 counts), respectively

  • OPT (dict) – several options that can be True or False (a) MICRO_SEC: if True we multiply Sampling by 1e6 (b) NORM: True if we want normalized waveforms (c) LOGY: True if we want logarithmic y-axis (d) SHOW_AVE: if computed and True, it will show average (e) SHOW_PARAM: True if we want to check calculated parameters (pedestal, amplitude, charge…) (f) CHARGE_KEY: if computed and True, it will show the parametre value (g) PEAK_FINDER: True if we want to check how many peaks are (h) CUTTED_WVF: choose the events we want to see. If -1 all events are displayed, if 0 only uncutted events are displayed, if 1 only cutted events are displayed (i) SAME_PLOT: True if we want to plot different channels in the SAME plot

  • save (bool) – True if we want to save the plot

  • debug (bool) – True if we want to print debug messages

Returns

None

lib.vis_functions.vis_two_var_hist(my_run, info, keys, percentile=[0.1, 99.9], select_range=False, OPT: Optional[dict] = None, save=False, debug=False)[source]#

This function plots two variables in a 2D histogram. Outliers are taken into account with the percentile. It plots values below and above the indicated percetiles, but values are not removed from data.

Parameters
  • my_run (dict) – run(s) we want to check

  • info (dict) – info dictionary

  • keys (list) – variables we want to plot as histograms. Type: List

  • percentile (list) – percentile used for outliers removal

  • select_range (bool) – True if we want to select the range of the histogram (useful if there are many outliers)

  • OPT (dict) – several options that can be True or False (a) DENSITY: True if we want density histograms (b) ACCURACY: binning of the histogram (c) TERMINAL_MODE: True if we want to select the channels in the terminal (d) COMPARE: β€œRUNS” to get a plot for each channel and the selected runs, β€œCHANNELS” to get a plot for each run and the selected channels (e) SHOW: True if we want to show the plot (f) SAVE: True if we want to save the plot

  • save (bool) – True if we want to save the plot

  • debug (bool) – True if we want to print debug messages

Returns

None

lib.vis_functions.vis_var_hist(my_run, info, key, percentile=[0.1, 99.9], OPT={'SHOW': True}, select_range=False, save=False, debug=False)[source]#

This function takes the specified variables and makes histograms. The binning is fix to 600, so maybe it is not the appropriate. Outliers are taken into account with the percentile. It discards values below and above the indicated percetiles. It returns values of counts, bins and bars from the histogram to be used in other function. WARNING! Maybe the binning stuff should be studied in more detail.

Parameters
  • my_run (dict) – run(s) we want to check

  • info (dict) – info dictionary

  • key (list) – variables we want to plot as histograms. Type: List (a) PeakAmp: histogram of max amplitudes of all events. The binning is 1 ADC. There are not outliers. (b) PeakTime: histogram of times of the max amplitude in events. The binning is the double of the sampling. There are not outliers. (c) Other variable: any other variable. Here we reject outliers.

  • percentile (list) – percentile used for outliers removal

  • OPT (dict) – several options that can be True or False (a) DENSITY: True if we want density histograms (b) ACCURACY: binning of the histogram (c) TERMINAL_MODE: True if we want to select the channels in the terminal (d) COMPARE: β€œRUNS” to get a plot for each channel and the selected runs, β€œCHANNELS” to get a plot for each run and the selected channels (e) SHOW: True if we want to show the plot (f) SAVE: True if we want to save the plot

  • select_range (bool) – True if we want to select the range of the histogram

  • save (bool) – True if we want to save the plot

  • debug (bool) – True if we want to print debug messages

Returns

all_counts, all_bins