Low emittance injector design for free electron lasers

Several parameters determine the performance of free electron lasers: the slice and the projected emittance, the slice energy spread, and the peak current are the most crucial ones. The peak current is essentially obtained by magnetic compression stages along the machine or occasionally assisted by velocity bunching at low energy. The minimum emittance and the alignment of the slices along the bunch are mainly determined in the low energy part of the accelerator (injector). Variations at the per-mille level of several parameters in this section of the machine strongly influence these quantities with highly nonlinear dynamic. We developed a numerical tool to perform the optimization of the injector. We applied this code to optimize the SwissFEL injector, assuming different gun designs, initial bunch lengths and intrinsic emittances. We obtained an emittance along the bunch of 0.14 mm mrad and around 0.08 mm mrad for the maximum and the minimum SwissFEL charges (200 and 10 pC, respectively). We applied the same tool to a running injector, where we automatized the optimization of the machine.


I. INTRODUCTION
The availability of reliable high-brightness electron sources is essential for the successful operation of linac based free electron lasers (FELs). The electron bunch may be produced by thermionic or photoelectric effect. Here we focus on the latter case, but the described procedure is in principle valid also for thermionic injectors with corresponding adaptations.
For the efficiency of the self-amplified spontaneous emission (SASE) of the FEL process a very high peak current, low energy spread, and small transverse emittance electron bunches are essential [1]. In the following discussion we will refer to the slice and the projected emittance. The first is the emittance of a fraction of the total bunch length along the longitudinal dimension of the beam (typically the first and the last 1=8 of the total bunch length which we identify as the head and the tail degraded in the downstream sections of the machine are excluded, and the total beam length is divided in 20 intervals). The latter one is the emittance considering the entire beam as a single slice. In typical FEL designs a 1 to 10 ps long bunch is compressed by magnetic chicanes down to femtosecond pulse lengths before entering a series of undulator modules. The final peak current and energy spread are determined by the compression process and the wakefields in the linac. The criterion [2]: with ϵ n being the projected normalized emittance, γ the Lorentz factor and λ the wavelength of the coherent radiation generated along the undulator line, expresses the requirement for the transverse overlap between electron and optical beam. From this relation it is evident that for shorter wavelengths a low emittance is mandatory to operate at lower electron beam energy and thus to keep the linac at reasonable length. Since the normalized emittance is at best preserved or realistically slightly growing along the accelerator complex, it is essential to optimize it at the exit of the injector. The emittance at this point is determined by four contributions [3,4]: the intrinsic emittance, the radio frequency (rf) fields [5], the space charge force, and the first solenoid downstream of the gun. The first two effects depend on the emission process of the electrons from the cathode and mainly on the gun design, whereas the latter one is influenced by several quantities in the injector (such as laser transverse dimensions and shaping, solenoid strengths, position of the first accelerating cavity, gun gradient, length of the first gun cell, and gradient of the first accelerating structures). The minimization of the emittance along the bunch is only one of the aspects to be considered for the SASE optimization. The good overlap of the radiation with the electron beam along the bunch in the undulator beamline plays an important role and it has to be maintained as much as possible. This is quantified by the mismatch parameter [6], defined as: where α, β and γ are the Twiss parameters at different longitudinal positions of the electron beam slices along the bunch. Several definitions of M are possible: the subscript 0 may in fact indicate the Twiss parameters of the projected bunch, the central slice or the design optics. We define M with reference to the optics of the projected bunch. Another important quantity used in photoinjectors is the brightness B, given by: where I is the beam current, and ϵ x and ϵ y the horizontal and the vertical beam emittances, respectively. Considering the number of parameters involved in the optimization of a photoinjector, we developed a code automatizing the process. Other authors reported about similar approaches [7][8][9]. A known condition to minimize the emittance of photoinjectors is based on the invariant envelope matching, described in [10,11]. According to this approach the beam emittance has two minima along the drift downstream of the rf gun. If the first accelerating cavity is positioned at a point where the emittance maximum and the envelope waist are, the second minimum is shifted toward the end of the accelerating section, where the space charge forces are for the typical conditions in photoinjectors negligible. If this condition is satisfied the resulting emittance can be minimized. Some of the optimization codes force the injector parameters to fulfill this condition [8]. Other codes are based on a genetic algorithm [9], which requires large resources, and in these cases it may be necessary to control many parameters to obtain a converging solution. We present here a very fast and userfriendly tool well which is not constrained by established analytical conditions, but directly analyzes and optimizes the beam parameters at the end of the injector. Our optimizer is based on the simplex algorithm used in different stages to optimize the most and the less critical variables of the photoinjector.
The code was used to optimize the SwissFEL [12] injector for various gun designs assuming different intrinsic emittances, laser pulse lengths, beam charges, and using nonstandard configurations for the laser longitudinal shaping. In all cases the process converged to some of the smallest reported emittances to our knowledge for equivalent configurations (peak current at the cathode, rf gradients, and first solenoid position). The Linac Coherent Light Source (LCLS) reported a normalized emittance of 600 nm for a bunch charge of 150 pC and a laser pulse length of 6 ps [13]. FERMI, the FEL facility in operation in Trieste, published an emittance of about 1500 nm for the same laser pulse length and 200 pC [14]. PITZ, the photo injector test facility at DESY, measured an emittance of 400 nm for a 250 pC bunch charge but a laser pulse length of 23 ps FWHM [15]. Simulations carried on in collaboration with Berkeley about LCLS-II, the future FEL facility under development at SLAC, showed a slice emittance smaller around 100, 300, and 450 nm for bunch charges of 20, 100, and 300 pC and pulse lengths between 10 and 60 ps rms [16]. Values similar to the simulations results have been experimentally confirmed at Cornell [17].
From our optimizations of the SwissFEL injector we expect an emittance around 200 and 100 nm with a laser longitudinal length of 6 and 23 ps FWHM, respectively. The results were achieved because the optimizer identified a novel working point for the SwissFEL photoinjector, obtained by shifting the position of the first accelerating cavity with respect to the optimum fixed by the envelope invariant matching condition. Some of our optimization results have already been confirmed experimentally [18].
We give a brief description of the tool in Sec. II. We also use some analytic formulas, which allow useful scalings to compute the minimum expected emittance as a function of peak current and intrinsic emittance, based on a single layout optimized by numerical simulations. Interfacing the optimizer to the control system of a running injector allowed achieving experimentally a fully automated optimization of the beam parameters. A brief description of this procedure is presented in Sec. IV.

