## 3 Discussion  
Given a set of scans \(\left\{\mathbf{S}^{(k)}\right\}\), their weighted average is  
\[\left\langle\mathbf{S}\right\rangle=\frac{\sum_{k}w_{k}\mathbf{S}^{(k)}}{\sum _{k}w_{k}} \tag{7}\]  
Figure 1: (**a**) Three representative delay scans and (**b**) their autocorrelation curves. We use the autocorrelation curves (\(q=0\) excluded) as a criterion to classify scans as good (black), drifting (red), or pure noise (blue). The autocorrelation curve of a good scan is well approximated by a gaussian (green). In panel (**a**), traces have been offset for clarity, and the shaded curve is the weighed average Equation (7); in panel (**b**), the green curve is a gaussian fit of the black autocorrelation trace; the gray curve is the same, scaled to the height of the red autocorrelation trace (white-noise peak excluded). The calculated signal-to-noise ratio \((SNR)\) for the three scans are 1.30, 0.52, and 0.20. \(\langle\mathbf{S}\rangle\) is the quantity reported in our work ([1] note for the sake of exactness that in Figure 2a therein, the unity baseline was not subtracted); we want to determine which scans to include in the average, and their weights \(w_{k}\). From Equation (6) and Figure 1b we can estimate the signal-to-noise ratio as:  
\[SNR_{k}=\sqrt{\frac{(\mathbf{S}^{(k)}\star\mathbf{S}^{(k)})_{0}}{(\mathbf{N}^{ (k)}\star\mathbf{N}^{(k)})_{0}}-1}=\sqrt{\frac{\alpha_{k}^{2}(\mathbf{R}\star \mathbf{R})_{0}}{(\mathbf{N}^{(k)}\star\mathbf{N}^{(k)})_{0}}}=\frac{\alpha_{ k}}{\sigma_{k}} \tag{8}\]  
A simple analysis of its trend over the course of the experiment reveals some regularities that we exploit to qualitatively classify scans, and to define a quantitative criterion that we adopt to accept or reject them. When the scans are ordered in the sequence they were acquired (Figure 2a) no obvious trend is visible for the \(SNR\), but one does note a large number of scans with \(SNR=0\): they are either those for which a gaussian fit of the autocorrelation was not successful, or those which have been excluded _a priori_ (e.g., because the scan was aborted). The ordering of the scans by increasing \(SNR\) (Figure 2b) reveals a gap between scans with \(SNR<0.25\) and \(SNR>0.45\). We cannot find an obvious reason for this gap; because this was one of the first resonant two-photon experiments performed at FERMI we can speculate a threshold behavior of some of the less-controlled parameters of the FEL (peak intensity; second harmonic content). In any case, we decided to use the condition \(SNR>0.45\) as a discriminant to include a scan in the average. Let us now come to the weight with which each accepted scan enters the average. We show in Appendix A that the weight which maximizes the \(SNR\) of \(\langle\mathbf{S}\rangle\) is \(w_{k}=\alpha_{k}/\sigma_{k}^{2}=SNR_{k}/\sigma_{k}\); in Ref. [1] we used \(w_{k}=SNR_{k}\), which gives a slightly worse result, although the difference is not significant. We presume that the latter fact depends on the limited number of samples, the predominance of few of them (see Figure 2a), and the low dispersion of the \(\sigma_{k}\). In both cases we observe an improvement of the signal-to-noise ratio of \(\langle\mathbf{S}\rangle\) by a factor \(\approx\)2.25 relative to the best single scan. Unfortunately at the time of the experiment we were not anticipating the need for this test, so we are not able to perform further checks on which parameters and events mostly affected our experiment. Likewise our primary goal was to identify a simple unbiased method of data selection, and we do not attempt a systematic analysis of its merits and limitations, for which we refer the reader to the vast existing literature ([6,7] and references therein); we simply note that the method is most easily applicable to the case of white noise and single- or well-separated peaks, although generalizations to other noise [6] or multiple peaks [8] have been discussed.