Of course, pheromones play an important role in regulating these very different ways of reacting to their environment. The ants, as a colony, are roughly in synch with each other in terms of level of excitement. You can watch a state of alarm spread from one ant to the next when something upsets just one of them.
But, if the upsetting stimulus fails to persist the ants will start grooming, and that spreads too across the group. Once the grooming is done the ants resume their calm collecting.