The recent attempt on Donald Trump’s life has invited scrutiny of the Secret Service. It looks increasingly likely that Trump’s security detail left him vulnerable to an assassin’s bullet, thanks to complacency, miscommunication, incompetence — or all three.

Still, not all of the blame can be laid at the feet of the Secret Service.

The job of protecting the president has long posed an extraordinary challenge. For over two hundred years, our chief executives have doggedly insisted on putting themselves in danger by mingling with ordinary citizens. This has led to an unfortunate statistic: roughly a quarter of all presidents have been victims of serious assassination attempts — four of which ended in death.

They’ve done so because they, like the rest of us, have believed that the president should not be a king in a castle, but a man (or woman) of the people, accessible to voters. Over time, the settings for those interactions have become more formal and ritualized, but no less risky. As a consequence, the presidency remains a uniquely dangerous job.

Thomas Jefferson pioneered the idea that presidents should be close to the people they govern, risks be damned. Unlike George Washington and John Adams, Jefferson self-consciously shed the aristocratic airs cultivated by his predecessors. For example, instead of taking a secure carriage to the Capitol for his inauguration, Jefferson walked the entire distance unprotected, among the crowds.

Given his faith in "the people,” it’s hardly surprising that Jefferson eschewed formal protection or bodyguards. His successors followed suit. Andrew Jackson, elected in 1828, was especially willing to hobnob with the general public, even inviting strangers into the White House. Not coincidentally, he was also the first victim of an attempted murder.

The aspiring assassin, Richard Lawrence, was a mentally ill house painter who became convinced the government owed him money and that Jackson had withheld the funds. When the president went a funeral in the Capitol, Lawrence went too, firing two Derringer pistols at Jackson. Miraculously, both failed to discharge, at which point Jackson repeatedly beat Lawrence over the head with his cane — the only president to hit back at an assassin.

One would think that after this near disaster, subsequent presidents would have maintained a retinue of bodyguards. Instead, not much changed beyond the eventual addition of some part-time security on the grounds of the White House. Even after Abraham Lincoln became president amid the outbreak of the Civil War, security would remain remarkably lax.

This was less a matter of incompetence than self-conscious choice. Lincoln hated the interposition of a phalanx of guards between him and the public. His refusal to take precautions made him a very visible, inspiring leader in a time of crisis. Yet it also led him to visit Ford’s Theater in the final weeks of the Civil War with only a single inept bodyguard to protect him. We all know how that turned out.

One might imagine that Andrew Johnson, his successor, would have learned the obvious lesson. Yet he provoked consternation in the press when he initially announced that he wouldn’t accept any protection because he was "unwilling to evince any distrust of the people,” as the New York Times put it.

For the most part, Congress agreed with Johnson. In fact, the Secret Service, which been created during the Civil War to protect the new national currency from counterfeiters, would not take its modern role as the protector of the president until 1894 — and even then, only on a part-time, informal basis. And this was after James Garfield died at the hands of another mentally ill assassin: a deranged preacher named Charles Guiteau, who believed that Garfield owed him an ambassadorship.

Guiteau visited the White House, managing to get all the way to Garfield’s office. When the president rebuffed him, Guiteau resolved to kill him. Garfield, who habitually went out in public among the city’s crowds, proved an easy target, and Guiteau mortally wounded Garfield in the city’s railroad station on July 2, 1881.

When William McKinley became president, he followed Garfield’s lead, even getting rid of the sentry boxes that protected the White House. Resolutely optimistic, McKinley rejected what little protections the Secret Service offered him. Little wonder, then, that anarchist Leon Czolgosz managed to get close enough to shoot McKinley when he visited Buffalo, New York, in 1901.

The third assassination in less than 50 years eventually spurred Congress to formalize the Secret Service’s obligation to protect the president. This meant an end to the kind of easy access that defined the lives of presidents in the 19th century. Yet it did not end the violence — but not because of security failures.

Until the turn of the 20th century, presidential candidates didn’t actually campaign in the way they do now. Instead, surrogates delivered stump speeches and supercharged voters while presidents remained above the fray. Beginning with McKinley, though, candidates now took a more active role in campaigning, delivering speeches to crowds and otherwise wading into the political muck.

McKinley’s successor, Teddy Roosevelt, captured this shift — and the rethinking of security it required — in a letter to an associate written in 1906. He described the Secret Service as "a very small but very necessary thorn in the flesh” because they kept "the multitude of cranks and others” who tried to visit him. Roosevelt added, though, that the security detail "would not be the least use in preventing any assault on my life.”

He grasped what we seem to have forgotten: that a president who attends countless rallies and other public events is difficult to protect. In fact, when Roosevelt ran for a third term under the Bull Moose Party, an assassin shot him on his way at a campaign event. (The bullet lodged in his chest, but Roosevelt insisted on giving a lengthy speech before going to the hospital, memorably quipping: "I have just been shot, but it takes more than that to kill a Bull Moose.”)

Roosevelt’s bravado was a harbinger of things to come. Even as the Secret Service gradually increased its security detail, presidents and presidential candidates became increasingly visible in staged public events on and off the campaign trail. This inevitably led to yet more assassination attempts.

One gunman came close to killing president-elect Franklin Delano Roosevelt in 1933; another succeeded with presidential aspirant Huey Long two years later. FDR’s successor escaped two more assassination attempts in 1953.

John F. Kennedy wasn’t so lucky. A charismatic campaigner, Kennedy craved crowds and the meandering path that his motorcade took on Nov. 22, 1963, was designed to maximize his visibility to well-wishers along the way. Unfortunately, it also gave an opening to Lee Harvey Oswald.

Every one of these incidents spurred ever-higher levels of security for presidents and candidates. Yet for all the precautions the Secret Service now takes — locking down entire city blocks and posting snipers on roofs — agents face a daunting task so long as current and aspiring presidents insist on doing the kinds of public events, rallies and meet-and-greets that are the lifeblood of democracy.

Ronald Reagan captured this reality when he visited Ford’s Theater shortly after being inaugurated. Looking up at Lincoln’s box, Reagan had a premonition: "I thought that even with all the Secret Service protection we now had, it was probably still possible for someone who had enough determination to get close enough to the president to shoot him.” Nine days later, John Hinckley managed to do just that.

And little wonder. Reagan understood that assassination is a kind of occupational hazard, one that transcends the particulars of any given security detail. It’s the inevitable consequence of the public persona we expect presidents to adopt. And most presidents, Trump included, are more than happy to play that role, the risks notwithstanding.

Stephen Mihm, a professor of history at the University of Georgia, is co-author of "Crisis Economics: A Crash Course in the Future of Finance.”