D. Minnich:
The 'parts that look like derby hats' on top of a steam locomotive boiler are known as 'domes'. One dome is known as the 'steam dome'. It is a cylindrical projection off the boiler, made as part of the actual boiler shell (known as a 'pressure vessel'). The steam dome was used to collect the steam from within the barrel (the horizontal cylindrical portion of the boiler). The 'flashing' action where steam bubbles come off the water within a boiler is quite violent, and droplets of water are initially carried up with the steam. The danger is the droplets of water could be carried along into the engine's cylinders ( a condition known as 'priming'). If enough water is carried into an engine's cylinders, the result could be damage in the form of a knocked-off cylinder head, or a bent piston rod and broken rings. The steam dome was a collection point for the steam and gave a bit of space for water carried up with the steam to drop back down into the boiler barrel. In addition, on most steam locomotives, particularly older ones, the throttle valve was located up in the steam dome. Atop the steam dome there is a bolted cover. This is a manway and gives access into the boiler barrel (gotta be a very limber individual and not claustrophobic).
The steam dome would be made using the same riveted construction as the boiler. The 'derby hat' was a sheet-metal cover. A locomotive builder would deep-draw these sheet metal dome jacketings. A backshop might well have sheet-metal workers who could repair a dented sheet metal dome cover. In the worst case, they would 'raise' a cover out of flat sheet steel by hand hammering methods. Once oxyacetylene welding took hold, making a dome jacketing became a lot easier as it could be pieced together.
The other dome on top of a steam locomotive boiler was the 'sand dome'. This was usually an iron casting with a top cover. It 'saddled' onto the boiler barrel, but had no connection into the actual barrel. The sand dome was sometimes called a 'sand box'. It held a quantity of sand. On either side of the sand dome, at its base, were 'air sanders'. These were 'ejector' type devices which used compressed air (from the braking system) to convey the sand from the dome down thru pipes. These pipes ('sand pipes') were used to shoot the sand ahead of behind the drive wheels, onto the rails. The sand was used to improve traction or stop wheel slip on the rails.
A steam locomotive relies on 'adhesion' between the tires on the drive wheels and the rails to transfer the power to pull itself and a train behind it. Adhesion is an interesting sub topic. The top of the rails is not entirely flat and the drive wheel tires have a slight taper to them. If we recall out early schooling in geometry, we may remember learning that the theoretical contact area between a circle and a line tangent to it is a point. In practicality, such as considering a steam locomotive drive wheel (known as a 'driver') tire contacting a rail, there is not much area. Get a rail that is wet or greasy and a train that needs to be started from a standstill, and it is almost a sure bet the drivers will slip. Sand is applied to increase traction, since adhesion by itself won't break the train loose. Hence, the sand dome on a locomotive.
BTW: engine terminals and roundhouses usually had a separate 'sand house'. This was a building with a hopper where sand was stored to fill the domes. In the sand house, there was usually a 'sand stove'. This was a large coal fired stove with a round cast iron hopper on top of it, and often some sort of agitator. This hopper on the sand stove was kept filled with sand and the agitator was cranked to 'turn over the sand'. In smaller engine terminals, the sand from the sand stove was moved in buckets to fill the sand domes on the engines. The sand needed to be dry, since wet or damp sand would pack together in the dome and the air sanders would not pull it in and move it down to the drivers. The engineers had air sander valves in the engine cabs. The valves had two positions: to put sand in front of or behind the driver treads depending if the engine was moving forward or backing.
In larger engine terminals, the sand house was located up high and there was a sand spout pipe. This allowed the hostlers (men who moved locomotives in and around the yards for service between runs) to fill the sand domes quickly and easily.
Another bit of bygone lore: hoboes and other persons riding the rails would often find the sand houses in cold rainy or winter weather as a place to warm up or sleep.
The sand domes had a cast iron cover that lifted off to allow the domes to be filled with sand. If the sand got wet or damp, there was a job to scoop the sand out of the some and take a wire and try to clear things so the sanders could work. Nowadays, a product known as "Black Beauty"- a crushed slag product used for abrasive blasting- is often used in place of sand on some locomotives. Black Beauty does not hang up or 'bridge' the way damp sand does. It is also a lot sharper than 'bank run' sand, and gives a 'better bite' on the rails.