π LIBRARIES
Contents
π 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.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
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
FIT#
SUMMARY
These functions are used to perform fits.
- 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.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.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_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.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.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.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.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_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
GROUP#
HEAD#
SUMMARY
These functions are used to start the macros, configure the flags and information provided by the user.
- lib.head_functions.apply_cuts(user_input, info, debug=False)[source]#
This function asks the user to select the cuts to be apply to your events.
- Parameters
user_input (dict) β Dictionary with the user input.
info (dict) β Dictionary with the information from the input file.
debug (bool, optional) β Debug mode, defaults to False
- Returns
cut_dict β Dictionary with the cuts to be applied to your events.
- Return type
dict
- lib.head_functions.convert_str_to_type(value, debug=False)[source]#
This function converts a string to its corresponding type.
- Parameters
value (str) β Value to be converted.
debug (bool, optional) β Debug mode, defaults to False
- Returns
value β Converted value.
- Return type
any
- lib.head_functions.get_flag_dict()[source]#
This function returns a dictionary with the available flags for the macro.
- Params None
- Returns
flag_dict (dict) β Dictionary with the available flags for the macro.
- Return type
dict
- lib.head_functions.initialize_macro(macro, input_list: Optional[list] = ['input_file', 'debug'], default_dict: Optional[dict] = None, debug: bool = False)[source]#
This function initializes the macro by reading the input file and the user input.
- Parameters
macro (str) β Name of the macro to be executed.
input_list (list, optional) β List with the keys of the user input that need to be updated, defaults to [βinput_fileβ, βdebugβ]
default_dict (dict, optional) β Dictionary with the default values for the user input, defaults to None
debug (bool, optional) β Debug mode, defaults to False
- Returns
user_input, info β Dictionary with the user input and dictionary with the information from the input file.
- Return type
tuple
- lib.head_functions.opt_selector(filename: str = 'options', arguments: Optional[list] = None, debug: bool = False)[source]#
This function reads the options from a YAML file and allows the user to select the options to be used.
- Parameters
filename (str, optional) β Name of the YAML file, defaults to βoptionsβ
arguments (list, optional) β List with the arguments to be used, defaults to None
debug (bool, optional) β Debug mode, defaults to False
- Returns
updated_opt β Dictionary with the updated options.
- Return type
dict
- lib.head_functions.print_macro_info(macro, debug=False)[source]#
This function prints the information about the macro.
- Parameters
macro (str) β Name of the macro to be executed
debug (bool, optional) β Debug mode, defaults to False
- lib.head_functions.select_input_file(user_input, debug=False)[source]#
This function asks the user to select the input file.
- Parameters
user_input (dict) β Dictionary with the user input.
debug (bool, optional) β Debug mode, defaults to False
- Returns
new_user_input β Dictionary with the updated user input.
- Return type
dict
- lib.head_functions.update_user_input(user_input, new_input_list, info, debug=False)[source]#
This function updates the user input by asking the user to provide the missing information.
- Parameters
user_input (dict) β Dictionary with the user input.
new_input_list (list) β List with the keys of the user input that need to be updated.
info (dict) β Dictionary with the information from the input file.
debug (bool, optional) β Debug mode, defaults to False
- Returns
new_user_input, info β Dictionary with the updated user input and dictionary with the information from the input file.
- Return type
tuple
- lib.head_functions.update_yaml_file(file_path: str, new_data: dict, convert: bool = True, debug: bool = False)[source]#
This function updates a YAML file with new data.
- Parameters
file_path (str) β Path to the YAML file.
new_data (dict) β Dictionary with the new data to be added.
convert (bool, optional) β Convert string to type, defaults to True
debug (bool, optional) β Debug mode, defaults to False
- Returns
None
- lib.head_functions.use_default_input(user_input, default_dict, info, debug=False)[source]#
This function updates the user input by asking the user to provide the missing information.
- Parameters
user_input (dict) β Dictionary with the user input.
default_dict (dict) β Dictionary with the default values for the user input.
info (dict) β Dictionary with the information from the input file.
debug (bool, optional) β Debug mode, defaults to False
- Returns
new_user_input β Dictionary with the updated user input.
- Return type
dict
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#
UNIT#
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