Small-angle inelastic scattering of 40 MeV protons by 12C, 40Ca, 56Fe and 58Ni