Characterization of transverse modes of a laser beam: analysis and applications to a Q switched Nd:YAG laser