Oh, imagine frieght trains that carry a few battery coaches, and periodically stop at charging stations in the middle of nowhere and then continue on their journey without polluting and being a menace to the urban grids..
Now, if only such battery systems could come down in cost so much that it becomes a no-brainer.
There are regions where the grid and the plants powering that are separate from the maingrid. (West-)Germany was like that, still is. For historical reasons, like different frequency of 16 2/3Hz. It's called 'Bahnstrom'.
If your'e wondering wtf!? 16 2/3Hz at all, that was because at the time of early electrification with AC (less transmission loss over longer distances), that frequency produced less sparks/arcing with the then available electro-motors for that single phase of AC, RPM, lack of advanced (mobile(power))electronics, and so on. Legacy...
DC had different trade-offs.
Since you wrote freight-trains, which isn't light-rail, which also had its own power-plants and grids, and mostly still has?