Theory of the generation and detection of carriers in ultrafast photoexcitation experiments in semiconductors