histogram calculation