Some imaging optical systems include diffraction elements, both the even reflected stray light and multi-order diffraction stray light need to be considered at the image. They are related to the reflectivity and diffraction efficiency of optical surfaces. In this paper the binary tree is employed to describe the multifurcating tree in which each sampling ray’s information is kept. According to the multi-order diffraction efficiency, paraxial ray and real sampling rays are traced, and the calculating results are applied to analyze the stray light in optical systems including diffraction components, and then the stray light energy distribution at any space especially at the image can be obtained. A new calculated wavelength is used to replace the designing wavelength for binary optical elements to calculate the reflected diffraction stray light. Based on the principles above, the stray light analysis software is developed. By tracing and analyzing all sampling rays the positions of ghosts are shown, especially at image surface. In this procedure, the first surface of the system serves as the entrance pupil or stop, instead of the entrance pupil in original imaging system, so as to collect all sampling rays from all direction, in or out the field of view, and then all possible ghosts are obtained. According to the simulation, the glare shields or control methods can be designed.