I wouldn't exacly call it self defense either. It is war over there, and in war, you kill the enemy.
If the pilot and his ground contact both thought it was enemy troops, it didn't matter much that they had little chance of actually downing the plane. In war, when the enemy fires on you, you generally take the opportunity to kill them if you have the means. It's an easy way to identify the enemy... those shooting at you get shot back at.
Unfortunately, in this case, a terrible mistake was made in identifying the troops. Very sad. I think it's a lesson for the US to try harder to eliminate such accidents, but there will always be that rare mistake...