Characterization of fans and hereditarily pythagorean fields