Calculating thermodynamics properties of classical and quantum systems by a metadynamics Monte Carlo procedure