Gain and noise in rare-earth-doped optical fibers