Generation of large-bandwidth x-ray free-electron-laser pulses

X-ray free-electron lasers (XFELs) are modern research tools in disciplines such as biology, material science, chemistry, and physics. Besides the standard operation that aims at minimizing the bandwidth of the produced XFEL radiation, there is a strong scientific demand to produce large-bandwidth XFEL pulses for several applications such as nanocrystallography, stimulated Raman spectroscopy, and multiwavelength anomalous diffraction. We present a self-consistent method that maximizes the XFEL pulse bandwidth by systematically maximizing the energy chirp of the electron beam at the undulator entrance. This is achieved by optimizing the compression scheme and the electron distribution at the source in an iterative back-and-forward tracking. Start-to-end numerical simulations show that a relative bandwidth of 3.25% full-width can be achieved for the hard x-ray pulses in the SwissFEL case.


I. INTRODUCTION
X-ray free-electron lasers (XFELs) are cutting-edge scientific instruments in various research fields such as biology, material science, chemistry, and physics. Most XFELs are based on the self-amplified spontaneous emission (SASE) mechanism [1,2]. State-of-the-art SASE-XFELs produce transversely coherent radiation with pulse powers of tens of gigawatts and pulse lengths of tens of femtoseconds and shorter [3]. The central wavelength λ of the XFEL radiation is given by the resonance condition [2]: where λ u is the undulator period length, γ the mean Lorentz factor of the electrons, and K the undulator field parameter. The natural bandwidth of the SASE-XFEL pulses is on the order of the Pierce-parameter ρ [2], whose typical values for an XFEL facility range between 10 −3 and 10 −4 . The use of seeding techniques enables a further reduction of the XFEL bandwidth closer to the Fourier limit, thus improving the longitudinal coherence of SASE-XFELs [4][5][6][7][8].
There is, however, a strong scientific interest to obtain broad-bandwidth XFEL pulses for certain types of experiments. For instance, in x-ray crystallography, the use of large-bandwidth XFEL pulses improves the efficiency in recording useful diffraction patterns for reconstructing the structure of crystalline materials such as proteins [9][10][11].
XFEL pulses with large bandwidth are also beneficial for x-ray absorption spectroscopy [12], stimulated Raman spectroscopy [10], and multi-wavelength anomalous diffraction [13,14]. From the point of view of operation, a largebandwidth regime allows for more flexibility in the use of the radiation pulse: the XFEL wavelength can be tuned by just applying a monochromator and without changing any parameter on the accelerator side at the expense of reducing the photon count per pulse.
A natural way to obtain large-bandwidth XFEL pulses is to produce the radiation with an energy-chirped electron beam. For instance, an electron bunch with 2% relative energy chirp will generate, from the differentiation of Eq. (1), XFEL pulses with 4% relative bandwidth. Andonian et al. [15] obtained FEL pulses for a central wavelength at the micrometer level with a relative bandwidth of 15% full-width (FW), by injecting into the undulator section an electron beam with an energy of 70 MeVand a large chirp. In XFEL facilities the electrons are normally accelerated at the on-crest phase in the rf structures to ensure maximum energy gain. Some rf structures, however, operate off-crest to generate the required energy chirp for bunch compression: i.e., the head of the beam has less energy than the tail, such that when the electrons travel through a magnetic chicane the bunch is longitudinally compressed. Typically the beam is compressed with up to three bunch compressors (BC) and the relative energy chirp used to compress the beam has values at the 1% level or below. The last bunch compression stage is normally performed at an intermediate electron energy and the beam is further accelerated in rf structures downstream. To maximize the energy gain the last rf structures are normally operated on-crest, thus the energy chirp is reduced from the last BC to the undulator line proportionally to the energy increase. For this reason the generation of a large relative energy chirp becomes more challenging in the x-ray regime. A possibility to increase the final energy chirp is to operate off-crest in more rf structures than the ones required for compression. This option is, however, not efficient since more rf structures are needed to obtain the same final electron beam energy. In the following we will refer to the relative energy chirp and relative bandwidth simply as energy chirp and bandwidth.
With the proper parameter choice the longitudinal wakefields of the rf structures minimize the energy chirp of the beam in standard operation, which aims to minimize the projected energy spread of the beam. However, if the beam is overcompressed in the last BC, i.e., if head and tail of the bunch interchange their positions, the energy chirp changes its sign and the wakefields increase the energy chirp. An operation mode based on beam overcompression combined with the use of the wakefields from the rf structures to generate a large XFEL bandwidth was suggested for the first time by P. Emma [16] and is currently under investigation at the Linac Coherent Light Source (LCLS) [17].
The longitudinal phase space of the beam at the entrance of the undulators also depends on the distribution at the source. Backward tracking along the linac enables us to find a distribution at the end of the injector that produces the target distribution at the end of the linac. The optimization of the final distribution by properly shaping the electron beam current at the photoinjector has been discussed theoretically [18] and later demonstrated experimentally [19]. While Penco et al. used the shaping of the electron beam current to remove the quadratic term, it could also be utilized to enhance the first order and, thus, the compression in general. However, backward tracking along the linac is not a self-consistent method to optimize the compression scheme and the source distribution, as neither collective effects along the linac nor the space-charge dominated contribution from the injector can be included.
In this work we propose a self-consistent method that maximizes the XFEL pulse bandwidth by systematically maximizing the energy chirp of the electron beam with the use of overcompression in the last BC. To this end, we optimize both the compression scheme along the machine and the electron distribution at the source in an iterative backand-forward tracking routine, in which the injector dynamics with all collective effects are taken into account. In principle, dielectric structures or corrugated pipes could be used to further increase the chirp of the electron beam [20][21][22]. Here we only consider the effect from the rf wakefields.
There are other approaches to produce the energy chirp. For instance, in Ref. [23] it was proposed for the European XFEL project [24] to use the longitudinal space charge of an extremely compressed beam to generate an energy chirp that was further enhanced in the undulator line by resistive wakefields. The simulations showed a 2% bandwidth for a radiation wavelength of 2 Å. The option of harmonic lasing [25][26][27][28] can also be used to further increase the XFEL bandwidth. If the fundamental harmonic of the XFEL radiation is suppressed, the odd harmonics can grow to saturation, achieving a brilliance comparable to that of the fundamental. For the third harmonic the required electron beam energy is about 70% lower than the one required for the fundamental, according to Eq. (1). Therefore, for the same absolute electron energy chirp, the relative one will be 70% larger and, as a consequence, the bandwidth will be increased by the same amount. This option, however, is unfeasible for the SwissFEL case because the fundamental wavelength cannot be suppressed effectively in the hard xray undulator line and there is a poor coupling of the third harmonic due to the low K-value.