II. THE AUTOMATED OPTIMIZER
A large number of parameters determine emittance and beam mismatch at the end of a photoinjector. For this reason an automated optimization is highly desirable, as the manual tuning of more than a few parameters may become very tedious and time consuming. Several algorithms can be used to perform the optimization, keeping the overall structure of the code unchanged. The initial input file contains the starting lattice, the parameters to be adjusted and their initial values, and a function computes emittance and mismatch along the bunch. The latter quantities are used to calculate the figure of merit (FOM), as: where the summation is over the slices along the bunch and w 2 ∼ 5w 1 =ðmm mradÞ to balance the terms on the righthand side of Eq. (4). In all our simulations we defined a FOM given by a linear combination of the emittance and the mismatch parameter along the central 75% of the total bunch length (the head and the tail of the bunch do not typically participate to the lasing process). According to the results a new input file is written and the process is iterated until the variation of the FOM is smaller than a predefined tolerance. Satisfactory results were obtained using a simplex algorithm, which resulted to be enough if used in stages including before the most critical and after also the other injetcors variables to refine the obtained result. In case this were not enough anymore the algorithm could be easily changed without altering the structure of the code.
At low energy many several parameters of different importance must be adjusted simultaneously to compensate for space charge in order to control emittance and longitudinal matching. In Fig. 1 we show the schematic layout of a photoinjector.
The final injector emittance strongly depends on the amplitude of the solenoid at the gun exit, the laser pulse shape both in longitudinal and the transverse extension, and the position of the first accelerating cavity. The dependence on the gradient, phase and magnetic field of the first accelerating structure and the surrounding solenoids is weaker. In the region from the cathode to the first accelerating cavity, in fact, one can typically obtain several tens of percent emittance variation with less than 1% change of a parameter [19], therefore a careful optimization is mandatory.
In a multivariable problem it is extremely important to restrict the number of variables as much as possible to ease the convergence of the algorithm and to avoid being trapped in a local minimum. In this work two optimization stages were considered. In a first run only the most critical parameters for the emittance-mismatch optimization are varied: the transverse laser spot size, the strength of the first solenoid downstream of the gun and the position of the first accelerating structure. The code typically finds a solution in less than 20 iterations. After this first optimization less critical parameters, such as the gradient and the strength of the solenoids surrounding the accelerating cavities (typically the first two structures) are also included in the optimization process. Convergence in this case is obtained typically in about 50 iterations. Figure 2 shows the FOM computed versus the iteration number for the optimized case of the SwissFEL injector described in Sec. III A.
The beam dynamics simulations are performed using ASTRA [20], a tracking code which includes longitudinal and transverse space charge force calculations. First we run the simulations using 5000 particles (each iteration requires 2 min using 8 nodes of the PSI Merlin cluster), which is a good compromise between the accuracy of the solution and the time necessary to ultimate a single run. Figure 3 shows the mean and the standard deviation of the slice emittance calculated along the central 3=4 of the total length of the total bunch length assuming a different number of particles normalized to case using 200 thousand particles.
At each iteration the optimizer averages the emittance of the slices over the central length of the bunch. As shown in Fig. 3 the RMS value of the slice emittances along the bunch decreases by about a factor 2, whereas the variation between the case using 5000 and 200 thousand particles of the mean value, used in the FOM computation, is below 5%. After a solution has been determined using 5000 particles another simulation is done using 200 thousand particles (this requires 5 min using 8 nodes of the PSI cluster Merlin). In total each complete optimization takes less than two hours using 8 cores of the PSI cluster Merlin.

