Random error propagation on electron beam dynamics for a 50 MeV S-band linac

The stability and the quality of particle beams are of utmost importance for many emerging linac installations. The impact on beam properties damage of beam electromagnetic element misalignments and jitter/fluctuations in various accelerator sub-systems should be properly known, as usually such shot-to-shot fluctuations cannot be avoided. On top of that, knowing which parameters the machine is most sensitive to is of utmost to take precautionary measures to reduce the beam degradation and thus improve beam stability and quality. This simulation work focuses on a 50 MeV S-band linear accelerator based on RF photoinjector electron source. The sensitivity of the beam parameters towards several errors has been studied collectively as well as individually for each accelerator element. While the emittance at the end of the linac is dominated by the laminar behavior in the accelerating section, the main emittance degradation comes mainly from orbit errors located at the linac entrance.


Introduction
New linear accelerators, hundreds of MeV classes, worldwide under installation, are becoming more demanding in terms of beam dynamics, particularly regarding emittance, energy spread, and peak current. Main useful applications, strongly requested by different scientific communities are free electron laser [1,2], laser plasma wake-field acceleration [3,4], inverse Compton scattering [5], with secondary applications in imaging [6,7], x-ray crystallography [8,9], radiolysis [10], particle therapy [11], and many more. Several of these installations have very strict requirements in terms of beam performances. Thus, one very important aspect is the unavoidable random errors due to the combined misalignment of various accelerator components, jitter, and fluctuations in different accelerator subsystems, directly impacting the beam properties.
In the literature, error studies are often treated at the point of interest such as the interaction point for electron lasers [12], or in accelerator cavities and transport lines [13,14] assuming a golden beam from the electron source. In our case, we focus here on the importance of the errors from the electron source. This clearly establishes the constraints needed to implement an S-band linear accelerator based on a photoinjector.
We take here ThomX [15], a linear accelerator in its early commissioning phase at the IJC Laboratory (Orsay, France) as a basis for our error studies. It consists of a photo-injector, followed by a linear accelerating section (linac). For ThomX, it has been shown that the energy spread and the emittance are two crucial parameters influencing the spectral bandwidth of the x-rays generated as a result of the inverse Compton scattering (ICS) [16]. In addition, jitters of the beam Twiss parameters and orbit at the ring injection will induce unavoidable emittance growth. Therefore, sources of errors that impact the beam properties during acceleration should be properly evaluated. This article contains detailed simulation results and discussions on the parameters (alignment errors and jitters) influencing electron beam dynamics at the end of the S-band linac-based photoinjector source. Such studies are particularly relevant for applications that require high-level performance.
They enable understanding of limitations and beam quality sensitivity towards various accelerator elements such as laser spatial & temporal fluctuations and timing jitter. The effect of individual parameters and alignment errors are known, but additional not linearly correlated random errors, or jitter, can modify the expected global behavior putting the accelerator out of the acceptable tolerance limits. Since the beam properties are strongly correlated in a nonlinear fashion, such analysis is of crucial importance to predict beam damage due to unavoidable errors.
First, we briefly discuss the electron beam dynamics in ThomX linac that we choose as a basis for this study and list out the chosen parameters which minimize transverse emittance and energy spread for a case of 1 nC, 50 MeV electron beam at the end of the linear accelerator. Then, the various sources of errors are enlisted. To understand the limitations imposed on emittance and energy spread, the error due to each subsystem considering every single related parameter is analyzed individually. Then the overall behavior is studied with attention to the stability of the accelerator components by randomly propagating all errors together until the end of the linac. This procedure is very important to make sure that the sum of the contributions does not significantly affect the accelerator performance, i.e., beam quality and orbit. Ideas for minimizing these errors, whenever necessary and possible, are also discussed. Towards the end, we list out the conclusions from this study and we introduce a beam-based laser alignment procedure to minimize the electron beam orbit distortion at the entrance of the accelerating section.