II. THE SwissFEL FACILITY
Since our simulations are based on SwissFEL parameters we briefly describe this facility. The discussed scheme, however, can be applied to FEL machines with a similar layout: rf gun, bunch compressors, wakes, etc.
SwissFEL is an x-ray free-electron laser presently under construction at the Paul Scherrer Institute. In its initial phase SwissFEL will produce SASE photon pulses covering the wavelength range from 1 Å to 7 Å at the hard x-ray undulator line Aramis. A soft x-ray undulator line, Athos, producing photon pulses in the wavelength range from 7 Å to 70 Å, is planned for an upgrade phase.
The electron bunches for SwissFEL are generated at an S-band rf photoinjector (gun) and accelerated by S-band rf cavities in two booster sections. A laser heater (LH) is situated in between the boosters. The last cavities in the booster are operated off-crest to create an energy chirp in the bunch. The X-band rf cavity downstream operates at a fourth harmonic of the booster cavities, and is used to linearize the energy chirp of the bunch. The first magnetic chicane (BC1) compresses the electron bunches at an energy of 330 MeV. A first C-band linac accelerates the beam up to 2.1 GeV, at which energy the second magnetic chicane (BC2) compresses the bunch further. The two C-band linacs downstream bring the beam up to the final energy of 5.8 GeV. Two transverse deflector cavities, one situated after the first bunch compressor and the other at the end of the linac, will be used for longitudinal diagnostics. A schematic layout of SwissFEL showing only the beamline components relevant to the longitudinal phase space is shown in Fig. 1.
SwissFEL will have various operation modes [29]. In the standard one bunches of 200 pC will be accelerated up to 5.8 GeV and will generate XFEL pulses of 1 Å with a 4 × 10 −4 bandwidth. For the SwissFEL large-bandwidth mode bunches of the same charge at the same energy should yield pulses of 1 Å with a 3% FW bandwidth. To this end, the electron beam should have an energy chirp of at least 1.5% at the entrance of the undulators.
We have performed start-to-end tracking simulations along SwissFEL with the use of different codes. Tracking simulations from the gun to the LH are run using ASTRA [30]. In this low-energy region space charge is the dominating distortion source and ASTRA enables 3D simulations including it. The simulations from the LH to the end of the linac are performed using LiTrack [31] and Elegant [32]. We run the numerical optimizations using LiTrack, a 1D (longitudinal) code in which some distortion sources as the wakefields from the rf structures can be included, but collective effects cannot. We use LiTrack as it enables very fast computations for iterative procedures. Afterwards we validate the results by comparing them to the tracking results from Elegant, which accounts also for the effects of other distortion sources such as coherent and incoherent synchrotron radiation (CSR and ISR). The differences in bunch length and energy chirp between LiTrack and Elegant are of the order of 1% for bunches that are not strongly compressed (that is, upstream BC2). The difference in bunch length increases to the order of 10% for overcompressed bunches (downstream BC2), where CSR cannot be neglected. The simulations of the XFEL pulses generated by the electron beams in the undulators are done with the code Genesis 1.3 [33].

