What do you want to do?Count them when it is moving?I mean for what?
First of all do you know how IR sensors work? You have a transmitter and a Receiver.A train travels very fast, and how would you mount a system to do this practically?Counting can be done in various ways and the best is using microcontrollers.
my design is like when ever a wheel passes between the IR TX and RX it will give you a pulse, this pulse will give an interrupt to the Micr0 (eg ,8051),
on the BAsis of the interrupt micro will count the no of wheel passed through a signal.