Generating real xray beam

Are you interested in the beam formation or just in the resulting spectrum? You can make an x-ray tube, see this post. But it will be inefficient in terms of computational time since x-ray tubs are not very efficient per electron (they compensate with a lot of beam current).

If you want to use the x-ray spectrum for some other purpose you could just generate the spectrum, also in that link, and then use the particle gun to emit photons sampled from that energy distribution in a particular direction. See this.