III. THE OPTIMIZATION OF THE SWISSFEL INJECTOR
We applied the optimization process to the SwissFEL injector. SwissFEL [12] is the Free Electron Laser facility under construction at the Paul Scherrer Institute. It consists of an S-band injector followed by a C-band linac powering two undulators lines in parallel. The hard X-ray line will deliver photons in the wavelength range from 1 to 7 Å, and the soft X-ray line from 7 to 70 Å. The commissioning of the injector is foreseen to start in Spring 2016 and the first pilot user experiments are expected by the end of 2017.
The electrons emitted from the photoinjector are accelerated by two S-band cavities to about 150 MeV, before entering a laser heater system foreseen to mitigate the microbunching instability [21] that can develop during the bunch compression. The beam is then further accelerated to 320 MeV before undergoing the first longitudinal compression. All optimizations presented here refer to the injector section up to the exit of the fourth accelerating structure with laser heater off. At this position, with an energy of about 250 MeV, the beam dynamics is not dominated anymore by the space charge forces and the beam parameters are practically frozen.
The photoinjector consists of a 3 GHz rf-gun driven by an ultraviolet (UV) laser at 260 nm wavelength illuminating a Cs 2 Te cathode. We plan using a Cs 2 Te coating on copper cathode, which experimentally showed a negligible increase of the intrinsic emittance compared to copper while yielding a much larger quantum efficiency (QE) [22]. This makes this cathode material particularly attractive for routine operation. The laser pulse is shaped longitudinally into a quasi flat-top distribution by stacking replicas of an initial Gaussian pulse with alternating polarizations. The nominal bunch charge of SwissFEL ranges from 10 pC to 200 pC in order to accommodate the different users needs. The pulse length will be tuned depending on the bunch charge by adjusting the parameter of the stacked pulses. The limitation of this approach arises from the possible interferences generated by the overlap of single pulse tails of the same polarity and from the intrinsic flat-top modulation generated by the stacking method. In our simulations we approximated the laser pulse by a uniform radial and flat-top distribution with a rising and falling time of 0.7 ps, as feasible by the laser system, in the transverse and longitudinal dimensions, respectively, since under normal conditions the deviation from this setup has a negligible impact on the emittance and the mismatch in the central part of the bunch. Some studies about the effect of the deviation from the ideal longitudinal flat-top can be found in [21].
In preparation for SwissFEL we built the SwissFEL Injector Test Facility (SITF) to verify the required beam parameters and test the accelerator components and diagnostics. This facility was operational from 2010 to 2014. The measurements presented in the next sections were performed at this machine.

