Beam position and energy monitoring in compact linear accelerators for radiotherapy