Monte-Carlo-based spectral gain analysis for terahertz quantum cascade lasers