III. GENERATION OF ELECTRON BEAMS WITH A LARGE ENERGY CHIRP
We propose to generate electron beams with a large energy chirp by setting the time-dependent rf fields and the dipole angles of the magnetic chicanes to overcompress the beam in the second bunch compressor. The electron beam enters the second bunch compressor with a positive energy chirp: the head of the bunch contains the electrons with the lowest energy and the tail those with the highest. Due to the dispersion of the magnetic chicane the head of the bunch travels a longer path than the tail and the sign of the energy chirp changes. At the exit of the magnetic chicane the electrons in the bunch head have a higher energy than those in the tail. Thus, the longitudinal wakefields of the subsequent linac increase the energy spread and contribute to the build-up of the energy chirp.
The longitudinal wakefield potential WðsÞ is given by the convolution of the longitudinal charge distribution of the beam, ρðsÞ, and the point-charge wake function of the rf structure, wðsÞ, According to Ref. [34] the point-charge longitudinal wake function of the structure can be approximated as where Z 0 is the free-space impedance, a is the iris radius, and s 0 is a geometric parameter that depends on the period length, gap and radius of the rf structure.
Due to the increase of the longitudinal wakefields with the decrease of the iris radius, as shown in Eqs. (2) and (3), the wakefields of the X-band structures are stronger than those of the C-band structures, which themselves exceed those of the S-band structures. However, the effect of the wakefields on the beam is proportional to the length of the structures which generate the wakefields. A comparison of the product of the point-charge wake function with the effective structure length, L RF , is shown in Fig. 2 for the full length of the S-band boosters (24.5 m), the X-band linearizer (1.5 m) and C-band linacs (205.7 m). This product is a factor 24 higher for the C-band structures than for the S-band ones. Thus, the use of C-band linacs at SwissFEL contributes to the build-up of a large energy chirp in a compact machine. Additionally, from Eq. (2) it is clear that a larger wakefield potential can also be generated by increasing the longitudinal charge distribution of the beam. Thus, a larger energy chirp can be built with the use of a higher bunch charge.
The effects of the rf fields and wakes in the longitudinal phase-space are reversible, that is, by tracking forward and then backward along the same structure the initial distribution is recovered. The reversibility is also true in the BC if the CSR and resistive wall effects are neglected, as we do when we track using LiTrack. Reverse tracking is a common technique that has been used, for example, to flatten the final current and energy profiles [18]. Thus, by tracking backward the final distribution with the energy chirp we need, we can find the corresponding unique distribution at the end of the injector. In this manner the initial distribution from the gun can also be considered a variable to be optimized.

