{'fraction_non_alphanumeric': 0.02482786789590384, 'fraction_numerical': 0.011028124635313339, 'mean_word_length': 4.7444276856041565, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Machine learning applied to single-shot x-ray diagnostics in an XFEL

X-ray free-electron lasers (XFELs) are the only sources currently able to produce bright few-fs pulses with tunable photon energies from 100 eV to more than 10 keV. Due to the stochastic SASE operating principles and other technical issues the output pulses are subject to large fluctuations, making it necessary to characterize the x-ray pulses on every shot for data sorting purposes. We present a technique that applies machine learning tools to predict x-ray pulse properties using simple electron beam and x-ray parameters as input. Using this technique at the Linac Coherent Light Source (LCLS), we report mean errors below 0.3 eV for the prediction of the photon energy at 530 eV and below 1.6 fs for the prediction of the delay between two x-ray pulses. We also demonstrate spectral shape prediction with a mean agreement of 97%. This approach could potentially be used at the next generation of high-repetition-rate XFELs to provide accurate knowledge of complex x-ray pulses at the full repetition rate.


I. INTRODUCTION
X-ray free-electron lasers (XFELs) 1-3 are emerging as one of the most versatile tools in x-ray research, becoming widely used by the scientific community, as well as industry, in many fields including physics, chemistry, biology, and material science. Their brightness, coherence, tunability, and ability to generate pairs of few-fs multicolor pulses for pump-probe experiments 4-7 make them ideal sources to perform diffract-before-destroy imaging 8 , resonant x-ray spectroscopy 9 , and a range of time resolved measurements of picosecond to few-femtosecond dynamics in molecules and atoms [10][11][12][13][14][15][16] .
A drawback to XFELs is their current poor stability. XFELs are driven by single-pass electron linear accelerators (LINAC) typically several hundred meters in length. High density electron bunches are formed in an electron photoinjector, accelerated in radiofrequency (RF) cavities, compressed in magnetic chicanes, and finally driven through one or multiple undulator sections where the electrons emit coherent x-ray pulses due to Self Ampli-fied Spontaneous Emission (SASE) 17 (see Figure 1) or amplify an external laser seed in High Gain Harmonic Generation (HGHG) schemes 18 . Small fluctuations in, for example, the photoinjector drive laser, RF amplitudes or phases along the LINAC translate into fluctuations in the XFEL pulse properties. Furthermore, all existing XFEL machines operating at wavelengths shorter than 4 nm have additional fluctuations due to the stochastic character of the SASE startup process, and shows only partial longitudinal coherence across the XFEL pulse. As a result, even a perfectly stable electron beam will exhibit shot-to-shot fluctuations in the fine temporal structure of the x-ray pulse. For example, when using single-pulse SASE emission at the LINAC Coherent Light Source (LCLS), fluctuations driven primarily by the LINAC RF systems lead to photon energy jitter of 0.1% to 0.5% full width half maximum (FWHM), depending on the central wavelength. The energy jitter drives bunch compression jitter leading to pulse length fluctuations of~5% and intensity fluctuations from 1% to 10%. These numbers are exacerbated in more advanced lasing schemes such as the twin bunch technique 5 where two electron bunches are accelerated simultaneously to produce two pulses with variable time delay and photon energy separation. In this case the inter pulse delay jitter is in the order of 10 to 15 fs FWHM and the intensity can fluctuate much more widely (~20-100%).
Often the only way around such instabilities is performing a full x-ray characterization for each XFEL shot, using a variety of detection methods such as gas detectors (total pulse energy), single-shot x-ray spectrometers (wavelength, spectral shape and even polarization), and transverse deflecting cavities for the spent electron bunches (pulse shape, pulse duration and delay between pulses). Based on these measurements, one can circumvent issues with instability by retaining only the events presenting certain pulse characteristics, or even exploiting the jitter to act as an effective power 19 , wavelength 19,20 or delay scan 21 by sorting and binning the events according to those characteristics. Unfortunately, some diagnostics that intercept the full beam such as optical spectrometers are incompatible with some experimental setups, requiring the x-rays to be either sent to the diagnostic line or to the sample. Furthermore, many of those essential diagnostics will not be compatible with the next generation of XFELs driven by superconducting LINACs operating at MHz rates such as European XFEL 22 or the LCLS-II 23 . Simple shot-to-shot diagnostics such as electron bunch monitors (beam position, beam energy, peak current), x-ray gas detectors, or particle time-of-flight (TOF) detectors can in principle work at the increased repetition rate but this will not always be the case. In general, devices that require intercepting the full electron or x-ray beam with a solid, such as screens to measure the electron bunch phase space streaked by a transverse cavity or the time tool 21 for optical pulse synchronization, will not be able to cope with the thermal load at the high repetition rate. Moreover, devices that rely on a CCD array will not have in most cases the required bandwidth for readout and storage of the data at MHz rates. This means that any experiment requiring single-shot characterization will likely be limited to a much lower (<1 kHz) repetition rate.
In this paper we propose a general method applicable at any XFEL facility to obtain typical complex shot-toshot diagnostics or any other variable at a higher repetition rate than that allowed by the corresponding acquisition devices. Using data from the LCLS operating at 120 Hz as an example, we found that much of the information usually extracted from slow, complex diagnostics such as the pump-probe delay in the twin bunch mode, the photon energy, or even the spectral shape of the xray pulses, is strongly correlated to electron bunch and x-ray properties measured by fast diagnostics. While this correlations are driven by physical processes, performing accurate direct modelling of every experimental aspect in machines as complex as XFELs is not currently possible. As an alternative we use generic linear, quadratic and more complex but well known machine learning models such as Neural Networks (NN) 24 or Support Vector Re-gression (SVR) 25 to describe the non-trivial hidden correlations between the fluctuations in the simple diagnostics and the fluctuations in the complex diagnostics. Similar approaches have been successfully used for feedbackloops at particle accelerator facilities 26 . Furthermore, by including fast gas detectors, measuring the total x-ray energy, which is sensitive to SASE fluctuations, we can make predictions accounting for some of the stochastic jitter. These models can be fitted or trained to predict the output of complex diagnostics, such as pump-probe delay, using a small amount of training data obtained for a fraction of the shots containing full diagnostics. After applying standard testing techniques and estimating the accuracy of the predictions, the models can be used to calculate the missing variables that could not be measured using complex diagnostics for all the remaining shots. This has the potential of lessening the load on the data stream requirements in existing machines, as well as providing full repetition rate information for even the most complex of the diagnostics at the new generation of XFELs.

A. Experimental setup
Experiments were conducted at the LCLS 1 x-ray freeelectron laser operated in the twin bunch mode 27 at the Atomic, Molecular and Optical Science (AMO) 28 endstation in February (Expt. 1) and April (Expt. 2) of 2015. The experimental setup is depicted in Figure 1.
Two electron bunches were generated at 120 Hz at the photo-injector and accelerated in three different accelerator sections (L1,L2,L3), interleaved with two magnetic chicanes used as bunch compressors (BC), to energies near 3500 MeV and separated by 50 MeV 1,5 . The resulting x-ray photon energies generated at the undulator were near the oxygen edge (540 eV) and separated by 15 eV. A double slotted foil (DSF) was used in the second chicane (BC2) to partially spoil each of the two electron bunches in time, limiting the emittance to a few femtoseconds duration 29,30 . By modifying bunch compression settings and the position of the DSF, it was possible to change the delay while maintaining the central photon energy of each of the pulses. We choose to demonstrate our technique in this mode of operation due to its versatility for ultrafast experiments, allowing two color, few-fs pulses, with an adjustable delay that can take any value from -100 fs and 100 fs, including zero-delay. The typical energies obtained for each pulse were spread over the range 0 to 30 µJ for the double pulse mode, and 15 to 45 µJ in the single pulse mode. All the data presented in this paper was taken at a fixed position of the foil and compression settings, with the different values for the time delay arising from fluctuations in the machine. In order to provide a larger range of photon energies, the final electron bunch energy was continuously scanned us-  ing the vernier.
An optical x-ray spectrometer (Expt. 1) and an electron TOF x-ray spectrometer 31 (Expt. 2) were used to measure single-shot spectra, each operating at 120 Hz.
The optical x-ray spectrometer was calibrated using the absorption of a mylar filter 32 at the oxygen K-edge and at the corresponding π * resonance. The TOF x-ray spectrometer was calibrated using CO Auger electron emission at the oxygen K-edge and neon 2s and 2p photoelectrons at different photon energies. Under the applied experimental conditions, we found the signal-to-noise ratio of the optical spectrometer to be up to 16 times better than that of the TOF spectrometer, however, the average x-ray power in the double pulse mode during Expt. 2 was about three times larger, providing more signal.
An x-band transverse deflecting-mode cavity (XTCAV) was used to measure the single-shot spectrogram image of the electron bunches (time-energy distribution) downstream from the undulator at 60 Hz. By comparing images in the lasing and non-lasing cases one can determine the lasing region for each of the bunches and measure the distance along the time axis to obtain the pump-probe delay values [33][34][35] (Fig. 5a-b).
Four gas detectors based on N 2 fluorescence 36 were used to measure the single-shot total x-ray energy, recording 6 variables in total. Hundreds of different electron beam parameters were measured on each shot, however, only 16 of them were recorded at the full repetition rate. These included position monitors 37 (position and angle), bunch charge monitors, and peak current monitors at different stages (accelerators, chicanes, undulators) as is indicated in Figure 1. All these diagnostics consist of fast, non-intrusive detectors, and should be therefore scalable to the MHz regime.
Additionally nearly 300 "slow" variables were recorded at 2 Hz by the Experimental Physics and Industrial Control System (EPICS) 38 . These variables mainly include temperatures of different sections or devices, pressures in the chambers, configuration values such as voltages or field strengths, and the settings of the many slow feedback loops that keep the FEL stable. The purpose of these variables was to monitor long term drifts, which can be useful to understand how the fluctuations evolve over time. More details about the variables included in the analysis can be found in Appendix 1.

B. Computational methods
The proposed technique for the prediction of x-ray pulse characteristics at higher repetition rate than measured is summarized in Figure 2. It relies on a fast, highrepetition-rate data stream containing single-shot information of simple diagnostics for all the events, with information from complex diagnostics obtained at a lower repetition rate and only for a fraction of the events. The set of events containing correlated information from all devices can be split in three: the training, validation, and test sets. The training set is used to train a machine learning model to learn how to predict variables normally obtained with complex diagnostics, based on input variables from simple diagnostics. The validation set is used to optimize the hyperparameters. In this context, a hyperparameter is any parameter of the model that is no optimized by the training process. Examples of hyperparameters are the maximum degree of a polynomial model, or the number of hidden layers in a NN. This optimization is done by training many different versions of the same model using different sets of hyperparameters, and then comparing the error on the validation set to decide which set of hyperparameters works best. Finally, the test set is used to test the prediction accuracy of the model for the chosen set of hyperparameters. At this point, the model can be applied to predict, with a known accuracy, the expected values from complex diagnostics for all the remaining events, which originally did not have that information.
We tested this approach using data from LCLS acquired at 60 Hz. It was implemented in python using the LCLS software package psana 39 at the LCLS servers, and locally on standard consumer computers. The Scikitlearn 40 framework was used for feature scaling, feature selection, Principal Component Analysis (PCA) 41 and fitting of linear, polynomial and SVR (Gaussian kernel) models. Tensorflow 42 was used for the implementation of NNs.
More than 300 variables including signals from gas detectors, electron beam diagnostics, EPICS variables and a timestamp, were used as input variables or, in the common terminology of machine learning, features for the prediction. More details about some of the particular variables included can be found in Appendix 1. The time delay, obtained from XTCAV, and the photon energy and spectral shape (~350 spectral components), measured with the spectrometers, were used as the output variables of the models. More details about each of these output variables can be found in the corresponding subsections for each of the prediction examples. As part of the feature selection process constant features were eliminated, as well as features taking a small number (<10) of sparse discrete values. This normally reduced the total number of features to around 90. We then gradually reduced the number of features included, keeping only the ones showing a high correlation with the variable to be predicted, setting the threshold by minimizing the error of the validation set. Around 40 features were normally kept as a result of this process.
A typical dataset consisted of about 3·10 4 shots. A filter was applied to remove all the shots where the total energy was below 5 µJ (<10% of all shots depending on the dataset). Shots presenting outliers in the outputs were also removed to avoid training on events where the results obtained from the complex diagnostics were potentially unreliable. We considered as outliers all the values separated from the median of the distribution by more than four times the median absolute deviation. This filtering process removed only a small fraction of the data (<1%), except in the spectral prediction case, where the noise due to single photon spikes in the optical spectrometer raised this value to 20%. Each dataset was then divided randomly into 3 subsets using a common split for our dataset size, with 70% of the data used for training, 15% for validation and 15% for testing. The test set was kept isolated from the rest during the training and optimization of the models.
Each of the features was normalized by subtracting the mean value and dividing on the standard deviation. This was also applied in some cases to the outputs, although we found the latter to only be relevant for the NNs. We did not find it necessary to use PCA on the features, as the total number of features feeded into the models was low (~40) for machine learning standards. On the other hand, we applied PCA to the output variables of the spectral shape prediction to reduce the number of predicted variables required for the prediction of a spectrum, while TABLE I. Summary of the mean error or agreement of the different prediction examples tested using the different models. The first column shows the mean error of the initial distribution. In the case of the shape agreement, this value corresponds to the mean agreement between each of the single-shot spectra and the mean spectrum. The values for each of the models correspond to the predictions on the test set, while the numbers in brackets correspond to the training set. minimizing the effects of the noise in the training with the measured spectra. We found the best results by keeping only the first 20 principal components out of the 350 spectral components measured by the spectrometer.
We used multiple models to predict each of the output variables from the scaled features, and evaluated them using the mean error, calculated as the mean distance of each predicted value to the measured value. The training was performed to minimize the mean error on the training set. The hyperparameters of each model were modified to minimize the mean error on the validation set. Finally, the accuracy of each model was quoted as the mean error obtained on the test set. In the case of the spectral shape prediction, we define our accuracy by calculating the agreement between the vectors representing the measured, V m , and the predicted, V p , spectra using the similarity function defined as: Polynomial models were fit to the data using simple regression. Due to the large number of features, it was not possible to use higher order models than quadratic, as the number of artificial features created by combining all of the input features up to the required degree scales as the number of k-multicombinations of n elements, where k is the polynomial order, and n the number of input features. In fact, the number of parameters to fit in the model can become comparable or larger than the size of the training data. In practice this limits the nonlinearities that can be represented, as the order is the only hyperparameter available to increase the complexity of polynomial models.
The optimal hyperparameters for the SVR models (C, epsilon, gamma) and the NN (number of hidden layers, number of cells per layer) were found in each case by applying a grid search. Each NN presented up to 3 hidden layers, with between 20 and 100 hidden cells per layer. A rectified linear activation function was used for the hidden cells. The NNs were trained until convergence using the Adagrad 43 algorithm with a batch size of 1000 samples per training step. The final hyperparameters were chosen to minimize the error of the validation set, while not overfitting the training set, to make sure the model was kept as simple as possible. K-neighbors and Decision Tree Regressor models were also used, but in general achieved worse results for all the examples.
The same technique should be applicable to make predictions for every shot in new XFEL machines working at MHz, as the training, validation, and testing steps can still be performed at a low repetition rate (below 1 kHz). Nevertheless the accuracy of the predictions in this case may be different from the values shown here, as the hidden correlations exploited by the machine learning models may change in the new XFELs.

III. RESULTS AND DISCUSSION
We applied our technique to predict the photon energy, the spectral shape, and the pump-probe delay of x-ray pulses, which are the critical parameters in x-ray spectroscopy and time-resolved studies. These characteristics are predicted for both single pulse and double pulse configurations. For each of the predictions we optimized four different models: a linear model, a quadratic model, a support vector regressor, and a neural network. The results are summarized in Table I.

A. Single pulse photon energy prediction
For the calculation of the photon energy, we used the position of a Gaussian fit in our calibrated optical spectrometer as the variable to be predicted. Two examples of the experimental data with their corresponding Gaus- sian fits are shown in Figure 3a. The nominal electron beam energy was continuously scanned over a full range of 60 MeV (triangular periodic scan, 1 minute period, over 10 periods) to provide a wider range of photon energies for the predictions. The effect of this scan, combined with the inherent jitter, resulted in a distribution of photon energies spanning a FWHM of approximately 18 eV, corresponding to a mean error of 5.6 eV (Figure 3b).
The results show that all 4 models are able to predict the photon energy of the test set with a mean error of near 0.3 eV when compared to the actual measured values (Table I and Figure 3c), reducing the error of the initial distribution by a factor of 20. While the error of the initial distribution was artificially enhanced by the electron energy scan, it is worth noting that the model is able to automatically pick up on its own and make use of the correlations between the variables due to the scan. Additionally, as the mean error due purely to the inherent jitter is near 1 eV, we still expect an improvement factor of near 3-4 in cases where the nominal electron energy is kept fixed.
These accurate predictions are not surprising due to the well known quadratic relationship between the electron beam energy and the photon energy given by the XFEL resonance condition. For small variations in energy (60 MeV change at 3500 MeV in our case), this leads to the linear approximation: where E 0,ph and E 0,e are the central photon and electron beam energies respectively, and ∆E = E − E 0 , where E is the single-shot energy. In this way, the electron beam energy, measured non-invasively at the LCLS by an electron beam position monitor in the final dispersive section, can be used to sort data as a function of photon energy. On the other hand we observed that, if we train our models using the electron beam energy as the only feature, then the mean error achieved is still as high as 0.7 eV, and in fact it is necessary to include at least 20 features to achieve an error rounding to 0.30 eV. This suggests that, even in a simple case like this one, useful information about the photon energy is contained not just in the main feature, but it is also encoded in other variables. Nevertheless, most of the correlations relevant to predict the photon energy seem to be essentially linear. As a consequence, the quadratic and the SVR models tend to overfit the data, showing a larger error for the test set than for the train set (Table I). Similarly the best performance of the NN was obtained including only two hidden layers, with 10 and 5 hidden cells respectively, greatly limiting the degree of nonlinearities that the NN can model. While the degree of overfitting was not problematic for our purposes, regularization 24 or dropout 44 techniques could be applied to avoid it if necessary.

B. Single pulse spectral shape prediction
In this case, instead of predicting the photon energy as a feature obtained from fitting the spectrum, we built models to directly predict the spectral shape by predicting multiple spectral components. The histogram of agreements between the measured and predicted spectra for the test set are shown in Figure 4a. As this problem is much more non-linear than the previous case, the linear model only achieves a mean agreement of 88%, while the other three models achieve mean agreements above 94% (Table I).
In particular the chosen NN, consisting of three hidden layers with 50, 50 and 20 hidden cells respectively, allows the network to find and model the non-linearities required for the prediction with a mean agreement of 97%. In fact, 86% of the shots in the test set show an agreement higher than 96%. Figures 4b-e show examples of predicted compared to measured spectra for increasing agreements from 96% to 99%. Even the example with the lowest agreement shows a good match, including more details of the spectral shape that can be achieved with a Gaussian or Lorentzian fit.
It is worth noting that due to the non-linearity of the problem, none of the models seem to overfit, making this a possible symptom of a high-bias situation, meaning that given more training, more features, or more complex models, even better results could be achieved.
Apart from potentially solving the repetition rate problem, this technique could also be of interest in absorption experiments, where the spectrum after absorption through a sample has to be measured and compared to the reference spectrum. Normally the reference spectrum is measured before inserting the sample and averaged for many shots, or even averaged for shots sorted in different bins as a function of one or two of the features 19 . However, this approach cannot be used to bin with respect to more than two variables, as then the number of samples per bin would become too small. Instead a model could be trained to learn how to predict the reference spectrum based on training reference data obtained without an absorption sample, and then used to predict the incoming spectrum for each single-shot measurement with the sample, allowing the calculation of single-shot absorption. This approach could be successful as long as reference data are recorded sufficiently often to account for long term drift in the machine.

C. Double pulse time delay prediction
The delay values between the two x-ray pulses were extracted from electron time-energy distribution images recorded using the XTCAV diagnostic systems. Each image was processed by first separating the two bunches, and then locating the lasing part which appears as a temporally localized loss of electron beam energy and increase of energy spread when compared to non-lasing references [33][34][35] . Figures 5a and 5b show two XTCAV images, where the lasing slices have been highlighted with a red dashed line for the high energy bunch, and an orange dashed line for the low energy bunch. These two figures, obtained from the same dataset, already show two situations with opposite delay values. In fact, the distribution of the delays due to the jitter (Figure 5c) spans a FWHM of 25 fs, yielding a mean error of 6.8 fs.
After training all four models using the delay values from the training set, they were applied to the test set to predict the delay values. We found that all the models are able to predict the delay with a mean error near or below 2 fs (Table I). Considering the mean error of the initial distribution was 7 fs, this already represents an improvement factor of at least 3.5 on the accuracy of the delay.
As the physical processes that determine the final delay are complex, the non-linear models show better results, below 1.7 fs mean error. In particular, a NN with two hidden layers, with 50 and 10 hidden cells, predicts the delay with a mean error below 1.6 fs. From Figure 6, we also observe that it is the neural network that presents the most symmetric deviation from the perfect correlation (dashed line), as opposed to the other models where  there is some asymmetry in the residuals.
Most of the models (except the linear) seem to overfit, showing larger values for the error of the test set, than that of the training set (Table 1.). This could be a symptom of a high-variance situation where the training could benefit from having more training data. In order to determine if this is the case we studied the accuracy of the predictions for the training set and the validation set as a function of the number of samples used for training ( Figure 7). This shows that, except for the linear model, all the other models have not fully converged to a value, so given more training data better results would be obtained, and maybe even more complex models could be fitted. Nevertheless, it is worth noting that all the non-linear models can predict the delay with a mean error smaller than 1.8 fs with only 5000 events which at a repetition rate of 200 kHz could be recorded in only 25 seconds.
While XTCAV is essential to measure some values of the delay, this result shows that it is possible to learn how to create models that calculate the delay from simpler parameters, which can be measured at a higher repetition rate. For an experiment aiming to measure few femtosecond dynamics, requiring XTCAV, this opens the possibility of actually recording data at the full repetition rate, not being limited by the XTCAV maximum repetition rate. This will be critical for the next generation of high-repetition-rate XFELs, but can also be retroactively applied to previous experiments at LCLS, where the XFEL and the data acquisition were working at 120 Hz, but XTCAV data was only recorded at 60 Hz.

D. Double pulse photon energy prediction
Following a similar approach as in section III A, we used the electron TOF spectrometer in the double pulse mode to monitor the photon energy of each of the pulses ( Figure 8a). We scanned the electron energy over a range of 20 MeV, yielding a distribution of photon energies with mean errors of 1.45 eV and 1.03 eV for each of the pulses. In this case, as in the single pulse case, we observe that all four methods show similar results (Table I), with the NN (two hidden layers, with 20 and 5 hidden cells) yielding the smallest mean errors of 0.46 eV and 0.40 eV respectively (Figure 8b and 8c).
Nevertheless the absolute errors are still larger than the 0.3 eV mean error obtained for the single pulse. We believe the main reason for this is the lower signal-tonoise ratio of the TOF spectrometer, that we estimated to be 16 times worse than that for the optical spectrometer under the experimental conditions used. Furthermore the mean total x-ray energy was the same in both cases (~30 µJ), but in the double pulse mode each of the pulses carried only half the energy, providing less signal. As a consequence, the accuracy of the fits is reduced, giving less reliable values for the central photon energy.
Additionally, we attempted to perform the full spectral prediction in this case, but found that while the predicted spectrum matches well the position of the peaks, it does not predict the correct relative intensities between the two pulses. The first reason for that could again be related to the lower efficiency of the TOF spectrometer. Another possible reason is that, regardless of how much we learn about the trajectory of the bunches, the stochastic SASE emission cannot be easily predicted, as it depends on the microscopic structure of the bunch which is not yet possible to measure using existing diagnostics. In the single pulse mode this is not a problem, as the gas detector directly measures the total pulse energy for every single shot, however in a double pulse mode the gas detector cannot tell how much of the energy is in each of the pulses. All these considerations should be taken into account to better design future XFELs, by including simpler/faster diagnostics, placed strategically to have some correlations with the information we plan to predict, even if the correlations are not simple.

IV. CONCLUSION
We have shown that, for current existing data from LCLS, the fluctuations of the electron bunch trajectories measured with fast detectors encode important correlations with many of the required shot-to-shot x-ray properties, such as photon energy, spectral shape or time delay. Many of these properties will not be available on a shot-to-shot basis at high-repetition-rate XFELs. In many cases, the critical properties for an experiment cannot be easily measured for all shots if the design of the experiment does not allow measuring downstream of the interaction region or the diagnostics require unfeasibly high data rate in high repetition operation.
We have presented a technique based on machine learning algorithms that allows many of these key shot-to-shot properties to be obtained, based solely on information from fast detectors recorded upstream of the interaction region, requiring only a small amount of training data that can be recorded for a subset of the shots, or at a lower repetition rate. This may even be used to automatically obtain shot-to-shot reference spectra for absorption measurements. In a more general application, the same method could also be applied to fill data gaps due to synchronization failures through the recording of a dataset, or even to perform online filtering of the events before the storage, which will be challenging at the MHz rates.
As test cases, we have successfully applied the proposed method for prediction of the photon energy (mean error <0.3 eV at 540 eV), the spectral shape (mean agreement >97%), and the x-ray pulse delay (mean error <1.6 fs) in a twin bunch mode, using four different machine learning models. We present the results from different models not to show a deep comparison of all 4 models, but rather to prove that when the necessary correlations exist, many machine learning models can exploit them, and even non-expert users should be able to apply the technique using the simpler and easier-to-train models.
We believe that putting together XFEL science with machine learning opens new opportunities, particularly for ultrafast time-resolved experiments, at new highrepetition-rate XFEL facilities, but also offers a new route to reanalyze data from past experiments, including experiments involving XTCAV or absorption experiments. Now that many aspects of the next generation of XFELs are being defined, this work provides evidence that the design of the new machines should not dismiss useful and difficult-to-replace complex diagnostics that cannot work at the full repetition rate, but should instead store as much full-repetition-rate single-shot information as possible and use the complex, low-repetition-rate diagnostics to complement them.