Initial beam parameters at the linac exit
X-rays at ThomX [17] are produced as a result of the inverse Compton scattering (ICS) when a high-power infrared laser pulses are made to interact with ∼50 MeV electron bunches. These electrons are initially extracted from a photo-cathode with an ultraviolet laser pulse and are accelerated to ∼5 MeV using a 3 GHz 2.5 cells RF gun and then accelerated to higher energies (∼50 MeV) with a 3 GHz traveling wave accelerating section (ACS). These high-energy electrons are injected into a storage ring where they interact with the laser pulses and produce soft x-rays (∼45 keV) at the interaction point. Previous works [18,19] have shown that a 2 ps long (RMS) laser pulse at the cathode is the correct electron extraction time to avoid chromatic emittance increase due to inherent energy spread contribution. Moreover, to reach a flux of 10 13 ph/s of x-rays, 1 nC of charge shall be required [15]. To balance the beam transverse explosion due to space charge forces at the RF gun exit and charge limitation due to the mirror effect [20], a 0.5 mm (RMS) spot size of the laser beam was chosen. Figure 1 shows the optimized normalized beam emittance and beam envelope behavior starting from the photocathode up to the end of the linac along with the associated accelerator schematics. With the help of the focusing solenoid B3 (see figure 1), the electron beam enters at the beam waist inside the ACS in order to minimize the transverse emittance at the exit of the ACS with the so-called invariant envelope equation [21] (shown in figure 1). The main relevant parameters from the beam dynamics point of view like the normalized transverse emittance (ò), bunch transverse, and longitudinal dimensions (σ) are mentioned in table 1 at the end of the ThomX linac (6.1 m) for the ideal or 'perfect' configuration of the machine, which constitutes the targeted beam quality of our present error study.
The most relevant parameters for ThomX linac are the transverse emittance which must remain close to 4.2 π mm mrad and energy spread which must remain less than 0.25% within ±10% of their values.

Estimation of the errors
The ThomX linac has been modeled in ASTRA [22] using the electric and magnetic field profiles generated by Opera TM and HFSS ANSYS TM simulation tools based on the 3-D mechanical design of the accelerator elements. Figure 2 shows the electric field profile for the 2.5-cell RF gun and the combined magnetic field from the solenoids. To estimate the sensitivity of the ThomX linac towards various alignment errors and jitters, we used a macro-particle tracking code (ASTRA) by changing randomly the input parameters. It can be done by a script or using GIOTTO [23]. In this study, a total of 1000 random linac configurations with slightly different values of the relevant parameter are considered for each case discussed. The randomly generated parameters follow a Gaussian distribution truncated at 2σ. The errors introduced in various accelerator elements of the ThomX linac are listed in table 2. This study will characterize the beam quality deterioration induced by the error in the median of the outputs of each configuration and its interquantile range (IQR) (with quantile values corresponding to the well-known FWHM for a gaussian distribution).
Tilt and alignment errors were introduced for all accelerator elements (like a laser, solenoid, and accelerating section) except for the RF gun. We suppose that the RF gun electromagnetic axis is the reference axis for the rest of the accelerator elements. Laser fluctuations were also introduced in the simulations including the laser/RF synchronization jitter. Additionally, the accelerating gradient fluctuations in the RF structures and magnetic field fluctuations were also taken into account.
The alignment errors of 100 μm (RMS) [24] are all with respect to the RF gun and are justifiable if one uses the laser tracking-based alignment for the accelerator elements, as done with almost all accelerators as a basis. The rotational tilts are estimated based on the physical dimensions of the accelerator elements for a peripheral shift of 100 μm (RMS). The 0.1% RF peak field or gradient fluctuations in the RF cavities are in accordance with the element manufacturers, also considering power supply specifications. The same for the solenoids is one order more precise. The phase jitter between the RF gun and ACS is considered to be 1 ps [25]. This value is quite high compared to the state-of-the-art [26].
The pointing instability for the incident laser would depend on the optics configuration and the building stability (in terms of infrastructures, temperature, and hydrometry) from the laser chamber up to the photocathode. For the purpose of this article, the pointing instability has been assumed close to what we measured at  another electron beam test facility at IJCLab for a similar laser spot size at the cathode. Similarly, the fluctuations in the laser spot size were measured and the same value of 2% is used. The value for the fluctuations in the laser pulse width was provided by the manufacturer of the commercial laser system, Amplitude s-pulse HP 2 to be used for ThomX. The jitter in the arrival of the laser pulse at the cathode is capped by the synchronization jitter between the RF and the laser pulse [26].

