Very good question. How would the shooter have thought he would even get a shot off?
I can’t imagine somebody just walking around with a rifle and say hey , there’s the president. Let me get up on the roof and try to shoot him. This probably took days of planning and people usually don’t plan in advance for security breaches. They actually plan for tight security. If the Secret Service was close enough to kill him, then they were close enough to be part of his planning