A. Gun dependence
The SITF design, reported in [23], was based on the CTF2 gun version 5 received on loan from CERN [24]. A new gun [25], designed and manufactured at PSI was optimized for the specific requests of SwissFEL (repetition rate up to 100 Hz, suppression of the dipolar and quadrupolar modes) and tested at the SITF during the last 5 months of operation of this facility. From the beam dynamics point of view these guns are very similar, the main differences being the strong reduction of the quadrupole component of the rf field, and the higher strength at the cathode plane for the PSI gun. The longitudinal component of the electric field along the axis for both guns is shown in Fig. 4. We discuss the optimizations performed assuming both guns, stressing the cases regarding the PSI one, and using the results obtained with the CTF2 gun as a reference case.
When optimizing an injector for a very high brightness it is important to have a realistic estimation of the intrinsic emittance of the photoelectrons, since it determines the lowest achievable emittance. We will refer to the normalized intrinsic emittance, defined as the ratio of the emittance at the emission from the cathode over the laser transverse size (σ). Measurements performed at the Linac Coherent Light Source indicated 910 nm=mm as a normalized intrinsic emittance for pure copper photocathodes at pulse length of 4 ps FWHM and laser wavelength of 253.5 nm [26]. More recently at the SITF we measured smaller values around 550 nm=mm with laser wavelength of 266.6 nm [27]. We present the design using the largest value to compare our results with other optimizations in the literature and the latter one to really optimize for the operational conditions of SwissFEL. For the maximum bunch charge foreseen (200 pC) we assumed, if not stated differently, a 9.9 ps FWHM laser pulse length, corresponding to 20 A peak current at the injector exit. A very important parameter is the position of the first solenoid downstream the cathode. When not differently specified we assumed the center of the solenoid located 30 cm downstream of the cathode, since shifting it closer was impossible in the current PSI gun design. Figure 5 shows the results found by the optimizer for the CTF2 gun assuming the old and the new intrinsic normalized emittance compared with the optimization presented in [23].
The optimizer found a solution which allows reducing the emittance along the bunch by about 30% assuming 910 nm=mm as normalized intrinsic emittance. A further 30% reduction is obtained considering the measured normalized intrinsic emittance of 550 nm=mm. All this would give for SwissFEL an increase of the FEL power by more than a factor 10, as shown in [18]. The value obtained by the optimizer for the smallest normalized intrinsic emittance has already been verified experimentally with the measurements performed at the SITF [18].
During these optimizations we varied only the laser properties, the strengths and the phases of the cavities, and the surrounding solenoids, but keeping constant the position of the first accelerating structure. For SwissFEL we included also this parameter in the optimization process, since the machine has not been assembled and this allows for more flexibility in changing the position of the components. We found a solution which further reduced the emittance, as shown in Fig. 6. Slightly less than 80% of the final emittance is given by the intrinsic one for both cases. The mismatch along the bunch corresponding to the two the emittances shown in Fig. 6 are reported in Fig. 7. During the optimization done assuming 550 nm=mm for the normalized intrinsic emittance we increased the ratio of w 1 over w 2 in the definition of the FOM to reduce the emittance keeping a reasonable mismatch. The optimal values of the most critical parameters of the design for the SwissFEL injector assuming 550 nm=mm compared with the values corresponding to the design reported in [23], are shown in Table I.
In injector designs the position of the first accelerating structure is usually chosen according to the Ferrario criterion [10,11] for emittance compensation by adjusting   the strength of the first solenoid such that the beam waist location coincides with the local maximum of the projected beam emittance. This condition gives a reasonable optimization of the slice misalignment at the exit of the injector. Our optimizer found a different solution in terms of emittance and mismatch, where the optimal position of the first cavity is shifted by about 20 cm downstream of the Ferrario point, as shown schematically in Fig. 8. This emittance is, to our knowledge, the smallest one obtained with a standard S-band gun geometry with the solenoid placed at the exit of the rf-gun.
Several years ago Han demonstrated the advantages of further shifting the gun solenoid closer to the cathode for an early control of the emittance compensation process [28] starting from a design proposed at DESY [29]. To enable this the standard rf coupling ports orthogonal to the cavity axis must be replaced by a coaxial rf coupling. Han demonstrated the advantage of this configuration, since it allows shifting the first focusing solenoid closer to the cathode (only 10 cm distance instead of 30 cm as for the CTF2 and PSI gun), and therefore minimizing the unavoidable emittance increase in the cathode region. We have used the optimizer to determine the emittance which could be obtained substituting the PSI with the Han gun design in the SwissFEL injector. The gradient of the coaxial coupler gun was slightly higher than the PSI case. This allows a partial compensation of the fact that the Han gun is a standard 1.5 cells configuration, whereas the PSI one is 2.6 cells. In Fig. 9 we show the emittance along the bunch of the optimized cases using the coaxial and the PSI gun design.    We report also the value of the emittance optimized for a gradient of 100 MV=m to have a direct comparison with the PSI gun optimization.
The gun design by Han may further reduce the slice emittance by about 25% with respect to the new PSI gun layout, bringing the emittance at the end of the injector down to a value only a few percent larger than the intrinsic emittance. Based on this idea a design of a C-band gun has been started and our optimizer has been used to start the optimization of the injector layout [30].

