First-principles simulation of a photoinduced carbocation formation