diff --git a/xgm.py b/xgm.py index 40d61ea5443bad06ab7f96eb0db5e2b0a33c09bf..3ad8fd5c10a807815d4059344b6d9710d091a5ca 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)