B. Alternative options
We explored other working points for the PSI rf-gun aiming for a reduced bunch compression factor by shortening the laser pulse length while preserving an acceptable emittance and mismatch along the beam. A lower compression factor generally relaxes the rf tolerances, minimizes the microbunching instability gain [21], and the emittance increase at the exit of the magnetic compression chicane observed at the SITF [31].
In this study the initial transverse and longitudinal dimensions of the beam are defined by keeping the volumetric charge density ρconstant to roughly preserve the space charge force [32]. The optimal case found for the 200 pC, 9.9 ps FWHM pulse length defines the reference density, and the following relation allows estimating the new transverse size of the laser pulse for any other laser pulse length L: where L OPT and σ OPT are the length and the transverse dimension of the laser pulse corresponding to the optimized case, respectively. Assuming the intrinsic emittance scaling linearly with the laser transverse size and from the relation in Eq. (5) we could estimate the expected optimal emittance as a function of the laser pulse length. In this way we can have a guess of the minimum emittance we can expect as a function of the laser pulse length. For each case we used the optimizer to refine the result by minimizing the mismatch while keeping the emittance under control. Figure 10 shows the good agreement among these expectations and the optimizations. In Fig. 11 the brightness as defined in Eq. (3) at the end of the injector for these cases is shown. The brightness of the injector assuming the PSI gun has a peak at about 12 ps (20% larger than the standard 9.9 ps pulse length). For SwissFEL keeping the baseline parameters seems nevertheless a more conservative approach with respect to the risks related to longer laser pulse. According to the numerical simulations the coaxial design should allow almost a factor 4 increase in the brightness for the 9.9 ps initial pulse length. In particular reducing the pulse length to 5 ps results in a slice emittance similar to the baseline configuration of SwissFEL but with an appreciable reduction by a factor 2 of the required bunch compression.
In addition the laser profile may be tuned to minimize the nonlinearities introduced by the space charge. Theoretical studies indicate that a 3D ellipsoidal shape may be beneficial to precompensate the nonlinear effect of the space charge [33,34]. We used the optimizer to determine the best emittance using the PSI gun and the 3D ellipsoid as laser distribution. We kept the gun gradient at 100 MV=m, the peak current at 20 A, and we assumed the normalized intrinsic emittance equal to 910 nm=mm, as for the first optimization assuming the flat-top distribution as laser longitudinal profile. As shown in Figs. 12 and 13 the analysis carried out with the optimizer showed that the PSI  10. Emittance in the central part of the bunch versus the laser pulse length. The theoretical limit of the intrinsic emittance (550 nm=mm assumed) and the expected emittance shifted by the same difference from the intrinsic value obtained for the 9.9 ps pulse length is also shown. The error bars represent the standard deviation of the emittance along the 3=4 of the total bunch length. gun with a 3D ellipsoid gives performances similar to the flat-top configuration. At the moment we do not plan to use this kind of 3D ellipsoid to shape the laser at SwissFEL.

