## 4 Materials and Methods  
### Quadrupole Magnets  
Each magnetic quadrupole comprises 4 permanent neodymium-based magnets of a \(25\times 12\times 4\) mm\({}^{3}\) dimension with a nominal surface field of 1.2 T. The magnets are arranged with the field alternatively oriented in a soft iron frame of a \(40\times 40\times 25\) mm\({}^{3}\) dimension to gives a quadrupole field at the first order. This represents the simplest quadrupole design allowing, at the same time, for the largest effective free aperture. However, in the case of a square aperture bounded of permanent magnets, the quadrupole field cannot be  
Figure 8: Measurements with EBT3 radiochromic films and comparison with simulation: (**a**) Proton beam cross section calculated with a GEANT4 toolkit: (**b**) EBT3 measurement at 1 cm from Kapton window (8 shots); (**c**) EBT3 measurement at 4 cm after the Kapton window (15 shots). The lower scale bar applies to both EBT3 film images. In (**b**), the shadow from a metal wire is present. The contrast in (**c**) has been altered for better visualization of the image.  
approximated as an ideal field as the equipotential surfaces are not hyperbolic. For this reason, the actual field has been carefully measured and then simulated to obtain a proper approximation of the relative multipole field expansion.  
The orthogonal component of the magnetic field has been measured using a Hall probe along parallel paths taken at different distances from the entrance. Using these results as matching points, the complete 3D field has been simulated using Radia [44; 45], a software package build in C++ and interfaced with Mathematica (Wolfram Research). The focusing/defocusing properties of each device has been preliminary calculated using [46]:  
\[f_{c}=1/k\sin(kL)\simeq 8.4\ \text{cm},\qquad f_{d}=-1/k\sinh(kL)\simeq-7.4\ \text{cm} \tag{1}\]  
for focusing and defocusing length respectively, where \(k=(q\partial_{x}B_{x}/p)^{1/2}\) was calculated for 3-MeV protons with \(q\) and \(p\) the proton charge and momentum, respectively. The considered transverse gradient was \(\partial_{x}B_{x}=110\ \text{T}/\text{m}\) while \(L=25\ \text{mm}\) is the longitudinal quadrupole length. In terms of these parameters, the whole design of the magnetic line, which is made of six elements, has been roughly defined according to the classical thick lens equation. The preliminary design takes into account that it is possible (in ideal conditions) to localize a monoenergetic bunch in the same point in both orthogonal planes using a combination of identical devices. This properties follows from \((kL)^{2}\simeq 0.35\
ot\leqslant 1\), which implies remarkably different focal lengths \(f_{c}\
ot\simeq-f_{d}\) (see Equation (1)). Clearly, the whole guiding system remains intrinsically astigmatic as the case of the thin lens approximation. Finally, the fine optimization has been obtained through several tests performed with GEANT4, in which an analytical model for the 3D magnetic field has been implemented to take into account the fringe field. An analytical approximation has been chosen instead of the complete Radia fields in order to drastically speed up the simulation process. No relevant differences has been observed in the final results considering a realistic protons bunch. In more detail, the transverse component of the field was used \(B_{\perp}=A(B_{x},0,B_{z})\), where \(A\) is a supergaussian amplitude, while the \(B_{x,z}\) components are given by:  
\[\begin{split} B_{x}&=\left(K_{0}-\tfrac{K_{1}}{2}z^{ 4}\right)x+\left(K_{1}z^{2}-\tfrac{K_{1}}{10}x^{2}\right)x^{3},\\ B_{z}&=-\left(K_{0}-\tfrac{K_{1}}{2}x^{4}\right)z- \left(K_{1}x^{2}-\tfrac{K_{1}}{10}z^{2}\right)z^{3},\end{split} \tag{2}\]  
where \(k_{0}\) and \(k_{1}\) are free fit parameters. Expressions (2) can be directly obtained trough a Taylor's expansions considering a square symmetry and the divergenceless and irrotational conditions on the fields.