# An Active Irradiation System with Automatic Beam Positioning and Focusing for a Medical Cyclotron
## 2 Materials and Methods
At the first step, the selected magnet current is varied around the starting point by adding and subtracting a coarse amount (typically \(\pm 1\) A). This allows to individuate the right direction for optimization. The current corresponding to the highest value of the optimization parameter is retained for the second step when two further variations are applied, whose size depends on the outcome of the first step. Beam profiles are measured at each successive step and, at the end of the procedure, the applied variations become smaller and smaller down to a user defined minimum. At each step, two variations are applied. They are allowed to be both positive, both negative or one negative and one positive. The choice is made on the basis of the previous step. Figure 4 shows two examples of the optimization procedure, where the steps are highlighted. It has to be noted that the optimization parameter as a function of the magnet currents was found to be continuous, as needed for an optimization procedure. The AFS optimizes the beam on the basis of the measurement of the beam profiles performed by the two-dimensional UniBeaM detector located about 30 cm upstream with respect to the target. It is therefore necessary to predict the size and position of the beam on target by means of calculations based on the Twiss parameters \(\alpha\), \(\beta\) and \(\gamma\), which are functions of the beam along the MBL. The Twiss parameters were assessed by measuring  
Figure 4: Examples of the optimization process for one quadrupole (**left**) and one steering magnet (**right**). The succession of the steps with the corresponding magnet current variations is highlighted. the variation of the beam profile as a function of the gradient of the downstream quadrupole magnet, as described in Ref. [18], where the beam dynamics of the BTL was studied in detail. To estimate the size of the beam on target, we introduce a scaling factor \(f\) as the ratio between the standard deviation of the beam at the position of the UniBeaM (\(\sigma_{UB}\)) and on target (\(\sigma_{target}\)). Using beam dynamics equations, one gets  
\[f\ =\ \frac{\sigma_{target}}{\sigma_{UB}}\ =\ \sqrt{L^{2}\cdot\frac{\gamma_{UB}}{ \beta_{UB}}\ -\ 2\cdot L\cdot\frac{\alpha_{UB}}{\beta_{UB}}\ +\ 1}, \tag{1}\]  
where \(L\) represents the distance between the UniBeaM and the target and the Twiss parameters are evaluated at the position of the UniBeaM. As far as the position is concerned, the horizontal shift \(\Delta x\) of the beam profile centroid between the UniBeaM and the target can be estimated for small angles by using the formula:  
\[\Delta x\ =\ \frac{q(\int B(l)dl)c}{\sqrt{E_{kin}^{2}\ +\ 2E_{kin}mc^{2}}}\cdot L, \tag{2}\]  
where \(q\) is the elementary electric charge, \(c\) the speed of light, \(B(l)\) the magnetic field profile within the MBL along the beam axis and \(dl\) an infinitesimal element along this line. \(B(l)\) was accurately measured by means of a Hall probe. Finally, \(E_{kin}\) is the kinetic energy of the proton and \(m\) its mass. An analogous function is used for the vertical shift \(\Delta y\). Equation (2) can be derived from the equations of motion of a charged particle in a magnetic field. A typical value of \(f\) is 0.1, which means that the beam is 10 times smaller on target with respect to what is measured by the UniBeaM. For \(\Delta x\) and \(\Delta y\) the correction is of a few millimeters.