Individual error studies
This section focuses on determining if the random errors and fluctuations mentioned in table 2 for the linear accelerator-based photoinjector source are small enough to preserve the beam properties in the context of nonlinear correlation due to collective effects such as space charge, and also beam orbit induced in the photoinjector with a fast energy increase from rest mass to almost relativistic energies. For this purpose, we first present the individual effect of each of the parameters listed in table 2 separately and within their groups to highlight the most relevant or dominant parameters. As we introduced asymmetry in the horizontal and vertical directions, we introduced the following quantity to evaluate the normalized emittance under errors: Then ò and the energy spread (σ E ) are obtained at the end of the linac for a total of 1000 random linac configurations within the listed errors for each case presented hereafter. Each linac configuration within one random set of parameters is also called in this paper machine. For each case, the histogram of the emittance and energy spread of the 1000 random machines will be presented and discussed. The vertical axis is then the number of random machines i. e linac configuration set, called in all the following figures number of configurations (no. of configs).

RF gun
As mentioned earlier, the alignment of all other accelerator elements is considered with respect to the axis of the RF gun, we only have the electric field gradient fluctuations to consider for this case. Figure 3 shows a histogram of the resulting normalized transverse emittance (ò) at the end of linac (6.1 m away from the cathode) for the 1000 random machines considering 0.1% gradient fluctuations inside the RF gun due to fluctuations in the high-voltage power supply. A fluctuation of the electric field gradient changes at worst 3% of the emittance and 0.85% of the energy spread. The vertical axis is then the number of random machines per bin called in all the following figures as a number of configurations (No. of configs). A small improvement in emittance up to 1.5% at the end of the linac is a result of the change of the beam energy, which in turn modifies the electron beam transport (for example, beam waist at the ACS entrance) and also the space charge effects, particularly significant inside the RF gun. Concerning the energy spread, as expected the variation induced by the 0.1% error in the accelerating gradient is below 1%. In any case, the gun gradient error has very few effects on the parameters.

