Photon echoes stimulated from an accumulated grating: Theory of generation and detection