# How do we know which term to attach a phase factor to in a state equation?

I need to find the state of a particle in a one-dimesional harmonic oscillator where a measurement of the energy yields the values $$\hbar\omega\over 2$$ or $$3\omega\hbar\over 2$$, each with a probability of one-half at time t. I would have thought that the state would be $$\big|\psi(0)\big>= {1\over \sqrt2}\big|0\big>+{1\over \sqrt2}\big|1\big>$$. However the right equation is $$\big|\psi(0)\big>= {1\over \sqrt2}\big|0\big>+{1\over \sqrt2}e^{-i\phi}\big|1\big>$$. I know that the $$e^{-i\phi}$$ is a relative phase factor, but I can't figure out where it came from.

Where did the phase factor come from and when do phase factors need to be applied to the terms in state equations?