From 04337cc13850c7a59c0665bdb95279049fd2df85 Mon Sep 17 00:00:00 2001 From: Laurent Mercadier <laurent.mercadier@xfel.eu> Date: Fri, 28 Feb 2020 18:58:37 +0100 Subject: [PATCH] Adds option to select peak (max) value instead of integrating over peak of fast ADC --- xgm.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/xgm.py b/xgm.py index 40d61ea..3ad8fd5 100644 --- a/xgm.py +++ b/xgm.py @@ -814,7 +814,7 @@ def matchXgmTimPulseId(data, use_apd=True, intstart=None, intstop=None, # Fast ADC -def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=None, npulses=None): +def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=None, npulses=None, usePeakValue=False): ''' Computes peak integration from raw FastADC traces. Inputs: @@ -859,11 +859,15 @@ def fastAdcPeaks(data, channel, intstart, intstop, bkgstart, bkgstop, period=Non bkga = bkgstart + period*i bkgb = bkgstop + period*i bg = np.outer(np.median(data[keyraw][:,bkga:bkgb], axis=1), np.ones(b-a)) - integ = np.trapz(data[keyraw][:,a:b] - bg, axis=1) - results[:,i] = integ + if usePeakValue: + val = np.max(data[keyraw][:,a:b] - bg, axis=1) + else: + val = np.trapz(data[keyraw][:,a:b] - bg, axis=1) + results[:,i] = val return results -def autoFindFastAdcPeaks(data, channel=5, threshold=35000, display=False, plot=False): +def autoFindFastAdcPeaks(data, channel=5, threshold=35000, usePeakValue=False, + display=False, plot=False): ''' Automatically finds positive peaks in channel of Fast ADC trace, assuming a minimum absolute height of 'threshold' counts and a minimum width of 4 samples. The find_peaks function and determination of the peak region and @@ -873,6 +877,8 @@ def autoFindFastAdcPeaks(data, channel=5, threshold=35000, display=False, plot=F data: xarray Dataset containing Fast ADC traces key: data key of the array of traces threshold: minimum height of the peaks + usePeakValue: bool, if True takes the peak value of the signal, + otherwise integrates over integration region. display: bool, displays info on the pulses found plot: plots regions of integration of the first pulse in the trace Output: @@ -897,7 +903,8 @@ def autoFindFastAdcPeaks(data, channel=5, threshold=35000, display=False, plot=F print(f'Found {npulses} pulses, avg. width={w}, period={period} samples, ' + f'rep. rate={1e6/(9.230769*period):.3f} kHz') fAdcPeaks = fastAdcPeaks(data, channel=channel, intstart=intstart, intstop=intstop, - bkgstart=bkgstart, bkgstop=bkgstop, period=period, npulses=npulses) + bkgstart=bkgstart, bkgstop=bkgstop, period=period, + npulses=npulses, usePeakValue=usePeakValue) if plot: plt.figure() plt.plot(trace, 'o-', ms=3) -- GitLab