Laser pulse
A well-known assumption is that the initial electron bunch has the same 3D shape of the incident laser pulse on the photo-cathode if laser pulses are longer than the time response of the cathode material. So, if the incident laser pulse properties fluctuate in time, it could induce shot-to-shot fluctuations in the extracted electron bunch. The sensitivity of transverse emittance and energy spread towards the fluctuations related to the incident laser pulse are investigated in this subsection using the parameters introduced in table 2. The phase jitter between the RF gun electric field and the arrival of the laser at the cathode is also considered in this subsection. Figure 4 shows the percentage change in the normalized transverse emittance and energy spread due to the laser error or fluctuations. The most important laser characteristic turns out to be the pointing stability, which can increase the emittance at the end of ACS by 10%. In the case of laser pointing instabilities (offset in the legend of figure 4), the emittance increase is a consequence of the fact that the extracted electrons from the cathode are not aligned with the axis of the RF gun, solenoids, and accelerating section. Such precise laser alignment is not so trivial. This is explained later in this subsection. A relatively smaller change in emittance due to spot size fluctuations is due to the change in space charge forces, which in turn modifies the beam transport all along the beamline.  The laser intensity and spot size fluctuations at the cathode directly impact the beam energy spread through variations in the extracted charge and initial electron transverse dimensions. A 5% (RMS) fluctuation in the extracted charge can change the relative energy spread at the end of ACS by 5% (RMS). These changes act on the overall electron beam transport mainly via the space charge forces and focusing, up to the end of the linac The energy spread at the exit of the ACS is also dependent on the initial bunch length at the entrance of the section. A simple expression is obtained for the standing wave RF gun [27], showing that energy spread is linked to the initial bunch length (or laser pulse duration).
As we have seen from these results, spot size fluctuations play a very crucial role in beam dynamics optimization. In fact, spot size at the cathode modifies the focusing at the entrance of the ACS, and thus the output emittance. In addition, space charge effects are also modified according to size. Thus during optimization, an optimal value of the laser spot size was chosen so as to keep both emittance and relative energy spread within the allowed tolerances. A small decrease (∼5%) in emittance due to the spot size fluctuations is merely a consequence of this trade-off between emittance and energy spread.
In the end, all the combined error gives a median increase of the emittance of 3.5% with an IQR of 7.1%. An asymmetry is introduced by the offset, which gives in any case the worst emittance. In combination with the other errors, the emittance can be slightly improved. The energy spread has the maximum probability of not being affected by errors with an IQR of 14.3% fluctuation. The spread is dominated by the combination of all quantities affecting the charge density.
As seen from the error simulations, a good laser alignment at the photocathode avoids electron-beam orbit distortions at the linac entrance with consequent emittance degradation but also limits the use of correctors or kickers. As explained above, this helps in reducing emittance growth by keeping the electron beam aligned with the electromagnetic axis of the accelerator components ensuring an orbit independent of the energy tuning. To achieve this, we will use the measurement of extracted charge at the RF gun exit versus the RF phase (without solenoids to decouple the orbit errors) as shown in figure 5(ii). Depending on the RF phase, the electric field amplitude at the cathode experienced by the photo-electrons changes. In addition, to the beam properties such as energy ( Figure 5(i)), energy spread, transverse dimensions (figure 5(iii)), and emittance, the extracted charge also changes as the maximum electric field at the cathode changes with RF phase. In fact, the RF voltage lowers the average potential barriers for the electrons in the metal, called the Schottky effect. Hence, the maximum charge is extracted when the field at the cathode is the highest. Now, as the electrons go from a few electron volts of energy at the cathode to quasi-relativistic at the photo-injector exit, electrons encounter a phase slippage along their propagation inside the RF gun. As a consequence of this, the RF phase that maximizes the extracted charge (or electric field) at the cathode is not the same as the one maximizing the energy gain for the electrons. This phase difference can easily be estimated by using simple tracking simulations or modeling [27] and depends on the accelerating gradient. The phase slippage is reduced as the accelerating voltage (or gradient) increases.
During experiments, this difference could be used as a first simple diagnostic to tune the RF phase that maximizes the energy gain. Actually, most photo-injector installations have a classical charge measurement diagnostic as an ICT at the photo-injector exit. To avoid additional orbit coupling, this kind of measurement is preferably done without any focusing elements, as these may lead to additional charge losses through kicks.
This measurement serves also as a reference for the laser alignment at the cathode in the following manner. We take advantage of the radial force coming from the non-zero radial electric field component inside the RF gun. Indeed, the electron beam encounters a different focus depending on the RF phase. The maximum focusing is observed at the RF phase which maximizes the extracted charge as it is shown in figure 5(iii) in the zone delimited by the vertical dashed lines. Then, the loss of charge due to laser misalignment is more sensitive in this zone. As a consequence, the width of the charge phase measurement gives information on the rough laser alignment (above 3 mm). Actually, if the laser alignment is far from the electromagnetic axis of the RF gun (on the order of a few mm), the width of the charge phase is reduced. When the width of the charge-phase curve is close to the estimated value, the fine-tuning of the laser alignment can be done with the variation of the beam centroid at the gun exit with the help of a screen (see figure 5(iv)). The electron beam is expected to be kicked radially if it is off-axis with respect to the electromagnetic axis of the RF gun. This kick is, for small misalignments, proportional to the transverse displacement of the electron beam. Then, the behavior of the beam centroid at the RF gun exit (without any other RF or magnetic components) is directly proportional to the offset of the laser on the cathode for a given phase difference. An offset of 30 μm on the laser gives a centroid displacement, which can be easily measured on a conventional screen. A precise remotely-controlled mirror mount can then be used to slightly move the laser on the cathode to reduce the displacement of the centroid of the electron beam while changing the RF phase. Such on-the-fly laser and electron beam tuning not only avoids RF phase-dependent orbit correction but also helps to obtain the highest on-axis electron beam acceleration.

