Beam dynamics of realistic bunches at the injector section of the European X-ray Free-Electron Laser

We consider a 3D electron bunch at the cathode, modelled via photoemission, with realistic (asymmetric) spatial and temporal distributions for accelerator beam dynamics studies at the European X-ray Free-Electron Laser (European XFEL). A series of measurements are performed for low energy beams in the European XFEL injector. Using modeled 3D electron bunches, beam dynamics simulations, enabled by a three-dimensional (3D) space-charge solver with valid image-charge calculation on the photocathode plane, have shown improved agreements on measured beam properties (e.g., charge, bunch length, and shape) over a large range of variable machine parameters (e.g., cathode drive laser pulse energy, rf gun phase) for injector operation. In addition, the beam dynamics close to the cathode in a strongly space-charge dominated regime is studied in the rf gun. In light of the choice of a suitable machine working point along a so-called emission curve, the impact of the space-charge effect on the longitudinal length and shape of the produced electron bunch is analyzed in comparison to the measurements downstream the injector exit.


I. INTRODUCTION
Electron bunches with a small emittance, small energy spread, and high peak current are essentially required by short-wavelength self-amplified spontaneous emission (SASE) free-electron lasers to generate high-brilliance photon pulses [1]. To obtain such electron bunches at the European XFEL [2], a high-gradient photoemissionbased radio-frequency (rf) gun [3] and complex systems of rf driven superconducting linear accelerators are used in conjunction with a multistage scheme of bunch compression [4,5]. A large space of machine parameters therefore exists, in which a series of critical parameters need to be optimized, experimentally, for best achievable beam qualities. Such an optimization process needs as detailed as possible guidance from beam dynamics simulations. Its capability and efficiency thus rely highly on the physical as well as numerical modeling approaches incorporated in the simulations.
At the European XFEL, beam dynamics studies have been carried out at the design stage [2,6] as well as during commissioning periods of the facility [7,8]. In [2,6], design of the magnetic lattice layout and the rf module specifications are explicated. In [9], a periodic Poisson model for beam dynamics simulations is developed and applied for the simulation of laser modulated beams. Another efficient model proposed for low energy beam dynamics in nine-cell 1.3 GHz cavities is described in [10]. A procedure is found in [4] for analytically choosing machine working points in the parameter space of the longitudinal beam dynamics. Detailed simulations of beam dynamics are performed in [11][12][13] for various bunch charges and accordingly the expected properties of the radiation are estimated. These works provide useful theoretical guidance for setting up the accelerators and tuning electron beam parameters for the lasing. However, it is still very challenging, under direct experimental conditions, to reproduce the measured beam properties and the change tendencies of these properties as a function of variable machine parameters. Particularly in the injector, low energy beams (i.e., ≤130 MeV at the European XFEL) are fragile and sensitive to the change of experimental conditions and machine uncertainties. Discrepancies of beam property parameters in the injector are already observed between measurement and simulation (e.g., in [3,14]).
The issue can be multifaceted. First, in conventional simulations, an electron bunch generated at the cathode is assumed to have the same transverse and longitudinal distributions as those of the cathode drive laser pulse. Consequently, the contribution from the cathode quantumefficiency (QE) distribution to the transverse spot size of the produced electron bunch is missing. This is due to the fact that the transverse electron bunch distribution (and therefore its size) is determined by the convolution of transverse distributions of the cathode QE and its drive laser via photoemission [15]. This means, an inhomogeneous map of the cathode QE can change the actual spot size of the produced bunch compared to the assumed bunch size which is the same as that of the drive laser pulse. For simulations, this may cause already inconsistencies in the intrinsic bunch size on the cathode plane and alter the obtained results from downstream beam dynamics. Particularly, the effect can be significant for user facilities, where routine cathode exchange is usually conducted on a long timescale (e.g., several years for Cs 2 Te cathodes) in consideration of not interrupting the user operation. Thus, a significant degradation in the cathode QE and its homogeneity over the illumination area of the drive laser pulse are expected.
Yet another missing term in previous simulations is the modeling of fine features imprinted in the electron bunch produced in the photogun. This refers, for instance, to the shape of the temporal profile (e.g., nonideal Gaussian, flattop or those with locally irregular curvatures). This effect is often correlated to the pulse length and shape of the cathode drive laser, and meanwhile, can be strongly influenced by local space-charge densities in the cathode vicinity. A careful treatment of these features is useful for resolving the details in the longitudinal beam dynamics downstream the beam line.
Last but not least, phase determination of the rf gun with respect to the incoming cathode drive laser pulse is crucial to the beam dynamics in the injector. A phase change corresponds to the change of the rf field gradient applied on the cathode. This affects properties of the produced photoelectron bunch via different mechanisms (e.g., Schottkylike effect [16], space-charge effects in the cathode region [17]). To fairly compare measurement with simulation, the rf phase needs to be carefully determined with respect to the rf field zero-crossing in the experiment, and the measured phase configuration should be used in the simulation accordingly.
In order to take into accounts missing modeling terms above-mentioned so as to reduce observed discrepancies between measurement and simulation, we propose a threedimensional (3D) beam dynamics modeling and simulation approach. The approach generates realistic 3D (x, y and t) electron bunches produced at the cathode via photoemission according to the measured cathode QE map, and the measured transverse and temporal distributions of the cathode drive laser pulse. To be able to consider such a 3D electron bunch in the simulation, including spacecharge and image-charge effects, a 3D solver, which is valid already from the cathode plane, is further developed (see Sec. II). Note also, that more realistic machine parameters (or distributions), given as inputs to the simulation (e.g., cathode QE map, 3D cathode drive laser distributions and pulse energy, rf phases, etc.), are determined through characteristic measurements in this study. This is instead of using assumptions, typically made in previous simulations for simplicity, which are principally true only when the machine is operated under ideal conditions. The paper is organized as follows. The 3D space-charge solver is briefly described in Sec. II. In Sec. III, a series of measurements performed in the XFEL injector are presented. The diagnostic measurements for the cathode drive ultraviolet (UV) laser pulses in Sec. III A and the cathode QE map in Sec. III B will be used in Sec. IV for modeling a realistic 3D electron bunch produced at the cathode. The characteristic measurements, including determination of the rf zero-crossing and maximum mean momentum gain (MMMG) phases in Sec. III C, charge-phase scans in Sec. III D, and so-called emission curves in Sec. III E, provide systematical data for multiple comparisons with corresponding simulation results obtained over a large range of machine parameters in the rf gun section. Moreover, the measurement of longitudinal bunch shape and length in Sec. III F allows a further comparison with the simulation results till the injector exit. Then, the modeling method for obtaining such a 3D photoelectron bunch from the electron source is proposed in Sec. IV. Simulation results as well as comparisons with the measurement data are shown in Sec. V. In Sec. VI, space-charge effects in the cathode vicinity and the impacts on the longitudinal bunch shape at the inject exit are discussed. The temporal bunch profile is simulated for different bunch charges and compared with the measurements. A summary and an outlook are given in Sec. VII.