C. Charge dependence
SwissFEL will operate with bunch charges ranging from 10 pC up to 200 pC. The parameters for 10, 50, and 100 pC were optimized while keeping the position of the first cavity as optimized for the 200 pC case. For these optimizations we assumed the PSI gun with 100 MV=m gradient, and the normalized intrinsic emittance values of 910 nm=mm and 550 nm=mm as well. Also in these setups the laser pulse lengths have been fixed by the required injector current at the entrance of the first bunch compressor [23]. All intermediate cases can be estimated by interpolation.
To have a good starting point we calculated for each case the laser transverse size to keep the volumetric charge density ρ constant, using the relation: where the subscripts Q and 200 refer to the generic charge and the optimal value for the 200 pC case, respectively. Starting from these initial conditions the optimizer further refines the results in terms of mismatch and emittance. Table II shows a summary of these optimizations. The beneficial effect of the new PSI gun and the reoptimizations varies from 5% to more than 30% depending on the bunch charge.

D. Intrinsic emittance dependence
The injector behavior versus intrinsic emittance deserves a careful analysis. During operation cathode-to-cathode fluctuations of this quantity or an evolution during the    operation may happen. Additionally the intrinsic emittance can be tuned within a range defined by the available laser bandwidth [27] compromising the QE when tuning for lower emittances. The following analysis gives therefore useful indications about the emittance fluctuation one could expect in a real machine and for the specification of the laser system. Figure 14 illustrates the emittance at the injector exit for the 200 pC case versus the assumed intrinsic emittance at the cathode. In Fig. 15 the result of the optimizations for the 10 pC case is also shown.
At the SITF we measured the normalized intrinsic emittance of several copper and cesium telluride photocathodes [22]. We repeated the measurements on the same copper cathode after several months of operation and on different fresh photocathodes. In this framework typically the emittance measurement spreads by AE10 nm=mm peak to peak. For the cesium telluride we have measurements of photocathodes only after a few weeks of operation. For this material and with this limited set of data the spread of the measured normalized intrinsic emittance is of AE5 nm=mm peak to peak. These fluctuations in the normalized intrinsic emittance are negligible for the SwissFEL operation.

