Determination of the EM field in Q-switched laser resonators