Microscopic mechanism for transient population inversion and optical gain in graphene