Solenoid
In this subsection, we consider the errors originating from the solenoid misalignments and field fluctuations as listed in table 2. Figure 6 (i) shows the results obtained for the transverse emittance. The relative change in the energy spread is not shown here as it is not much affected (<1%) by the solenoid errors within the listed ranges. In fact, the solenoid magnetic field amplitude fluctuations considered according to the power supply specifications are small enough not to affect the beam size significantly. As a result, space charge density is not notably modified and thus energy spread remains almost the same. Also, the beam waist condition for the laminar regime at the entrance of the ACS is not affected and the emittance at the linac exit remains the same if only errors due to magnetic field amplitude fluctuations are considered. The emittance in this case is most sensitive to the alignment errors: translation and rotation. These errors just like the offset for the laser case discussed in the previous subsection, always tend to increase the emittance value. This is the reason for the asymmetry observed in the histograms of figures 6 and 4 because misalignment will always damage the emittance compared to the nominal value (for the perfect machine).
The effects of the translation misalignment, referred to as offset in the figure and of rotational misalignment, referred to as tilt, are similar. They result in an increase in transverse emittance of ∼2% (see figure 6(i)) and a distance of the reference axis to the position of the electron beam at the linac exit of ∼2.5 mm. (see figure 6(ii)). For this reason, it is needful to realize a very precise beam-based alignment of the solenoids to achieve a very high accuracy as it is one of the limiting factors for emittance preservation. After the laser alignment is done, the beam-based solenoid alignment can be done. In contrast to the beam-based laser alignment, misalignment of the solenoid with respect to the electromagnetic axis of the RF gun introduces coupling between the horizontal and vertical axis as shown in figure 7.
Several methods have already been highlighted in the literature [28][29][30] for precisely controlling optics alignment.

ACS
For the accelerating section, phase jitter, accelerating gradient, and misalignment have been studied. Unlike the RF gun case, the electric field gradient fluctuations have almost no effect here, as the beam is more rigid in terms of energy. Also, the gradient is less important (14 MV m −1 against 80 MV m −1 for the RF gun) as it is a traveling wave accelerating structure. The rotational tilts are also not very important for the ACS as the section is much longer than the RF gun or the solenoids and tilts for the ACS were calculated for the same alignment precision at the entrance and the exit.  The most important beam dynamics characteristic affected by the phase jitter inside the ACS is the energy spread (see figure 8). As highlighted by the histogram, the linac is nearly tuned for energy spread minimization as a few cases slightly improve it.
In fact, for a traveling wave ACS [31] the behavior of the energy spread versus the RF phase is a sinus-like function whose amplitude depends on the energy gain in the section, length of the accelerating section, RF frequency, and the initial electron bunch length. In our case, with a L = 4.5 m long, f = 3 GHz TW ACS, with an energy gain of E m = 14 MV m −1 and a bunch length of 3.7 t i s = ps at the entrance of the section, change in the energy spread can go up to 50%, if the energy spread at the entrance is low (∼50 keV).
It should be noted that jitter of 1.0 ps (rms) or approx ±4 ps (peak to peak) for the RF phase is huge compared to the state of the art which is of the order of a few hundreds of femtoseconds [32]. For 1 ps of jitter (peak to peak), which is achievable with electronic components, the maximum increase of energy spread remains in the acceptable range of 10%.
As expected, the phase jitter has almost no effect on emittance (less than 2%). Figure 9 shows the histograms of the emittance and energy spread at the end of the linac of the 1000 combined random error of all parameters listed in table 2. The emittance ò from equation (1) is shifted in the median by 4.3%, which is within the acceptable tolerances. As expected, the maximum probability shift is not the sum of all sub-system contributions as the overall system is correlated in a non-linear way. The profile is asymmetric and dominated by the misalignment errors coming from the laser and the solenoid. IQR of the histogram is 9%, which corresponds almost to the sum of each sub-system's contributions (see table 3) whereas each sub-systems was dominated by one of their individual errors. As the solenoid misalignment is not a fluctuation, it can be retrieved with beam-based alignments procedure, whereas the laser contribution comes from shot-to-shot fluctuations. The energy spread is shifted in the median by 4.4% of its value with an IQR of 29.4% and is also the sum of each sub-system contribution, with a main contribution coming from the laser and accelerating section coming from the phase jitter, which can be smaller than the case taken there. As seen in previous sections, the sources of error for energy spread and emittance are not the same, and they do not act in the same way in the distributions of errors introducing asymmetry. To end we highlight the orbit error at the end of linac, which takes origin at the accelerator injector due to laser jitters and solenoid misalignment (see figure 9(iii). The electron source is the key to optimize the electron beam properties and to minimize the errors at the end of the linac.

