Pull oneself together

Please, what is the origin of the expression "pull oneself together" under the meaning of gaining recomposure?

This is a total guess. People used to believe that in times of emotional upheaval, stress, etc., a person's soul could separate from his body. You could be "beside yourself." That would result in the need to "pull yourself together."

I've been falling apart ever since I learned I would not be on "American Idol." I'll have to pull myself back together. SS