A linear accelerator, comprising: an accelerator structure having an electron injection point and defining an electron flow path from said electron injection point; an electron gun, for injecting electrons to the accelerator structure at the electron injection point, comprising: i. a cathode, for generating electrons; ii. an anode; and iii. an intermediate electrode, located between the cathode and the anode; a source of microwaves, operatively connected to the accelerator structure; a current meter; and a controller comprising at least one voltage source, adapted to: a) perform at least one of the following: measuring a current required to charge the intermediate electrode to an electrical potential by applying a direct voltage to the intermediate electrode and detecting with the current meter the current flowing between the voltage source and the intermediate electrode; and applying an alternating voltage to said intermediate electrode and measuring a ripple current caused by said alternating voltage with said current meter; b) determine from said current or said ripple current whether or not said intermediate electrode is correctly connected to its voltage source; and c) control the electron gun and the microwave source to emit pulses of electrons and microwaves respectively, timed such that said pulse of electrons is accelerated along the electron flow path. an accelerator structure having an electron injection point and defining an electron flow path from said electron injection point; an electron gun, for injecting electrons to the accelerator structure at the electron injection point, comprising: i. a cathode, for generating electrons; ii. an anode; and iii. an intermediate electrode, located between the cathode and the anode; i. a cathode, for generating electrons; ii. an anode; and iii. an intermediate electrode, located between the cathode and the anode; a source of microwaves, operatively connected to the accelerator structure; a current meter; and a controller comprising at least one voltage source, adapted to: a) perform at least one of the following: measuring a current required to charge the intermediate electrode to an electrical potential by applying a direct voltage to the intermediate electrode and detecting with the current meter the current flowing between the voltage source and the intermediate electrode; and applying an alternating voltage to said intermediate electrode and measuring a ripple current caused by said alternating voltage with said current meter; b) determine from said current or said ripple current whether or not said intermediate electrode is correctly connected to its voltage source; and c) control the electron gun and the microwave source to emit pulses of electrons and microwaves respectively, timed such that said pulse of electrons is accelerated along the electron flow path. a) perform at least one of the following: measuring a current required to charge the intermediate electrode to an electrical potential by applying a direct voltage to the intermediate electrode and detecting with the current meter the current flowing between the voltage source and the intermediate electrode; and applying an alternating voltage to said intermediate electrode and measuring a ripple current caused by said alternating voltage with said current meter; measuring a current required to charge the intermediate electrode to an electrical potential by applying a direct voltage to the intermediate electrode and detecting with the current meter the current flowing between the voltage source and the intermediate electrode; and applying an alternating voltage to said intermediate electrode and measuring a ripple current caused by said alternating voltage with said current meter; b) determine from said current or said ripple current whether or not said intermediate electrode is correctly connected to its voltage source; and c) control the electron gun and the microwave source to emit pulses of electrons and microwaves respectively, timed such that said pulse of electrons is accelerated along the electron flow path.