Periodic orbits in magnetic fields and Ricci curvature of Lagrangian systems