npac_calibration.tools package¶
Submodules¶
npac_calibration.tools.constants module¶
npac_calibration.tools.data_extract module¶
- npac_calibration.tools.data_extract.count_peaks(data, layer_nbr, threshold, neighbour_condition=False)¶
Counts the number of energy peaks in the event for a chosen layer. For a peak to be considered as such, it must be above a certain threshold. Another condition (neighbour_condition) can be added.
Parameters¶
data : DataFrame layer_nbr : int_like
Number of the layer in which we want to find the peaks (between 0 and 6).
threshold : float_like neighbour_condition : bool
If neighbour_condition is True, in addition to the threshold, the peaks must have at least 3 neighbouring pixels with a non-zero value.
Returns¶
- counter_peaks, pixel positionint_like, list_like
counter_peaks is the number of peaks. pixel_position is a list containing the position of the peaks: [[idx1, idy1], [idx2, idy2], …].
Examples¶
>>> import npac_calibration.tools.data_extract as dext >>> data = dext.data_read("electron", True, 47) >>> __, __, __, energy = dext.data_columns(data) >>> counter_peaks, pixel_position = dext.count_peaks(data, 2, energy.min(), neighbour_condition = False) >>> len(pixel_position[0]) 2
- npac_calibration.tools.data_extract.count_peaks_dbscan(data, layer_nbr, threshold)¶
Finds the hits associated to an energy cluster.
Parameters¶
data : DataFrame layer_nbr : int_like
Number of the layer in which we want to find the peaks (between 0 and 6).
threshold : array_like
Returns¶
- labelsarray_like
For each pixel, it associates a natural integer corresponding to the cluster number of the pixel is indeed part of a cluster. It associates -1 if it is not.
Examples¶
>>> import npac_calibration.tools.data_extract as dext >>> data = dext.data_read("electron", True, 47) >>> __, __, layer, energy = dext.data_columns(data) >>> layer_nbr = 2 >>> threshold = np.array([10]) >>> peaks_nbr_dbscan = dext.count_peaks_dbscan(data, layer_nbr, threshold) >>> len(peaks_nbr_dbscan) == len(energy[layer == layer_nbr]) True
- npac_calibration.tools.data_extract.create_matrix(data, layer_nbr)¶
Creates a matrix with the energy hits for the chosen layer.
Parameters¶
data : DataFrame layer_nbr : int_like
Returns¶
matrix : ndarray
Examples¶
>>> layer_nbr = 7 >>> import npac_calibration.tools.data_extract as dext >>> data = dext.data_read("electron", True, 47) >>> __, __, layer, __ = dext.data_columns(data) >>> layer_nbr in range(layer.max()+1) False
>>> layer_nbr = 6 >>> layer_nbr in range(layer.max()+1) True >>> eng_matrix = dext.create_matrix(data, layer_nbr)
- npac_calibration.tools.data_extract.data_columns(data)¶
- Returns the idx, idy, layer and E columns from data.
idx is the pixel number along the x axis. idy is the pixel number along the y axis. layer is the layer number, it goes from 0 to 6. E is the energy.
Parameters¶
data : DataFrame
Returns¶
[idx, idy, layer, energy] : list_like
Examples¶
>>> import npac_calibration.tools.data_extract as dext >>> data = dext.data_read("electron", True, 47) >>> "idx" in data.columns True >>> "idy" in data.columns True >>> "layer" in data.columns True >>> "E" in data.columns True >>> idx, idy, layer, energy = dext.data_columns(data)
- npac_calibration.tools.data_extract.data_read(particle, shower, event_nbr, path=None)¶
Reads the data file corresponding to the chosen event.
Warning
Opens .csv files only.
Parameters¶
- particlestring_like
“electron” for electron events and “pion” for pion events.
- shower: bool
True for shower events and False for no-shower events.
- event_nbrint_like
Number of the chosen event.
- pathstring_like
Path to the data. If path is None, the function uses our predefined path.
Returns¶
data : DataFrame
Examples¶
>>> import npac_calibration.tools.data_extract as dext >>> type(dext.data_read("electron", True, 47)) <class 'pandas.core.frame.DataFrame'>
>>> path = "data/electron_1Gev_Shower/event000000047-hits_digitised.csv" >>> path.endswith('.csv') True
npac_calibration.tools.fit module¶
- npac_calibration.tools.fit.fit_gaussian(data, layer_nbr, N_bins, plot=False)¶
Gaussian fit of the histogram.
Parameters¶
data : DataFrame layer_nbr: int_like
Number of the chosen layer. Goes from 0 to 6.
- N_binsint_like
Number of bins in the histogram.
- plotbool
True to plot the fit and False to not plot it.
Returns¶
(Amplitude, standard deviation) : float_like
- npac_calibration.tools.fit.fit_gaussian2D(data, layer_nbr, threshold)¶
Gaussian fit of the histogram.
Parameters¶
data: DataFrame layer_nbr: int_like
Number of the chosen layer. Goes from 0 to 6.
Threshold: float_like
Returns¶
[Amplitude_x, standard deviation_x, Amplitude_y, standard deviation_y] : list_like
- npac_calibration.tools.fit.get_threshold(data, layer_nbr, n=3)¶
Affine function. Calculate the threshold below which the pixel is considered as noise.
Parameters¶
data: DataFrame layer_nbr: int_like
Number of the chosen layer. Goes from 0 to 6.
n: int_like
Returns¶
threshold : float_like
Examples¶
>>> import npac_calibration.tools.data_extract as dext >>> data = dext.data_read("electron", True, 47) >>> threshold = get_threshold(data, 0, n=3) >>> threshold.shape (1,)
npac_calibration.tools.generic_functions module¶
- npac_calibration.tools.generic_functions.gaussian(x, amp, sigma, mu)¶
Gaussian function.
Parameters¶
- x: array_like or float_like
input variable
- amp: float_like
Amplitude of the gaussian
- sigma: float_like
standard deviation of the gaussian
- mu: float_like
mean of the gaussian
Returns¶
gaussian : array_like or float_like
Examples¶
>>> gaussian(0, 1, 1, 0) np.float64(1.0)
- npac_calibration.tools.generic_functions.gaussian2D(X, amp, sigma_x, sigma_y, mu_x, mu_y)¶
Gaussian function.
Parameters¶
- X: array_like
List of two matrices of size 21x21.
- amp: float_like
Amplitude of the gaussian.
- sigma_x: float_like
standard deviation of the gaussian for the first element of X.
- mu_x: float_like
mean of the gaussian for the first element of X.
- sigma_y: float_like
standard deviation of the gaussian for the second element of X.
- mu_y: float_like
mean of the gaussian for the second element of X.
Returns¶
- gaussianarray_like
Array of size 441.
Examples¶
>>> x = np.arange(0,3,1) >>> y = np.arange(0,3,1) >>> X = np.meshgrid(x,y) >>> output = gaussian2D(X, 1, 1, 1, 0, 0) >>> output.shape (9,)
- npac_calibration.tools.generic_functions.gaussian_mu_fixed(x, amp, sigma)¶
Gaussian function with the mean fixed at zero.
Parameters¶
- x: array_like or float_like
input variable
- amp: float_like
Amplitude of the gaussian
- sigma: float_like
standard deviation of the gaussian
Returns¶
gaussian : array_like or float_like
Examples¶
>>> gaussian_mu_fixed(0, 1, 1) np.float64(1.0)