The ac Stark shifts of the terahertz clock transitions of barium