## 2 Materials and Methods
The camera is connected to a Raspberry Pi computer, used for data acquisition, by means of a USB cable under vacuum and a vacuum feed-through. To avoid the cable to interfere with the beam during movement, a pulley system was realized using a weight inside a vacuum pipe mounted vertically and perpendicularly with respect to the beam axis (see Figure 2, left, number 3). A thermal gap filler pad between the camera and the support allows for an optimal heat conduction and prevents overheating the CCD electronics which causes image degradation. As shown in (Figure 2, right), the full volume behind the camera was filled to optimize thermal conduction. For the beam tests of this first prototype, the beam line was terminated using an aluminum beam dump. The analysis of the images was performed using a Python software specifically developed for the \(\pi^{3}\) detector. It performs a pre-processing of the beam images to assess the beam size and position along the MBL [15]. Although the \(\pi^{3}\) detector is moving along the MBL, images of the scintillating screen are recorded at regular time intervals. To analyze the images, 2D-Gaussian distributions are fitted to each recorded 2D image. From the 2D-Gaussians, the rotation angle of the beam ellipse is calculated to obtain two projections along the two principal axes. The \(x\) and \(y\) projections are then fitted by means of a one-dimensional generalized Gaussian curve that, for \(x\), is given by the following equation:  
\[f(x)=A_{x}\cdot\exp-\left[\frac{(x-\mu_{x})^{2}}{2\sigma_{x}^{2}}\right]^{p_{x}} \tag{1}\]  
Figure 2: 3D view of the \(\pi^{3}\) detector mounted inside of the MBL beampipe (**left**). The moving support (1), the position of the motor behind the vacuum feed-through (2) and the tube for the pulley system (3) are visible. The support holds the camera that looks towards the P47 coated aluminum foil. The beam comes from the left side. The magnet system of the MBL is not shown. Details of the moving support (**right**) featuring the scintillating foil (a) and the CCD (b). where \(\mu_{x}\) gives the centroid of the beam, \(\sigma_{x}\) the standard deviation and \(p_{x}\) is a fit parameter describing the flatness of the profile. The same function was used for \(y\). The use of this function was due to the non-pure Gaussian nature of the beam. The image pre-processing includes some necessary corrections such as those related to the angle between the axis of the camera and that one perpendicular to the scintillating foil (Figure 3) and to convert the image to gray-scale. Finally, a circular mask is applied to the image to remove those parts which are not on the sensitive area of the scintillating screen. Laboratory tests were first carried out to evaluate the spatial resolution of the detector by using a laser beam. Results showed a high spatial accuracy of 0.3 mm in both the horizontal and vertical planes. In addition, conversion factors of 0.05 mm/pixel and 0.07 mm/pixel were estimated for the horizontal and vertical axis, respectively [15]. After laboratory tests, beam tests were performed using the BTL, as shown in Figure 4. To control the beam position and shape at the entrance of the MBL, the \(\pi^{2}\) detector was used. The \(\pi^{3}\) detector was mounted inside the beam pipe of the MBL. A system of vacuum valves was used to limit the air flow during pumping to avoid damage to the aluminum coated foil. Figure 4: The setup used for the beam tests at the BTL of the Bern medical cyclotron. One of the two BTL quadrupole doublets (1), the \(\pi^{2}\) detector (2), the MBL with its beam pipe containing the \(\pi^{3}\) detector (3), and the motor with the pulley and vacuum valve system (4) are visible. Figure 3: Circular scintillating screen (23.8 mm diameter, total thickness about 2 \(\upmu\)m) illuminated by the LED of the endoscope camera. The perspective angle is corrected by the pre-processing software.