All together: a practical machine!
We also summarize changes in the other parameters due to the listed sources of errors (see table 3). It enables us to keep the beam energy with a 0.2% (100 keV) energy variation mainly due to the phase jitter of the accelerating section i.e. keeping the beam inside the dedicated screen station in the dispersive section after the linac.
We have an estimate of the error for the Twiss parameters at the entrance of the transfer line and then the error in the matching condition at the ring entrance. The total error is not the sum of the individual contributions as the Twiss parameters are calculated from different parameters. The overall contribution is less than the individual contributions. The variation of the bunch length is small, within 10%.
In other words, such a study reveals the parameter(s) to which the machine is most sensitive. It is possible to determine if various alignment errors and jitters are well within the acceptable tolerance levels for the machine. If not, then it is possible to know which parameter(s) should be corrected so that we are within the set level of tolerance. Figure 9. Sensitivity of (i) norm. transverse emittance ò from equation (1)) and (ii) relative energy spread (σ E ) and (iii) distance of electron beam barycenter from the reference axis towards all the misalignment and jitters mentioned in table 2. The width, and the position of bins have been adjusted in order to have comparable peak intensity distribution with a sum equal to 1000 runs. Table 3. Variations of the parameters of the beam in different error conditions listed in Table 2. The first number gives the median of the percentage of variation of the parameters and the second relates the InterQuantile Range (IQR) (with quantiles 0.12 and 0.88 to match FWHM for a gaussian distribution). ò equation (1), σ E energy spread, E mean energy, σ t bunch length, β and γ function of the Twiss parameters.

Conclusions
A systematic study of misalignment errors and jitter of a 3 GHz S-band linac-based photoinjector source has been presented in this article with the aim to estimate the allowed tolerances on the emittance and energy spread at the end of a 3 GHz linac Such holistic studies help to quantify the parameter(s) which the machine is most sensitive and help plan for the precautionary measures (diagnostics, appropriate component mounts, etc...) in advance to keep beam properties within the allowed tolerances. The results and conclusions obtained in this paper can be generalized to linear accelerators with photoemitted electron source (DC or RF). The main source of limitation comes from the electron source i.e. laser used for photoemission and the solenoid for emittance compensation.
As a consequence, beam-based alignment of solenoids has to be implemented to limit the alignment errors as well as orbit correction along the linac Similarly, a relay imaging combined with a feedback system could be used to stabilize the laser pointing fluctuations at the photocathode [33]. We also show that beam-based alignment is very powerful even for laser alignment below its pointing stability. In some of the presented cases above, we see an improvement of the transverse emittance, but most of the time it is just an artifact of either the reduced electron charge or a variation in energy. As we started from an already well-optimized machine configuration no matter what we do, we always tend to increase the emittance values.
Further, the relative energy spread at the linac exit is most affected by the RF phase jitter in the accelerating section. This is one of the reasons why it is often suggested to use a single klystron to feed both the RF gun and the accelerating section (as is at CLEAR electron beam test facility at CERN, Geneva [34]). Nonetheless, we shall try to reduce the electronic jitter to bring it within 1 ps (peak-to-peak).

Limitations in Astra simulations code for small error variation
Astra is a well-benchmarked tracking simulation code. However, during this study, we encountered some limitations when the variation of the variable of interest was very low. These limitations are well-represented in the case of the RF gun gradient error study in section 4.1. Indeed, as seen in figure 9, the change in the relative energy spread is the smallest variation case in our work. To highlight these limitations, we will first study the impact of the number of macroparticles on the simulation outputs and show that the number of 10 000 macroparticles is relevant to our study. Then we will highlight the behavior of the energy and energy spread versus the RF gun gradient, which exhibits unexpected numerical behaviors.

