The cavity method for quantum disordered systems: from transverse random field ferromagnets to directed polymers in random media