A. General procedure
There are no analytical formulas that describe the longitudinal phase space generated in a system where wakefields cannot be neglected, and which contains two or more magnetic chicanes. In such a case no equations can be used to convert directly the parameters of the desired compression scenario into the lattice parameters, namely the angles of the magnetic chicanes, the rf voltages and phases of the accelerating structures. Therefore, iterative procedures based either on semianalytical models or numerical tracking are required to find these lattice parameters. Similarly, to find an optimum longitudinal distribution at the gun, a procedure based on numerical tracking has to be applied.
We propose a four-step cycle, sketched in Fig. 3, to optimize the compression scheme and the electron distribution at the source.

B. Step 1: Forward optimization of the compression scheme
The compression scheme is optimized for the nominal initial distribution of the electron beam at the LH, which we call input distribution (A). A two-stage procedure, which combines an initial coarse tuning with a later fine tuning, is used to optimize the compression scheme to obtain the distribution with the largest energy chirp at the undulator entrance. We call the distribution resulting from the optimization of the compression scheme the final distribution (B).
The first stage of the forward optimization is based on the semianalytical algorithm developed by Zagorodnov and Dohlus [35]. This semianalytical algorithm was already applied for the design of the different operation modes of SwissFEL [36]. It uses the voltages and phases of the rf cavities upstream of the BCs as optimization variables. The correlation between the longitudinal positions of each particle up-and downstream of each BC is used to describe the longitudinal dynamics. The fitting parameters of the correlation plots, related to the compression factor (linear term) and to the bunch profile (nonlinear terms), are used as optimization targets. This semianalytical method, however, suffers from some limitations: first, it does not include the angles of the BC dipoles as optimization variables. Second, the optimization targets are relative to the initial beam distribution. Consequently, tracking simulations run on a trial-and-error basis are needed for each input distribution to find a given final current profile. Finally, it only optimizes the current profiles but not the energy profiles, thus, the energy chirp cannot be explicitly maximized.
The second stage of the forward optimization consists of a fine tuning of the bunch profile based on a numerical optimization. The voltages and phases of the rf structures and the angles of the BCs are used as optimization variables (phases, voltages and angles indicated in red under their corresponding component in Fig. 1). A vector containing the optimization variables is defined as x. We include constraints on the optimization variables (lower and upper boundaries, x l and x u , resp.) according to the hardware limits (e.g., the maximum gradient of an rf structure). The optimization targets are chosen to be independent of the input distribution. To this end, the rms bunch length σ zB and rms energy spread σ EB of the final distribution (B) are set as targets. The bunch profile of (B) is sliced and the current of each slice, I iB , is also used as a target. In this manner not only flat profiles, but any profile can be generated. The energy profile is also sliced and the value of each slice C iB is used as a target. The numbers of slices implemented in the optimization presented here are five for the current profile and five for the energy profile. These numbers are a compromise between flexibility-enough slices to define a profile-and complexity-not too many optimization goals. The fraction of particles of the distribution considered in the optimization can be varied. Typically only the central part of the distribution, contributing the most to the lasing, would be optimized into a flat profile, but also the head or tail regions may be selected for optimization. For the simultaneous optimization of all goals an aggregate objective function, F 1 ðxÞ, is constructed as a weighted average, where the coefficients c are the weighting terms. We apply a single-objective optimization algorithm, in this case the interior-point method, to the aggregate function subject to constraints. Due to the nature of the algorithm, convergence only occurs if starting from a good initial estimate. The result from the semianalytical algorithm is used as an initial estimate for this numerical optimization, and convergence is typically achieved in less than 50 iterations.