IV. APPLICATION OF THE OPTIMIZER TO A RUNNING INJECTOR
The structure of the automatic optimizer was adapted to directly control and optimize the parameters of SITF. It is sufficient to send the settings to the control system of the accelerator instead of writing an ASTRA input file, and to measure the emittance and the mismatch instead of postprocessing the outputs of the simulation. The Matlab based graphical user interface (GUI) developed to run the optimizer is shown in Fig. 16.
The GUI menu allows selecting between projected or slice emittance measurements and adjusting the FOM (horizontal or vertical projected emittance, geometric average of the two or slice emittance, weighted average of the emittance and mismatch along the bunch). At each step the Twiss, the mismatch parameters, and the emittance are measured. In the GUI the method of the measurement can be selected from a menu according to the quantity which has to be optimized (slice emittance only along the horizontal plane, projected emittance, or geometric average of the vertical and horizontal projected emittances). In the described case we optimized the geometric average of the vertical and the horizontal emittances. We measured the projected emittance via the quadrupole scan technique. The strength of the quadrupoles used in the measurements cover 180 degrees phase advance variation in the horizontal and vertical dimension between the first quadrupole and the profile monitor. The emittance and the Twiss parameters are then reconstructed fitting the measured beam size at the profile monitor as a function of the phase advance. More details about the measurement procedure are reported in [18]. The emittances computed in the cases the mismatch is below the maximum tolerated one are used to calculate the FOM. The machine settings are changed according to the optimizer predictions and the procedure iterated.
The most important differences of the code applied to the machine with respect to the one used in the simulations are the way of treatment of the noise and the matching of the beam optics to the design one, necessary conditions to minimize the error on the measured emittance. For the latter aspect the tool automatically changes the currents in the quadrupoles upstream of the measurement point to match the beam optics to the design one if the mismatch is larger than a threshold defined by the user in the GUI. In this way the precision of the measured emittance is optimized, introducing the mismatch with respect to the design optics as an error in the emittance reconstruction. The noise in the simulations was controlled by simply increasing the number of particles up to a level where it was tolerable. When applied to a real machine more attention has to be dedicated to this aspect. Experimentally a successful optimization was achieved considering to be above the noise only when the measured emittance differs by more than the standard deviation of the previous measurement. If this condition is not fulfilled the step size of the parameter is increased and the iteration repeated. Modifying the code to take into account for this constraint was sufficient to obtain successful results.
The test was performed after the installation of the linearizing X-band cavity at SITF, before doing any beam-based alignment (and at that time it was not possible to include the position of the X-band cavity in the optimization). The minimum geometric average of the projected emittance in the two transverse planes measured in this condition was around 0.6 mm mrad. During the measurements a feedback fixed the beam horizontal and the vertical orbit in all the rf structures to eliminate any possible emittance degradation due to the wakefields excited by the bunch passing through the structure. To have an evident test of the optimizer we intentionally degraded the emittance to about 4 mm mrad by changing the first solenoid downstream of the gun and the gun phase, and we let the code optimize the machine again. We obtained a geometric average of the emittances of 0.5 mm mrad. In Fig. 17 the FOM (defined in this case as the geometric average of the projected horizontal and vertical emittances) is plotted as a function of the iteration number.
Each measurement requires about 1 min, so that this optimization took 35 min using 7 variables to be optimized: the first solenoid downstream of the gun, the two corrector quadrupoles around it, and the four sections of the solenoid surrounding the first accelerating cavity.
It can be seen that the code brought the emittance down by a factor 8. The measured value is the minimum measured with those machine conditions, providing in this way a completely successful automatic optimization of the injector.

V. CONCLUSIONS
The tool we presented allows a fast and robust optimization of high-brightness injectors. The code demonstrates that optimizations different from the recipe given by Ferrario et al. are achievable avoiding a tedious manual process. Applied to SwissFEL within the given mechanical constraints the tool ameliorated the emittance by about 30% compared to the previous layout (a total emittance reduction of about 60% was achieved assuming the normalized intrinsic emittance measured in SITF). The new optimization provides to our knowledge the smallest emittance achievable with the given solenoid configuration. Furthermore assuming a new gun design, which allows shifting the first solenoid closer to the cathode, the optimizer identified a configuration reaching a final emittance only a few percent above the intrinsic emittance. In this case the brightness of the SwissFEL electron beam may be increased by another factor 5 for the 200 pC bunch charge case compared to the optimum working point with the PSI gun. Alternatively a shorter laser pulse length can be used to reduce the compression factor downstream in the machine, relaxing in this way the rf tolerances.
Properly modified to control the parameters of a running accelerator the code optimized successfully the performance of the SITF. For this application the tool verifies and if necessary rematches the optics at each iteration. In this particular case the FOM was given by the geometric average of the horizontal and vertical projected emittances.