Emergence of coherence and the dynamics of quantum phase transitions