Replica mean field theory for granular media