Method
This study has been performed using Astra V3.2. As a new version of Astra (V4.0) has been released during the final steps of this work, a few simulations have been done, confirming the limitations observed in the V3.2 one. Each figure is the result of 1000 simulations. The input files (one for the generator program and one for the Astra program) are generated with a Python script so that they have the desired distributions. The generator program and the Astra program are then run consecutively. For each simulation, the Xemit, Yemit, and Zemit files are saved along with the final particle distribution.
From the particle distribution, we recompute the mean energy as the average of the kinetic energy of all the macro particles, weighted by their charge: The energy spread is the standard deviation of the energy, weighted by the charge.

Limitations due to the number of macroparticles
In this section, we are interested in the intrinsic statistical error of RMS energy spread and emittance due to the number of macroparticles. To determine the ideal ratio computing time/number of macroparticles, while minimizing the intrinsic error, we did various simulations with the same set of parameters by increasing the number of macroparticles. In the interest of studying a wide range of a number of macroparticles, we launched 1000 runs with a number of macroparticles following a log-uniform distribution between 1000 and 100 000 macroparticles. The results are shown in figure 10. The spread of the output values is more important for a few macroparticles as expected. A saturation occurs around 10 000 macroparticles, value chosen for the study of this paper. However, the spread remains and defines what is called the intrinsic error of the random simulations. For 10 000 macroparticles the intrinsic error of the energy spread is 0.5 keV rms, and for the emittance 0.01 π mm mrad. The case 0.1 % of rf gradient variation is at the intrinsic limit of the simulations. So, the limitations we show in the next paragraph are in conditions below the intrinsic error. It has then no incidence on the results of the paper which are highest than the intrinsic errors. Nevertheless, it can be an input to improve the Astra computing.

Output precision limitations
Let us now look at the energy and energy spread behavior versus the RF gun gradient. As shown in figure 11(i), the energy variation versus the RF gun gradient is smooth at the gun exit. In contrast, as shown in the figure 11(ii) on the right plot, the variation of the beam energy as a function of the gun gradient shows discontinuities at the accelerating section exit. The blue curve is realized by taking the output of the Astra code in the Zemit files. In this case, a band at constant energy appears rounding at the 4th digit of energy (blue curve). These bands are due to the limitation clearly stated in the Astra manual as the output precision is significant 4 digits after the comma (Astra manual, p26). The Zemit result is compared to the direct calculation of the values of interest from the 10 000 macroparticle distribution (orange curve) also given by Astra with a precision of 12 significant digits (Astra manual, p2) in high-resolution mode (4 in the default mode). This curve follows the behavior of the Zemit one without horizontal lines (corresponding to the resolution) but still shows discontinuities even in high-resolution mode. A linear behavior should have been observed according to the physical phenomena. This observation suggests a truncation in the integration computation of the equations of motion. This may result in a possible truncation in the calculated energy which appears in the keV range.
Several settings have been made in the input files to understand the dependency of these jumps that appear from the distribution analysis. As explained in the previous section, these jumps remain present even if we multiply the number of macroparticles (by 10). So it is not related to statistical analysis. The decrease of the parameter H max until 1 fs (Hmin being set at 0), which represents the maximum time step for the Runge-Kutta integrator, does not improve the situation either. All our simulations are also made in high-resolution mode.
To end we present the same results for the energy spread behavior (see figure 12). Stripes are also highlighted. But there is no influence on the output file resolution as the results are exactly the same for zemit, scan or from the particles coordinate analysis.
The effects we have observed are limited to small energy variations of the order of keV and will not affect the simulations that have been done here. Nevertheless, it seems important to us to notify it to raise a potential limitation in the Astra simulation code for very small error variations. Figure 10. (i) Energy spread from Zemit file at the output of the accelerating section for 1000 runs with a randomly generated number of macro particles following a log-uniform distribution. (ii) Emittance from Zemit file at the output of the accelerating section for 1000 runs with a randomly generated number of macro particles following a log-uniform distribution.