We have studied time-resolved cathodoluminescence (CL) and electron beam induced current (EBIC) on AlGaAs/GaAs/InGaAs heterojunction phototransistors under operating conditions, i.e., at room temperature and under bias. Devices from four wafers, with a different amount of lattice relaxation, were tested. It is shown that the CL intensity increases more than one order of magnitude as the voltage is increased and the current gain of the device turns on. The voltage dependence of the CL signal is analogous to the current-voltage curve of the transistor. The buildup in CL intensity was found to be much less in devices with low current gain showing that the CL intensity correlates to the electrical gain of the device. Time resolved CL showed two distinct CL decay times, one very short, a few nanoseconds, and one long, of the order of microseconds. This indicates that two fundamental recombination processes are present, which we attribute to a spatially direct recombination between carriers in the base and a spatially indirect recombination. This spatially indirect recombination is believed to come from recombination of electrons trapped in the notch formed at the conduction band discontinuity and holes in the base. By studying EBIC as a function of beam current for devices from the different wafers we found that relaxed devices have a complex current-gain relationship. They require higher current densities than nonrelaxed devices to reach high gain. At low current densities the gain is very low and the ideality factor is high indicating a high degree of trap related recombination. At high current densities, on the other hand, these traps become filled and the associated recombination quenched. This results in a gain and an ideality factor comparable to those of nonrelaxed devices.