An optimal control problem in photoacoustic tomography