The selfishness occurs before and after the event. When you stop to do something, you make a decision that you/your society/ your country /... would be better off. You weigh this against no action and decide that you will be better of by acting. This action is then rewarded (feel good, gain praise, reputation) and your behaviour reinforced (much like a skinner rat) so that next time you make a similar decision.