toolbox_scs.detectors.digitizers

Digitizers related sub-routines

Copyright (2021) SCS Team.

(contributions preferrably comply with pep8 code structure guidelines.)

Module Contents

Functions

get_dig_avg_trace(run, mnemonic[, ntrains])

Compute the average over ntrains evenly spaced accross all trains

check_peak_params(proposal, runNB, mnemonic[, ...])

Checks and plots the peak parameters (pulse window and baseline window

get_digitizer_peaks(proposal, runNB, mnemonic[, ...])

Extract the peaks from digitizer raw traces. The result can be merged

load_processed_peaks(proposal, runNB[, mnemonic, ...])

Load processed digitizer peaks data.

check_processed_peak_params(proposal, runNB, mnemonic)

Check the integration parameters used to generate the processed

toolbox_scs.detectors.digitizers.get_dig_avg_trace(run, mnemonic, ntrains=None)[source]

Compute the average over ntrains evenly spaced accross all trains of a digitizer trace.

Parameters:
  • run (extra_data.DataCollection) – DataCollection containing the digitizer data.

  • mnemonic (str) – ToolBox mnemonic of the digitizer data, e.g. ‘MCP2apd’.

  • ntrains (int) – Number of trains used to calculate the average raw trace. If None, all trains are used.

Returns:

trace – The average digitizer trace

Return type:

DataArray

toolbox_scs.detectors.digitizers.check_peak_params(proposal, runNB, mnemonic, raw_trace=None, ntrains=200, integParams=None, bunchPattern='sase3', plot=True, show_all=False)[source]

Checks and plots the peak parameters (pulse window and baseline window of a raw digitizer trace) used to compute the peak integration. These parameters are either set by the digitizer peak-integration settings, or are determined by a peak finding algorithmes. The parameters can also be provided manually for visual inspection. The plot either shows the first and last pulse of the trace or the entire trace.

Parameters:
  • proposal (int) – the proposal number

  • runNB (int) – the run number

  • mnemonic (str) – ToolBox mnemonic of the digitizer data, e.g. ‘MCP2apd’.

  • raw_trace (optional, 1D numpy array or xarray DataArray) – Raw trace to display. If None, the average raw trace over ntrains of the corresponding channel is loaded (this can be time-consuming).

  • ntrains (optional, int) – Only used if raw_trace is None. Number of trains used to calculate the average raw trace of the corresponding channel.

  • plot (bool) – If True, displays the raw trace and peak integration regions.

  • show_all (bool) – If True, displays the entire raw trace and all peak integration regions (this can be time-consuming). If False, shows the first and last pulse according to the bunchPattern.

  • bunchPattern (optional, str) – Only used if plot is True. Checks the bunch pattern against the digitizer peak parameters and shows potential mismatch.

Return type:

dictionnary of peak integration parameters

toolbox_scs.detectors.digitizers.get_digitizer_peaks(proposal, runNB, mnemonic, merge_with=None, bunchPattern='sase3', integParams=None, save=False, subdir='usr/processed_runs')[source]

Extract the peaks from digitizer raw traces. The result can be merged to an existing merge_with dataset and/or saved into an HDF file. The calculation is a trapezoidal integration between ‘pulseStart’ and ‘pulseStop’ with subtraction of a baseline defined as the median between ‘baseStart’ and ‘baseStop’. The integration parameters can either be provided using integParams, or computed by a peak finding algorithm if integParams is None. If the bunchPattern argument is provided, the pulse ids are aligned to it. If there is a mismatch between the provided parameters or the computed parameters and the bunch pattern, the bunch pattern parameters prevail.

Parameters:
  • proposal (int) – the proposal number

  • runNB (int) – the run number

  • mnemonic (str) – mnemonic for FastADC or ADQ412, e.g. “I0_ILHraw” or “MCP3apd”. The data is either loaded from the DataCollection or taken from merge_with.

  • merge_with (xarray Dataset) – If provided, the resulting Dataset will be merged with this one.

  • bunchPattern (str or dict) – ‘sase1’ or ‘sase3’ or ‘scs_ppl’, ‘None’: bunch pattern

  • integParams (dict) – dictionnary for raw trace integration, e.g. {‘pulseStart’:100, ‘pulsestop’:200, ‘baseStart’:50, ‘baseStop’:99, ‘period’:24, ‘npulses’:500}. If None, integration parameters are computed automatically.

Returns:

  • xarray Dataset with digitizer peak variables. Raw variables are

  • substituted by the peak caclulated values (e.g. “FastADC2raw” becomes

  • ”FastADC2peaks”).

toolbox_scs.detectors.digitizers.load_processed_peaks(proposal, runNB, mnemonic=None, data='usr/processed_runs', merge_with=None)[source]

Load processed digitizer peaks data.

Parameters:
  • proposal (int) – the proposal number

  • runNB (int) – the run number

  • mnemonic (str) – the mnemonic containing peaks. Example: ‘XRD_MCP_BIGpeaks’. If None, the entire dataset is loaded

  • data (str) – subdirectory. The data is stored in <proposal path>/<subdir>/r{runNB:04d}/r{runNB:04d}-digitizers-data.h5

  • merge_with (xarray Dataset) – A dataset to merge the data with.

Returns:

  • xarray DataArray if menmonic is not None and merge_with is None

  • xarray Dataset if mnemonic is None or merge_with is not None.

Example

# load the mono energy and the MCP_BIG peaks run, ds = tb.load(proposal, runNB, ‘nrj’) ds = tb.load_processed_peaks(proposal, runNB,’XRD_MCP_BIGpeaks’,

merge_with=ds)

toolbox_scs.detectors.digitizers.check_processed_peak_params(proposal, runNB, mnemonic, data='usr/processed_runs', plot=True, show_all=False)[source]

Check the integration parameters used to generate the processed peak values.

Parameters:
  • proposal (int) – the proposal number

  • runNB (int) – the run number

  • mnemonic (str) – the mnemonic containing peaks. Example: ‘XRD_MCP_BIGpeaks’. If None, the entire dataset is loaded

  • data (str) – subdirectory. The data is stored in <proposal path>/<subdir>/r{runNB:04d}/r{runNB:04d}-digitizers-data.h5

  • plot (bool) – If True, displays the raw trace and peak integration regions.

  • show_all (bool) – If True, displays the entire raw trace and all peak integration regions (this can be time-consuming). If False, shows the first and last pulses.

Returns:

params – the integration parameters with keys [‘pulseStart’, ‘pulseStop’, ‘baseStart’, ‘baseStop’, ‘period’, ‘npulses’]. See extract_digitizer_peaks().

Return type:

dict