Eugene Laverty won race two at Laguna Seca to maintain hopes of winning the World Superbike Championship.