Optical confinement in thin silicon films: a comprehensive ray optical theory