Theory of ring imaging Cherenkov counters