hexsample.analysis — Analysis facilities#

Module documentation#

Analysis facilities.

hexsample.analysis.create_histogram(input_file: InputFileBase, column_name: str, mc: bool = False, binning: ndarray = None, mask: ndarray = None) Histogram1d#

Create a histogram from the values in the given column of the input file.

This takes either a digi or a recon file as an input and create a one-dimensional histogram of the values in a given column.

Parameters:
  • input_file (DigiInputFile) – The input (digi or recon) file.

  • column_name (str) – The name of the column to be histogrammed.

  • mc (bool) – If True, histogram a quanity in the MonteCarlo extension of the file. Note this must be specified by the user, as the Recon and MonteCarlo tables share some of the column names, so that one needs to actively pick one or the other.

  • binning (array_like or int, optional) – This is following the matplotlib convention, where if binning is an integer, it defines the number of equal-width bins in the range, while if it is a sequence, it defines the bin edges, including the left edge of the first bin and the right edge of the last bin.

  • mask (array_like, optional) – An optional mask on the input values. The length of the mask must match that of the values in the input column.

hexsample.analysis.fit_histogram(hist: ~hexsample.hist.Histogram1d, fit_model: ~hexsample.modeling.FitModelBase = <class 'hexsample.modeling.DoubleGaussian'>, p0=None, show_figure: bool = True) array#

Fit an histogram given as argument.

Parameters:
  • input_file (DigiInputFile) – The input (digi or recon) file.

  • hist (Histogram1D) – The histogram to be fitted.

  • fitting_model (FitModelBase) – The FitModelBase instance containing the model used for fitting the histogram. Default is DoubleGaussian.

  • p0 (np.array) – The array containing the initial parameters of the fit. It must have the same len() as the number of parameters of the FitModelBase used for the fit.

  • plot_figure (bool) – Bool that states if the figure containing the histogram and the best fit has to be shown.

Returns:

model_status – The FitModelStatus instance returned by fit routine.

Return type:

FitModelStatus

hexsample.analysis.double_heatmap(column_vals: array, row_vals: array, heatmap_values1: array, heatmap_values2: array)#

Creates a figure containing two different heatmaps (with the same size) constructed row by row.

Even rows (counting from 0) are the rows of the heatmap1 heatmap, odd rows are the rows of the heatmap2 heatmap. heatmap_values1 and heatmap_values2 must have the same size and share the same axes. The resulting figure will have the following dimensions: 2*len(row_vals) x len(column_vals).

Parameters:
  • column_vals (np.array) – Values relative to the columns of the heatmaps.

  • row_vals (np.array) – Values relative to the row of the heatmaps.

  • heatmap_values1 (np.array) – A flatten array containing the values of every cell of the first heatmap.

  • heatmap_values1 – A flatten array containing the values of every cell of the second heatmap.

Returns:

  • fig (matplotlib.figure.Figure) – Figure contaning the heatmap.

  • ax (matplotlib.axes._axes.Axes) – Axes of fig.

hexsample.analysis.heatmap_with_labels(column_vals: array, row_vals: array, heatmap_values: array)#

Creates a figure containing an heatmap having in every cell printed the value of the cell itself.

Parameters:
  • column_vals (np.array) – Values relative to the columns of the heatmaps.

  • row_vals (np.array) – Values relative to the row of the heatmaps.

  • heatmap_values (np.array) – Values of the heatmap

Returns:

  • fig (matplotlib.figure.Figure) – Figure contaning the heatmap.

  • ax (matplotlib.axes._axes.Axes) – Axes of fig.