The man had on a camouflage mask as well as a black hoodie, and that was enough to get the notice of the two cops.

Police Officer Lauren O’Rourke and Police Officer Geraldo Casaigne also observed that the man matched the general physical description of a maniac who had randomly attacked four people with a claw hammer in Manhattan two days before.

The cops began to follow the man down Eighth Avenue and across West 37th Street. The man had just reached the far corner when he turned and made eye contact with O’Rourke.

In the next instant, the man produced a claw hammer and charged O’Rourke, swinging wildly.

The hammer seemed to strike 27-year-old O’Rourke three times—at least once in the head—as she backed up, attempting to radio for more units. She lost her footing and went down.

The man was still on her, still swinging the hammer, the claw facing out.

The other cop, Casaigne, now had his gun out. The 36-year-old had but a split second to make the biggest decision a cop can make. He fired four times.

The man also went down, sprawling on his back in the middle of the sun-splashed street, the hammer nearby.

The face under the mask proved to be the one that NYPD facial recognition software had selected from a database after investigators fed in subway surveillance footage taken after Monday’s four hammer attacks.

The software had identified the man was 30-year-old David Baril of the Bronx. A check of his Instagram account showed that last year he had posted a drawing of a claw hammer dripping with blood.

“Hammer,” he wrote simply.

He also posted a verbal tangle of insanity he called “Evil.”

“The killer inside of me / In the dark I cannot see / the blade and the robbery / vaginas must bleed.”

He went on, “[My] head can get shocked / yours will get bopped / I’m not gonna stop…your blood will get mopped.”

He repeated the refrain “the killer inside of me” and concluded with “no heaven above me / no heart inside of me.”

A records check showed that Baril had a history of eight arrests, 11 summonses, and 13 warrants. He had tussled with a cop while armed with a “pointed object.” He had been stopped for smoking in the subway and been found to be carrying a stun gun while wearing body armor. He had been caught shoplifting CDs, possessing a small amount of cocaine, and possessing fireworks. He repeatedly failed to make court dates and was repeatedly picked up at home on warrants.

At one point, he stalked a woman he had known only vaguely years before. He waited by the elevator as she left her apartment to go to work, then followed her from her job and sat next to her on the bus, saying, “I miss you [on] Facebook, I was on it every day.” He also took to ringing her intercom and screaming her name in the street outside her building.

“Is afraid for her safety,” court papers say of the woman.

At the end of last year, Baril was living at a shelter for the mentally ill. He was reported missing from there on December 29.

“Missing suffers from schizophrenia and paranoia,” the center informed the police.

On March 21 at a Kentucky Fried Chicken in the Bronx, Baril gave the woman behind the counter $10.25 for an order that came to $10.21. She gave him four cents change.

“Give me my $10 back,” he demanded, according to court papers.

“You don’t want your food anymore?” the woman asked.

“Yes, and give me my $10,” he said.

The woman turned to get the manager. Baril allegedly jumped the counter and punched her in the back. He was arrested for assault and the case is pending.

By then, Baril was apparently living at homeless shelters or in the street or on the subway. He approached a man who was speaking with three women on a Manhattan sidewalk around 1:45 p.m. on Monday.

Without warning or apparent cause, Baril allegedly struck the man on the head with a hammer. The next attack was a few blocks away at 5:10 pm, when a 34-year-old woman was struck in the head with a hammer. A 28-year-old woman was the next to be similarly attacked. The same then befell a 33-year-old woman.

Interestingly, Baril paid his fare when he later went down into the subway, perhaps to avoid being stopped and found in possession of the hammer. The police were nonetheless able to get an image of him by searching the subway surveillance footage for a man fitting the suspect’s description in the immediate wake of the attacks.

After the facial recognition unit matched that footage with a photo on file of Baril, his picture was shown at roll calls and distributed to cops, along with a general physical description.

The combination of high-tech wizardry and street cop intuition resulted in the two cops trailing Baril at 10 a.m. on Wednesday.

By chance, an NYPD surveillance camera recorded all that followed. The footage should impart an important lesson in context to folks such as the person with the Twitter handle capricornsfire, who tweeted, “Cops just shot a man 5 times in the back outside my office building.”

At a press conference, Police Commissioner William Bratton noted the time that elapsed between Baril producing the hammer and Casaigne firing his weapon.

“Three seconds, start to finish,” Bratton said.

Bratton suggested that Casaigne might very well have saved O’Rourke’s life when he fired.

“The right decision,” Bratton concluded.

O’Rourke was examined at Bellevue Hospital and released. Baril arrived there classified as “likely,” meaning likely to die. He was still alive as of Wednesday evening.

Whatever the outcome, the surveillance video of those fateful three seconds should provide everybody with a reminder of what it can suddenly mean to be a cop.