Gain measurement of terahertz quantum cascade laser via a masteroscillator power-amplifier configuration