Steam trains

I’ve noticed that on a lot old stream trains there is bell looking device on top of the smokestack.

Does it serve a purpose, or is it decorative?

Spark arresting chimneys

Cool, thanks.