Sensitive X-ray polarimetry in the keV energy range can be achieved by measuring the azimuthal angle distribution of emitted electrons after the photoelectric absorption of X-rays in a micropattern gas detector. However, the initial direction of the electron is not readily measurable due to the randomization of its motion during energy loss. By using the Geant4, Maxwell and Garfield packages, we simulated the detected electron tracks following photoelectric absorption, electron drift and diffusion in the gas, and proposed a technique capable of reconstructing the initial direction of the emitted photoelectron. The technique allows us to measure the angular modulation of flux predicted for a polarized X-ray beam. We calculated the modulation factors in 2-10 keV with a gas mixture of neon and CO;, and discussed how electron diffusion along the drift will dilute the track and suppress the modulation. These results are useful for the design of the X-ray polarimeter.