The 4d photoabsorption spectra of La, LaF3, Ba and BaF2: dependence on the chemical and structural environment