Our recent ride on the Berkshire Scenic included several stops and photo run-by. On the return run from North Adams, we paused at the South View Cemetery. I opted for a position well away from the line in order to make pan-photos.
For these images, I set the camera lens to f22 to allow for use of a comparatively slow shutter speed (1/30 second at ISO 200). Then as the train passed, I used my body to pan with the train to keep my desired point of focus in constant movement with train. The slower shutter speed lets the background blur while camera motion keeps the train sharp.
Perhaps the most important thing about executing a successful pan is to release the shutter while continuing to move with the train.