The optimization of a triode electron gun with a thermionic cathode