C. Step 2: Rescaling of the final distribution chirp
The energy coordinate of the final distribution (B) is rescaled such that the energy chirp of the overcompressed beam is increased to the value that will produce the target pulse bandwidth. We call the distribution resulting from the re-scaling the final distribution with modified chirp (B').
The problem of optimizing the compression scheme and the distribution at the source to get a large energy chirp at the undulators cannot be simplified by artificially generating (B'), as convergence would not occur. Steps 1 and 2 are necessary to start from a realistic non-linear term.

D. Step 3: Backward optimization of the compression scheme
We need to find the distribution at the gun that would produce the final distribution with modified chirp (B'). By tracking (B') backward to the LH we find what we call the modified input distribution (A'). Due to the rescaling the optimized values for the compression scheme from step 1 are no longer optimal. If used, the resulting (A') would have a bunch length and energy spread that could not be generated with the photoinjector. Thus, the compression scheme has to be optimized again, in this case backward, to get a modified source distribution at the LH that can be attained by varying the longitudinal laser profile of the photoinjector. To fulfill this condition (A') should have a similar bunch length, energy spread, and shape (defined by the S-band booster) than the initial distribution (A). Thus, the goals of the numerical optimization are the rms bunch length σ zA and rms energy spread σ EA of (A), and the fitting coefficients of a second order polynomial k 0A , k 1A , and k 2A applied to (A). It should be noted that no goal is set on the bunch profile. The objective function for the backward optimization, F 2 ðxÞ, is built as a weighted average, where the coefficients c are the weighting terms. A singleobjective optimization algorithm is used to find the optimum values for the voltages and phases of all rf structures and angles of the BCs within their upper and lower boundaries.

E. Step 4: Photoinjector optimization
Finally, the distribution at the photoinjector is optimized such that its longitudinal profile at the LH matches the longitudinal profile of (A'). In the machine this corresponds to shape the laser longitudinal profile, which can be done by optimizing the pulse stacking scheme [37]. In simulation, we generate an electron distribution at the photoinjector that fulfills a certain current profile: a linear slope at its center and a rising and a falling edge at the head and the tail, respectively. We start with (A') as initial distribution at the photoinjector. We track it along the injector till the LH and call (A") the resulting distribution. This tracking is done using the numerical code ASTRA [30] to take into account not only the longitudinal but also the transverse space-charge forces acting at this low beam energy and large charge density. We iteratively modify the slope of the central part of the laser longitudinal profile to minimize the difference between (A') and (A") in terms of current profile. We limited the ratio between the current at the head and at the tail to a factor ten, as we consider this value to be the limit for the laser system.
Convergence is obtained when (A") is tracked forward, along a machine with the optimized compression settings from step 3, and a similar distribution at the undulator entrance is found as when (A') is used; attaining the target energy chirp and a flat current profile. In this case the XFEL pulse bandwidth generated by (A") will lie within the statistical error of the pulse bandwidth generated by (A'). The limits of this procedure are found when it is no longer possible, through the optimization of the distribution at the photoinjector, to produce a distribution (A") that matches (A') closely enough such that differences in terms of lasing lie within statistical errors from the shot noise. These limits are further discussed in the next section for the case of SwissFEL.

IV. APPLICATION TO SwissFEL
The procedure described above to obtain electron beams with a large energy chirp at the entrance of the undulators has been applied to SwissFEL. In this case the distribution from the gun is tracked to the LH, where it has a flat current profile, a bunch length of 933 μm rms and an energy spread of 0.24% rms. We first apply the semianalytical algorithm to optimize the gradient and phase of the booster cavities situated after the LH (V s , ϕ s ), the gradient and phase of the X-band linearizer (V x , ϕ x ), and the gradient and phase of the C-band structures of linac 1 (V c1 , ϕ c1 ) situated between the two BCs. The resulting compression scheme after 10 iterations, shown in Fig. 4, overcompresses the bunch, generating an energy chirp of 1.26% FW. The bunch profile, however, is not ideal as a large spike forms at the head. A bunch with such an uneven density distribution radiates nonuniformly along the undulators, as the spike dominates the FEL process and saturates much earlier than the rest of the bunch. Moreover, the spike is more prone to collective effects arising e.g., from space charge. It is also more sensitive to variations in the compression setup, making it overall more unstable as well as harder to predict and control. To fine-tune the bunch profile, removing current spikes while keeping the same energy chirp, the numerical optimization is applied. Additional variables are included in the numerical optimization, namely the angles of the two BCs (α BC1 , α BC2 ) and the voltages and phases of the rf structures in linac 2 (V c2 , ϕ c2 ) and linac 3 (V c3 , ϕ c3 ). The resulting final distribution (B) after 20 iterations has a much flatter profile, as shown in Fig. 4.
We calculate the XFEL radiation of the final distribution (B) along the undulator modules for five different seeds of the shot noise. A relative bandwidth of 2.44% FW (width above the noise level, including a 5% cut) is found for the energy-chirped electron bunch that results from the optimization of the compression scheme. The results including statistical errors are summarized in Table I. The increase of the XFEL bandwidth is proportional to the increase in energy chirp of the electron beam for an ideal flat current profile. Therefore, we rescale the energy coordinate of the optimized distribution from step 1 to reach the 3% FW bandwidth desired by the users of SwissFEL. In this manner we generate a distribution (B') with an energy chirp of 1.79% FW. To optimize the compression scheme backward all optimization variables are used. The objective function is built in such a way as to get a modified source distribution with a bunch length of 933 μm rms, an energy spread of 0.24% rms and the same shape as the input distribution, defined by the fitting coefficients of a second-order polynomial. In 50 iterations a backward-optimized compression scheme is found. The resulting modified source distribution at the LH, (A'), matches the bunch length, energy spread and shape of the input distribution but has a ramped current profile instead of the standard flat one. The current of the bunch head is twice larger than the current of the tail. The convolution of this ramped charge distribution with the point-charge wake produces a wakefield potential with a steeper initial slope and a flatter peak. In the optimized scheme found in step 3, the booster and linearizer cavity are set further off-crest, thus increasing the chirp that enters the BC1 by 10% and reducing the nonlinear components. The wakefield potential from the ramped distribution further helps linearizing the chirp before compression. Higher voltage amplitude is used to reach the same energy. The compression factor of BC1 is reduced by almost a factor two and the settings of Linac 1 are kept unchanged. The resulting chirp at the entrance of BC2 is almost a factor two larger. The compression factor at BC2 is twice larger (with less than a 3% larger dipole angle) to reach the same final bunch length of the order of 5 μm, with a 50% larger chirp FWHM.
We optimize the longitudinal electron distribution at the gun to generate an input distribution at the LH, (A"), which matches the aforementioned ramped current profile.
Generally, the first solenoid downstream of the gun is optimized for emittance compensation of the standard flatcurrent profile. In the case of a ramped profile each slice contains a different amount of charge and the emittance compensation could be no longer optimum. Extensive studies on ramped longitudinal distributions have been presented in [38]. However, for a ramped current profile with the bunch head twice larger than the tail, the slice emittance increase we observe along the injector is negligible. Additionally, in the optimization process we do neither modify the initial transverse size of the laser nor the solenoid parameters compared to the nominal case, so no transverse emittance increase is generated. The initial and optimized input distributions are shown in Fig. 5 (left). Tracking (A") along a machine with the compression scheme optimized in step 3 results in a distribution with the target energy chirp, 1.79% FW, and a similar flat current profile as (B'). A comparison between the distributions at the entrance of the undulators resulting from the forward optimization of the compression scheme (step 1) and from the full optimization routine is shown in Fig. 5 (center). The XFEL radiation obtained after the full optimization routine has a bandwidth of 3.25 AE 0.05% FW. The difference in terms of lasing bandwidth between (A'), the ideal distribution, and (A"), the matched distribution, is of the order of 10% and within the statistical error from the shot noise. Thus, convergence has been achieved for the rescaling factor used, which aimed to reach a 3% FW bandwidth.
An increase of 33% in radiation bandwidth is obtained after the full optimization routine compared to the case in which only the forward optimization is applied, as shown in Table I. It has to be noticed that the increase in bandwidth amounts to 50% if the FWHM is considered, scaling as TABLE I. Energy chirp and XFEL pulse bandwidth including the statistical errors for SwissFEL. Two different cases are presented: after the optimization of the compression scheme (step 1) and after the full optimization procedure, which includes the optimization of the compression scheme of the machine and of the electron distribution at the source.

Optimization
Energy Chirp XFEL Bandwidth Step 1   expected with the increase in FWHM energy chirp. A comparison between the radiation bandwidths from the Aramis undulators resulting from the forward optimization of the compression scheme (step 1) and from the full optimization routine is shown in Fig. 5 (right). The smaller increase in FW bandwidth can be explained by the poorer FEL performance at the head and tail of the bunch. This is typically caused by increased emittance, poorer alignment and stronger mismatch, even from the electron production in the gun and further enhancement due to CSR in the compression. We have investigated the source of this difference, though uncoupling all effects is not always possible. Most beam properties remain similar for the cases of full optimization and forward optimization (step 1), including the beam size evolution along the longitudinal axis. The largest variation has been observed for the bendplane orbit along the longitudinal position, which could be caused by the larger CSR in the bunch compressors due to the larger chirp.
We have explored the limits of this optimization procedure and studied the possibility to rescale the energy chirp to a larger value at (B'). For the case of a 2.15% energy chirp, backward optimization has been implemented successfully; a modified input distribution (A') with the same values of the bunch length, energy spread and fitting parameters as the input distribution has been found. The corresponding current profile has a more pronounced slope, with a five times larger current at the head than at the tail. The current profile also shows a sharp edge at the head. This high current at the head is necessary to drive the large wakefields needed to generate such a large bandwidth. However, optimizing the longitudinal distribution at the gun to match the modified current profile at the LH does not seem possible any longer. Although the slope can be matched, the sharp edge can no longer be generated. As a consequence, tracking the optimized beam distribution at the gun does not reproduce the distribution (B') with the target energy chirp and flat current profile. The resulting lasing bandwidth does not attain the values obtained from (B'). Attempts to generate this sharp edge by scraping horizontally the bunch at the center of BC1 lead to a correspondingly reduced chirp, which does not exceed the values from Table I.

V. CONCLUSIONS
We have developed a new self-consistent method to generate large-bandwidth XFEL pulses based on the maximization of the energy chirp of the electron bunches at the entrance of the undulators. To do so the compression settings along the machine (rf and BC parameters) and the longitudinal distribution at the photoinjector are optimized. The method is general, based on iterative forward and backward numerical tracking, and is also valid for other operation modes, by simply changing the weighting factors of the optimization goals.
In the case of the large-bandwidth mode of SwissFEL we found that a ramped current profile enables a larger energy chirp of the electron bunch and a proportionally larger XFEL pulse bandwidth with respect to the standard (flattop) input distribution. Thus, an increase of 33% FW (50% FWHM) in energy chirp and pulse bandwidth has been demonstrated in simulations when the full optimization procedure, consisting on the optimization of the compression scheme and of the electron distribution at the source, has been applied. A bandwidth of 3.25 AE 0.05% FW (2.19 AE 0.41% FWHM) has been achieved.