https://peeterjoot.com/2018/10/25/hamiltonian-for-the-non-homogeneous-klein-gordon-equation/
Hamiltonian for the non-homogeneous Klein-Gordon equation