Cavan recovered from a 12-point deficit at half time to edge out Westmeath – managed by former Breffni County star Dermot McCabe – in an incident-packed game played on a heavy pitch in Mullingar.