Do I understand correctly that classical trajectories of an electron are analogous to rays in optics?
Basically, yes. Schrödinger's guiding idea, when he arrived at its celebrated equation, was the relationship between geometric and wave optics. In particular, in a 1926 paper ( Quantization as a Problem of Proper Values-II ) he clearly explained his idea of looking at Hamilton-Jacobi's equation of Classical Mechanics as the analogous of the Eikonal approximation of undulatory theory of light. However, notice that the concept of a ray of geometric optics does not completely coincide with a particle trajectory. It should be better thought of as the evolution of a small section of a wave-front. It turns out that in many cases the evolution of such a small section looks like a classical trajectory but not always. A typical geometric optics phenomenon like the simultaneous reflection and refraction at a surface is far from the behavior of a classical particle.
Is it true that in optics rays may be considered as trajectories of photons in some sense?
Definitely not. At least, not if by photon one is meaning the entity described by Quantum Electrodynamics (QED). The reason is twofold.
- Light waves emerge as a superposition of a huge number of photons. In a way, the motion of a wave-front cannot give information about the trajectories of the individual constituents more than the water wave motion provides information about the trajectories of the individual water molecules.
- in the case of QED photons there is an additional problem connected with the problem of defining its position.