II. 3D SPACE-CHARGE SOLVER
The numerical results presented below are obtained with two codes: ASTRA [18] and KRACK3 [19]. These codes use the same mathematical model and similar numerical algorithms. Code ASTRA does not allow us to study three dimensional effects of asymmetric bunches near the cathode. In the emission process it allows to use only fully rotationally symmetric filed solver (monopole mode) and only later on, when the impact of the cathode is negligible, it is possible to switch to a three dimensional field solver. In KRACK3 we have implemented an algorithm to use a three dimensional field solver already in the emission time. In the following we describe shortly the mathematical model and the numerical algorithms used in KRACK3. The particles are advanced self-consistently using a particle-in-cell approach. The equations of motion in electromagnetic field are solved in laboratory frame using Runge-Kutta algorithms of different orders. The external electromagnetic fields of cavities and magnets are precalculated and tabulated on the axis following approach described in [20]. The self-fields are calculated in the beam frame. We approximate the electromagnetic field by electrostatic one and solve the Poisson equation for potential. Hence the radiation fields are not included in this model. The impact of rf cavity boundaries and the scattered fields (wakefields) are neglected as well. Only cathode is taken into account with the help of image charge (or Green's function of half-space) approach.
In the free space without any boundaries the Green function is translation invariant: G 0 ðx; y; z; x 0 ; y 0 ; z 0 Þ ¼ G 0 ðx − x 0 ; y − y 0 ; z − z 0 Þ. The charge distribution ρ has compact support inside cuboid D ¼ ð0; x 0 Þ × ð0; y 0 Þ × ð0; z 0 Þ and we are looking for the values of the convolution integral on the same cuboid ψðx; y; zÞ ¼ In this equation the Green's function G 0 ðx; y; zÞ is defined In order to take into account the cathode we use the Green's function of half-space with Dirichlet boundary condition at plane z ¼ z c : which is invariant only to the translations in z-plane. Hence Eq. (1) with the Green's function G þ cannot be written as a three dimensional convolution Eq. (2) and we cannot use FFT in all three dimensions (only FFT in the transverse coordinates x and y can be used here). But with change of variable z 0 → z 0 − z 0 we can rewrite the RHS of Eq. (1) as [21] Z D G þ ðx; y; z; x 0 ; y 0 ; z 0 Þρðx 0 ; y 0 ; z 0 Þdx 0 dy 0 dz 0 Each of the integrals in the RHS of Eq. (5) can be considered as a three dimensional convolution on domain D. Hence we can again rewrite each of them as a convolution of periodic functions on the extended domaiñ D and use FFT on a uniform mesh to reduce the number of operation from OðN 2 Þ to OðN log NÞ operations, where N ¼ N x N y N z is the total number of mesh points and N x is the number of the mesh points along x-axis and so on. Numerical discretization of the above equations follows the same route as described in [9].

III. MEASUREMENTS
Measurements are performed in the European XFEL photoinjector [8]. The injector consists of an L-band rf photogun, a TESLA (TeV-Energy Superconducting Linear Accelerator [22]) technology type 1.3 GHz module, a 3rd harmonic rf section, a laser heater and multiple diagnostic sections, as shown in Fig. 1. A detailed description of the injector layout at the European XFEL can be found in Sec. 4.3 of Ref. [2]. More information about the performance and stability of typical beam instrumentation devices can be found in [23][24][25].

A. Diagnostics of cathode drive laser pulse
The Cs 2 Te photocathodes in use at the European XFEL are driven by UV laser pulses at 266 nm from the primary Nd:YVO4 laser system [26]. The transverse spot size of the cathode laser pulse is controlled by a so-called beam shaping aperture (BSA) which cuts the beam profile from a Gaussian to a flat-top beam. The so-called virtual cathodes [27], realized by CCD-cameras which are UV sensitive and mounted exactly in a position corresponding to the photocathode of the gun, are used for relative spot positioning of the laser pulse and the measurement of the transverse laser beam profile. The longitudinal length and profile of the laser beam is measured using either a UV autocorrelator or a streak camera. Figure 2 shows a typically measured transverse distribution of the cathode UV laser pulse. The applied BSA size is 1.0 mm diameter. As shown, both horizontal (cyan curve) and vertical projections (green curve) correspond to nearly flat-top distributions. The measured rms size of the laser beam is 0.25 mm. In Fig. 3, the corresponding laser beam temporal profile obtained from a streak camera measurement is shown. The temporal shape of the measured curve (blue) is similar to a Gaussian fit (dotted green) with slight deviations. The measured pulse length is about 3 ps rms. Note also that the temporal profile measurement is also cross-checked using a UV auto-correlator and the obtained results are consistent between the two measurements.

B. Cathode quantum-efficiency map
A quantum-efficiency (QE) map is measured for an extensively used photocathode. This cathode was in use at the European XFEL until the beginning of 2020 after five years in operation. As a standard measurement at the European XFEL, the quantum-efficiency (QE) map is scanned over the cathode surface using a small spot size of the laser beam (e.g., 100 μm). The emitted charge is then measured with a high resolution toroid [23][24][25]. The pulse energy of the cathode drive laser is typically adjusted to generate a maximum charge of 10 to 30 pC. More details of the cathode QE and the QE map measurements can be found in e.g., [29]. Figure 4 shows the normalized QE intensity over the cathode surface (transverse plane). As shown, the homogeneity of the QE map is significantly degraded. The illumination area of the drive laser pulse over the cathode surface is marked by the white circle. The inset numbers represent relative QE intensities in different local areas within the map, and further show a significant change of the cathode QE within the illumination area. The impact of the cathode QE inhomogeneity onto the size and transverse distribution of the photoelectron bunch is demonstrated in Sec. IV. This cathode in its present status is used for the beam measurements in Sec. V and its measured properties are considered in the simulations via the modeling approach in Sec. IV so as to compare the results with the measurement data.

C. rf phase determination
An rf gun phase which corresponds to the zero field, namely, the zero-crossing phase, is measured. the measurement aims to find a phase which results in a zerocrossing of the extracted bunch charge downstream the gun. This is done through scanning a full range of the rf gun phase (Φ). The cathode laser pulse energy is kept low allowing the extraction of a bunch charge up to a few picocoulombs. Figure 5 shows the measured bunch charge obtained from a beam position monitor (BPM, black curve) and a toroid monitor (green curve). The two curves show consistent results. The determined zero-crossing phase is at 0 degree. The charge errors in both cases, as shown on the right axis of Fig. 5, are lower than 0.1 pC (<1%). Figure 6 shows the horizontal beam position read from a BPM in a dispersive arm of the gun after a dipole magnet. The magnetic spectrometer configuration allows the search of an rf gun phase (horizontal axis) at which the mean momentum gain is maximized (indicated from the vertical axis). As shown, a phase of −47 degrees with respect to the zero-crossing phase in Fig. 5 is found as the MMMG phase of the gun. The same phase configuration is then used in the following simulations.  black curve shows the averaged measurement data from 10 individually measured curves (shading curves). The dotted line marks the MMMG phase of the gun, as determined in Figs. 5 and 6. As described in [30,31], at around 0 degree in Fig. 7, the charge extraction is closely related to the temporal length and shape of the cathode drive laser pulse when the rf field is relatively low. As decreasing the gun phase down to -90 degrees, the charge extraction is further described by two separate regimes, the cathode quantumefficiency-limited and the space-charge-limited regimes [17]. As rf phase rises, the field gradient on the cathode surface is increased leading to an enhanced photoemission due to the Schottky-like effect. However, meanwhile, this process is influenced by the space-charge effect according to the beam dynamics close to the cathode. The resulting tendencies in the charge extraction are thus different in the phase range from −5 degrees to −90 degrees. More specifically, the charge production down to roughly −50 degrees is limited by the space-charge due to relatively weak rf fields applied at the cathode. This results in a sharper rising edge in the charge extraction [17], as sketched by the red line. From −50 degrees to −90 degrees, the rf fields are further increased. The bunched photoelectrons extracted from the cathode are efficiently accelerated. The accelerated electrons leave the cathode region which thus reduces the space-charge density in the cathode vicinity and allows further emission. Over this phase range, the charge extraction is mainly dominated by the Schottky-like effect through the cathode quantum-efficiency and is therefore called by convention, the quantum-efficiency-limited regime. Further decreasing the rf phase from -90 degrees leads to a sharp drop in the charge extraction. This is partially due to a strong phase slippage in the gun which results in significant charge loss during the beam transport. The dynamics can also be strongly affected by, for instance, secondary electron emission. Note that a maximum extracted charge of about 330 pC corresponding to the peak rf field applied at around an rf phase of −90 degrees. A nominal machine operation is typically at the MMMG phase of the gun where a bunch charge of about 250 pC is extracted. Note in addition, that the dynamics for the rf phases far away from the MMMG phase (i.e., <−90 degrees) is beyond the discussions in this paper and will not be further elucidated.

E. Emission curve
Another important measurement, the extracted bunch charge versus the cathode laser pulse energy, namely, emission curve, is shown in Fig. 8. As the cathode laser pulse energy increases, the measured curve (cross-markers) is bent by space-charge effects, resulting in a transition from the linear quantum-efficiency-limited regime to the nonlinear space-charge-limited regime. A 250 pC bunch charge as required for a nominal operation at the European XFEL is typically reached in the transition of the two regimes.

F. Bunch shape and length
The length and shape of a 250 pC electron bunch is measured downstream the gun at the exit of the injector section. This is done by using a transverse deflecting structure (TDS) downstream the gun, as shown in Fig. 1. For these measurements, all rf components upstream the TDS (Gun, A1 and AH1) are set on-crest. Figure 9 shows that the peak current of the bunch is about 20 A. The resulting bunch shape (black curve) is Gaussian-like with locally irregular curvatures. The length of the bunch is about 4.7 ps rms with a longitudinal resolution of roughly 0.3 ps. Compared to the intrinsic pulse length of 3 ps rms of the cathode drive laser pulse, the electron bunch length is much longer. The lengthening effect is caused by the spacecharge effect of low-energy beams in the rf gun. The local curvature observed in the bunch profile most likely originates from the high space-charge density of the produced electron bunch in the cathode region. A more detailed analysis will be presented in Sec. VI.

IV. 3D MODELING OF BUNCHED PHOTOELECTRONS
Based on measured distributions of the cathode QE map (transverse distribution in Fig. 4) and the cathode drive laser pulse (transverse and longitudinal distributions in Figs. 2 and 3, respectively), a three-dimensional photoelectron bunch produced at the cathode is modelled via photoemission [15]. This is realized by considering the transverse profile of bunched photoelectrons as a convolution of measured transverse distributions of the cathode QE map and its drive laser pulse within the emission time defined by the temporal profile of the drive laser. Figure 10 exemplarily illustrates such a 3D electron bunch where the convoluted transverse distribution (x-y plane) is shown in Fig. 11 and the longitudinal distribution (t-y plane of Fig. 10) follows the measured temporal profile, as presented in Fig. 3.
More specifically, an ideal electron bunch with transversely a uniform distribution (x, y) and longitudinally (z or t) a standard Gaussian profile is initially generated. For simplicity, the transverse (p x , p y ) and longitudinal (p z ) distributions in the momentum space of the bunch are assumed to be radially uniform and isotropic, respectively. Along with emission time (t) and macro-charge (q), a space of parameters, fx; y; z; p x ; p y ; p z ; t; qg is used for describing a simulation particle. Given sufficient number of simulation particles (e.g., 1 million for 250 pC), collective effects for an electron bunch can be well described. Then, the photoelectrons within the initial bunch distribution are discretized to N slices in the longitudinal direction. This follows the temporal profile of the cathode drive laser pulse obtained from diagnostic measurements. Given a measured total laser pulse energy (E las ) on the cathode, the produced charge per slice is then calculated as dQðx; y; tÞ ¼ e · QEðx; yÞ · dE las ðx; y; tÞ ℏω dxdydt ð6Þ with QEðx; yÞ ¼ α f1 þ E a =½ℏω − Φ eff ðx; y; tÞg 2 ; ð7Þ and Φ eff ðx; y; tÞ ¼ Φ 0 þ e ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi e · E surf ðx; y; t; z ¼ 0Þ=4πε 0 p : The form factor α is defined as η=ð1 þ pÞ with p described in [32,33] as the ratio between the penetration depth of the laser beam and the average distance traveled by the electrons between two successive collision events, and η as a coefficient in proportion to the reflectivity of the cathode which depends on the drive laser wavelength. The symbol E a is denoted as the electron affinity of the cathode. The term Φ 0 stands for the intrinsic cathode work function (e.g., 3.5 eV for Cs 2 Te) and the term Φ eff represents a corrected cathode work function accounting the Schottky potential for describing the probability of electron escape from the cathode surface by overcoming the surface barrier potentials. The terms E surf stands for the spatial (x=y) and temporal (t) dependent full fields at the cathode position (z ¼ 0). For simplification only rf cavity fields are considered here. The term dE las represents the drive laser pulse energy per slice. The symbols e, ε 0 , dx, dy, and dt denote electron charge, vacuum permittivity, the spatial and temporal dependencies of the charge production, respectively. The term ℏω stands for the photon energy (e.g., ∼4.8 eV for Cs 2 Te at λ ¼ 266 nm). A more detailed description for the cathode QE modeling can be found in [34]. As shown in Figs. 10 and 11, a transverse emission composition map is made according to the convolution of the measured QE map and the measured transverse distribution of the cathode drive laser pulse within the emission time defined by the temporal profile of the drive laser pulse. Based on Eqs. (6)-(8), the transverse distribution of each produced longitudinal slice of the bunch is corrected. A simultaneous correction of spatial and temporal distributions of the produced electron bunch is thus realized. It should be noted, that the rms size of the transverse emission composition map (Fig. 11) is significantly reduced by roughly 17% compared to the spot size of the cathode drive laser pulse alone (Fig. 2) for a BSA size of 1.0 mm diameter. This is, again, due to the significant inhomogeneity observed in the QE map of the degraded cathode (Fig. 4). To resolve downstream beam dynamics, an accurate determination of the electron bunch size produced at the photocathode by means of the proposed approach is thus of necessity.

V. SIMULATIONS AND COMPARISONS WITH MEASUREMENTS
Beam dynamics simulations using the 3D space-charge solver developed in Sec. II are performed for the European XFEL injector. The 3D modeling approach of the photoelectron bunch is applied. The measured machine parameters (or distributions), as presented in Sec. III are then used accordingly in the following simulations. Key simulation parameters are summarized in Table I. In addition that the electron beam momentum after the gun is close to 6.6 MeV=c, and that the 1.3 GHz cryo module A1 and the 3.9 GHz cryo module AH1, as seen in Fig. 1, are set oncrest for delivering a 130 MeV beam energy at the exit of the injector. It can be noted, that the simulation parameters as specified in Table I are set very close to typical operational parameters of the injector for the European XFEL. This set of parameters is applied, for example, to investigate the emission curves as in Figs. 12-14 and to study the bunch length and shapes as in Figs. [16][17][18][19]. Note also that the quantum efficiency of the used cathode is about 4% which is set the same between simulation and measurement, however, this is lower than that in a typical operation with a fresh cathode where the cathode QE is usually above 10% and its homogeneity over the laser illumination area is typically better. Figure 12 shows a comparison of the measured emission curve (bunch charge versus cathode laser pulse energy) with different numerical approaches. Note that, for comparison purpose, the simulations presented in this figure all use an ideal electron bunch produced at the photocathode. That is, no modeling approach shown in Sec. IV is applied yet. Thus, the transverse bunch distribution is uniform. The rms size of such a bunch is transversely 0.25 mm (i.e., same as the spot size of the drive laser) and longitudinally the length of its ideal Gaussian profile is 3 ps rms. As shown in Fig. 12, two numerical approaches are included for the comparison: KRACK3 3D and ASTRA 2D-transition-3D. The KRACK3 3D approach corresponds to the 3D solver developed in Sec. II. The ASTRA 2D-transition-3D approach stands for a transition of space-charge calculation from the cylindrical symmetric (2D) algorithm to the 3D algorithm in [18]. The image-charge is included at the cathode for the 2D algorithm while the 3D solver in ASTRA does not consider the image-charge at the cathode. It should be noted, that we have also performed simulations with purely the 2D algorithm in  ASTRA. It turns out the 2D approach agrees well with the ASTRA 2D-transition-3D approach when the longitudinal transition position of the two algorithms is properly set. However, switching to the 3D algorithm in ASTRA at an appropriate position allows us to consider a 3D distribution of the bunch for downstream beam dynamics. Thus, the ASTRA 2D-transition-3D approach is shown here instead of the 2D approach. Note also in our case, that the algorithm transition takes place at a longitudinal bunch position (z) of 10 cm. The chosen transition position ensures the imagecharge no longer plays a role for the charge extraction at the cathode (z ¼ 0). This is also cross-checked by performing simulations up to different longitudinal transition positions. The obtained results in Fig. 12 suggest two points. First, when using an ideally round transverse bunch distribution at the cathode for simulations, the simulated bunch charge using different numerical approaches are significantly higher than the measured bunch charge at higher laser pulse energies (>25 nJ, i.e., in the space-charge-limited regime of the measured curve as shown in Fig. 8). The deviation between the KRACK3 3D simulation and the measurement is about 30% (shown on the right axis). Second, the simulated charge using KRACK3 3D is consistent with that obtained from the ASTRA simulation. Remaining deviations between the two numerical approaches are rather small and nearly negligible. Note in addition, that the simulation results presented here are based on systematical convergence studies for both KRACK3 and ASTRA. This was conducted by a number of extensive simulations taking into accounts a set of key numerical parameters. As an example, the convergence study is presented for the extracted bunch charge at 50 nJ, as shown in Fig. 12. This data point is chosen due to the fact that the highest space-charge density is expected among all the cases in Fig. 12, and hence, that a most challenging case it is concerning the resolution of numerical simulations. Tables II and III exemplarily show the numerical convergence studies considering two crucial numerical parameters, number of macroparticles (NoP) and longitudinal mesh resolution (dξ), respectively. These two numerical parameters are varied in a range of [50000 2000000] and ½100; 0.0125 μm, respectively. A corresponding illustration is given in Fig. 13 with more data points included. Note that the simulation of the emission process is intrinsically refined in a dynamic way by different numerical algorithms incorporated in KRACK3 and ASTRA. The mesh resolution we refer to in Table III is by estimation over the whole emission process. As shown in Fig. 13, the extracted bunch charges in KRACK3 and ASTRA are both converged. The relative changes in the extracted bunch charges between the two simulations with the highest achievable resolution are well below 0.1%. The difference of the converged bunch charges between the two numerical approaches is small. The highest numerical resolution found from the convergence study is then applied to all the simulations as shown in Figs. 12 and 14. Figure 14 shows the comparison of the extracted bunch charge between the measurement and the same numerical approaches as in Fig. 12. However, instead of using an ideal electron bunch at the cathode, a 3D electron bunch with  Fig. 13. b extracted bunch charge from KRACK3 simulations. c extracted bunch charge from ASTRA simulations.  Fig. 13. Table II (left) and Table III (right). FIG. 14. Comparisons of a measured emission curve with different numerical approaches using an asymmetric electron bunch produced at cathode according to Sec. IV. asymmetric transverse and longitudinal distributions modelled in Sec. IV is used for all these simulations. In this case, the resulting rms spot size of the 3D electron bunch at the cathode is about 0.207 mm when the cathode drive laser spot size is 0.25 mm rms. This is due to the degradation in the homogeneity of the cathode QE map, as shown in Fig. 4. The longitudinal bunch length is 3 ps rms and the temporal shape is the same as the measured one presented in Fig. 3.

FIG. 13. Illustration of convergence studies summarized in
As shown in Fig. 14, all simulated bunch charges are significantly reduced and the resulting simulated curves move much closer to the measured one compared to the case in Fig. 12. This is due to the reduced spot size of the electron bunch at the cathode. For a fixed cathode laser pulse energy, the space-charge density is higher for a smaller spot size on the cathode plane. The resulting stronger space-charge force partially limits the emission and lowers the extracted bunch charge from the cathode. The difference between KRACK3 3D and ASTRA 2D-transition-3D is relatively small. This means, in this case, that the ASTRA 2D-transition-3D approach can still be a good approximation as it is compared to the 3D solver, even though the bunch distribution is not symmetric at the cathode. More importantly, the simulation result obtained from KRACK3 3D shows an improved agreement with the measurement data with a remaining deviation from 30% in Fig. 12 down to 5% (dotted black curve on the right axis in Fig. 14). This improvement is owing to the modeling of realistic bunches as presented in Sec. IV. Figure 15 shows the comparison of the extracted bunch charge over a large rf gun phase range (approx. 90 degrees) between measurement and simulation. The nominal rf gun phase for the XFEL operation is set at the MMMG phase of the gun (i.e., around −45 degrees in this case). The simulation results (red markers) show a fairly good agreement with the measurement (black curve) in a phase range from about −50 to þ40 degrees with respect to the MMMG phase. The beam dynamics in the low-charge region (i.e., Φ > −5 degrees) under low rf field conditions usually requires additional modeling approach and interested readers are referred to [35,30] for more details.
Furthermore, Fig. 16 shows the measured bunch length (black markers) at the exit of the injector and the comparisons with the simulated bunch length using KRACK3 3D (red markers) for different bunch charges. The 3D realistic bunches modeled in Sec. IV are used for these simulations. The rf gun, the 1.3 GHz cryo module (A1) and the 3.9 GHz cryo module (AH1) are operated on-crest. A downstream transverse deflecting structure (TDS, as shown in Fig. 1) is used for the bunch length measurements. The beam energy by the end of the injector is about 130 MeV. Identical rf parameters are applied correspondingly in the simulations. Note also that the cathode laser pulse has a temporal Gaussian shape with a pulse length of 3 ps rms (horizontal dashed line). As shown, due to stronger longitudinal spacecharge forces at higher bunch charges in the gun, the measured bunch length is significantly increased as the extracted bunch charge rises. This behavior is consistent between measurement and simulation. For a low bunch charge of 50 pC, the space-charge lengthening effect is relatively weak. The simulated bunch length is about 3 ps rms. This is comparable with the pulse length of the cathode drive laser and also very close to the measured bunch length. However, the bunch is lengthened already at 100 pC in the simulation due to the space-charge effect while in the corresponding measurement the bunch has not yet shown a prominent lengthening effect at the same charge. As the bunch charge increases, the agreement between measurement and simulation becomes much better.
Moreover, the measured temporal bunch shape is compared with the KRACK3 simulation for a nominal bunch of 250 pC at the exit of the injector, as shown in Fig. 17. The measured (black curve) and simulated (red curve) bunch shapes are both Gaussian-like. Deviating from a standard Gaussian distribution, the measured bunch shape shows steeper rising and falling edges. This behavior is consistent with what is obtained from the simulation. The measured bunch length is about 4.7 ps rms with a longitudinal resolution of 0.3 ps and the simulated one is about 5 ps rms. Toward the bunch tail (t > 0) at around 7 ps, a substructure appears in the measured profile. The beam current after the structure drops in a changed rate toward the bunch tail. In the corresponding simulation, a similar behavior is also observed. This is very likely related to the space-charge effect in the rf gun section which will be further discussed in Sec. VI. However, some deviation remains in the head part of the bunch between t ¼ 0 ps and −6 ps.

VI. SPACE-CHARGE EFFECTS IN THE CATHODE VICINITY
In the cathode vicinity of an rf gun, the extracted photoelectrons experience strong space-charge forces in all dimensions. Before the relativistic velocity factor β approaches 1 by strong rf acceleration within a short distance from the cathode, the space-charge effects significantly influences the shape and length of the electron bunch. This is, particularly, the case for high local spacecharge densities at the photocathode.
It should be noted, that the worn cathode which was in operation at the European XFEL until the beginning of 2020 has been exchanged for a fresh one due to the degradation of its QE map. The worn cathode has been considered for discussing the contents of this paper in Secs. III-V. In this section, a fresh Cs 2 Te cathode with a measured QE of about 17% and a homogeneous QE map is considered instead. In the following, we further demonstrate the space-charge effects near the cathode by comparing measured bunch profiles at the injector exit with the simulated ones for different bunch charges. Figure 18 shows the measured profile of a 250 pC bunch for a BSA set-point of 1.0 mm and the comparison with the corresponding simulation. Due to the use of a fresh cathode, the transverse bunch size almost follows the spot size of the cathode drive laser. According to Sec. IV, this is due to the homogeneous QE map of the fresh cathode as well as the homogeneous drive laser spot. As compared to the bunch size in Fig. 17, this leads to more than 15% larger size and thereby much relaxed space-charge density near the cathode. As a result, the simulated bunch profile (blue curve) by the injector exit reaches an even better agreement with the measured one (black curve) in Fig. 18 as compared to Fig. 17. No irregular structures are seen in these bunch profiles. The shape of the resulting bunch profiles generally follows the profile of the cathode drive laser, except that a broadening effect, introduced by the space-charge, can still be clearly seen.
As further increasing the pulse energy of the cathode drive laser, the charge extraction approaches into the space-charge dominated regime, as shown in Fig. 8. In this regime, strong space-charge forces partially suppress emission at the cathode. The extracted electrons, intrinsically produced by the FIG. 17. Comparison of the longitudinal profile between measurement and KRACK3 simulation for a 250 pC electron bunch at the injector exit. Shading curves represent 5 individual measurements. The black curve stands for the averaged measurement data. Note that the bunch head is in the direction of negative t, and that, the bunch tail is towards the opposite direction where t is positive. The head-tail orientation is the same between measurement and simulation. applied cathode laser pulse energy, piles up in the cathode region. Some of them can escape from the cathode when the local space-charge density drops as more low-velocity electrons that are earlier emitted are further accelerated by strong rf fields and leave the cathode region. This process depends on multiple parameters which can influence the local space-charge density, including the intensity, temporal length, transverse size of the drive laser pulse, strength and phase of the rf gun fields and so on. A significant amount of electrons can fail the process in the space-charge dominated regime. This leads to a prominent charge loss. The temporally bunching shape of survived electrons after emission are thus strongly affected. Irregular curvatures are typically formed up in the tail part of the bunch profile. An example is given in Fig. 19. The measured bunch profile (black curve) is compared to the simulation result (green curve) at about 550 pC. As shown, some substructure is formed toward the bunch tail (t > 0). This behavior is consistent in the simulation. However, the exact measured temporal shape toward the bunch head is still difficult to be resolved in the simulation.
In order to illustrate, particularly during the emission process, the formation of irregular curvatures in the bunch profile, a simple demonstration is provided by the simulation in space-charge dominated regime, as shown in Fig. 20. The simulation settings are the same as in Figs. 18 and 19. The subplots show a normalized charge density in the longitudinal direction at different moments of the emission process. Note that, the sampling points and the vertical bars in the plots are only used for visualization and do not correspond to any mesh resolution of the simulation. As shown, when a mean longitudinal position of the bunch z < 0.7 mm, the maximum local charge density (MLCD) is pinned at the photocathode position (z ¼ 0 mm). This implies that strong longitudinal space-charge forces are suppressing the produced photoelectrons from escaping the cathode. The MLCD slowly moves forward only when the local space-charge density drops. A pronounced curvature starts to be formed up in the bunch tail (z > 0.8 mm) as the MLCD is released from the cathode plane.
To avoid or reduce irregular bunch shapes caused by the space-charge effects in the gun, special attention must be paid to the choice of a suitable machine working point. A good reference is the emission curve, as shown in Fig. 8. Choosing a working point in the quantum-efficiency dominated regime for a required bunch charge can efficiently lower the space-charge contribution to the temporal shape of the bunch. This can be done by adjusting one or multiple machine parameters (e.g., spot size, pulse length and intensity of the cathode drive laser, applied rf field phase and gradient, etc.). Settling a machine working point, on the other hand, in a slightly space-charge affected regime, may reduce the intrinsic surface emittance of the bunch at the cathode without ruining a desirable bunch profile [34]. A case-dependent trade-off should be made.

VII. SUMMARY
A measurement-based modeling approach is proposed to consider a full 3D photoelectron bunch with realistic spatial and temporal distributions produced at the photocathode. A dedicated 3D space-charge solver with valid image-charge calculation starting from the cathode is used. This allows computing 3D beam dynamics with 3D realistic electron bunches in the simulation. A series of characteristic measurements on multiple accelerator parameters are performed in the injector of the European XFEL. Using the proposed approach, corresponding simulations have shown improved agreements with the measurement data over a large range of variable machine parameters. The simulated bunch length and shape at the exit of the injector also show consistent behaviors as in the measured ones. The beam dynamics in the space-charge dominated regime is discussed in consideration of the choice for a suitable accelerator working point. Good agreements of the resulting temporal bunch shapes are reached between measurement and simulation.