From 29d74c4d82be9f3bda74d6a7ca6f6122e26102d3 Mon Sep 17 00:00:00 2001 From: mercadil <laurent.mercadier@xfel.eu> Date: Sun, 24 Mar 2019 12:15:00 +0100 Subject: [PATCH] Simplified test of conditions in mcpPeaks --- xgm.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/xgm.py b/xgm.py index 73eb3d5..5f7c3c0 100644 --- a/xgm.py +++ b/xgm.py @@ -351,11 +351,14 @@ def mcpPeaks(data, intstart, intstop, bkgstart, bkgstop, mcp=1, t_offset=None, n bkgstart: trace index of background start bkgstop: trace index of background stop mcp: MCP channel number - t_offset: index separation between two pulses - npulses: number of pulses + t_offset: index separation between two pulses. If None, checks the + pulse pattern and determine the t_offset assuming mininum pulse + separation of 220 ns and digitizer resolution of 2 GHz. + npulses: number of pulses. If None, takes the maximum number of + pulses according to the bunch patter (field 'npulses_sase3') Output: - results: DataArray with dims trainId x max(sase3 pulses)*1MHz/intra-train rep.rate + results: DataArray with dims trainId x max(sase3 pulses) ''' keyraw = 'MCP{}raw'.format(mcp) @@ -364,13 +367,14 @@ def mcpPeaks(data, intstart, intstop, bkgstart, bkgstop, mcp=1, t_offset=None, n if npulses is None: npulses = int(data['npulses_sase3'].max().values) sa3 = data['sase3'].where(data['sase3']>1) - if npulses > 1: - step = sa3.where(data['npulses_sase3']>1, drop=True)[0,:2].values - step = int(step[1] - step[0]) - if t_offset is None: + if t_offset is None: + if npulses > 1: + #Calculate the number of pulses between two lasing pulses (step) + step = sa3.where(data['npulses_sase3']>1, drop=True)[0,:2].values + step = int(step[1] - step[0]) + #multiply by elementary samples length (220 ns @ 2 GHz = 440) t_offset = 440 * step - else: - if t_offset is None: + else: t_offset = 1 results = xr.DataArray(np.empty((sa3.shape[0], npulses)), coords=sa3.coords, dims=['trainId', 'MCP{}fromRaw'.format(mcp)]) @@ -409,6 +413,7 @@ def getTIMapd(data, mcp=1, use_apd=True, intstart=None, intstop=None, maxpulses = int(npulses_sa3.max().values) step = 1 if maxpulses > 1: + #Calculate the number of non-lasing pulses between two lasing pulses (step) step = sa3.where(data['npulses_sase3']>1, drop=True)[0,:2].values step = int(step[1] - step[0]) if use_apd: @@ -429,6 +434,7 @@ def getTIMapd(data, mcp=1, use_apd=True, intstart=None, intstop=None, if np.all(npulses_sa3 == npulses_sa3[0]): tim = apd[:, sa3[0].values] return tim + stride = 1 if use_apd: stride = np.max([stride,int(step/npulses_per_apd)]) -- GitLab