NFL referees throw their hats because they have already thrown their flags and the play has not stopped yet.
The short answer is referees and officials use headgear to mark a spot on the field when the ball is in play. Since officials are separated by several yards from the point on the field they wish to...
two feet on the ground hands and ball over head its one motion
You don't get the hat back.
To indicate that he has seen a penalty committed by one or more of the players.