Cab sway/movement depends on a lot of things.
Different locos/rolling stock can ride the same piece of track very differently. Likewise, track can make something that rides smoothly normally ride very roughly.
Loco weight and distribution also matter. Some designs of loco have very bad riding because of poor weight distribution, some are poor riding because of poor bogie design. So for example with a steam engine (especially a tank engine) how full is the bunker? How full are the water tanks? These all impact on ride.
Didn't the SP40F's have a very bad reputation for riding and wasn't that due to the tanks for the steam heat?
For example I used to travel on the Portsmouth line and we had 3 types of EMU. One type was known to be very rough riding (CEP) because of its design of bogie. While the others were much better. Travelling over the motor bogie gives you a much rougher ride as well. So when commuting you avoided certain units and certain places on the train if you wanted a decent ride.
Steam locos travelling tender first tend to ride more roughly.
Also, ride quality is the first thing that goes with age and maintenance.
Some units are good, some are bad.
Something that maybe of interest to people is the report into the 1927 Sevenoaks crash. To cut a long story short the loco rolled and derailed. There were a lot of questions about why it rolled - ie loco design vs track. As part of the investigation they did a lot of tests looking at ride, types of roll etc on different track and with different locos, with different settings - ie tender first, chimney first, bunker first, chimney first, high speed, low speed, full/empty/half-full bunkers, tanks. It's IMO very interesting because it gives some kind of attempt to study ride quality.
http://www.railwaysarchive.co.uk/documents/MoT_Sevenoaks1927.pdf