Performance of the CMS hadron calorimeter with cosmic ray muons and LHC beam data