calculate hessian