I work as a theoretical physicist, and I second this. Not only for code but mathematics and other chain-of-logic kind of work. Also not limited to train, but to doing dishes or other routine activities where the mind can decouple. It does happen though that I get stuck brushing my teeth for 15 minutes lost in thought.