Charge states of relativistic heavy ions in matter