A few months after the destruction of the World Trade Center on Sept. 11, 2001, the New York Police Department, with help from the Central Intelligence Agency, established a program that would spy on mosques and other places Muslims gathered in an effort to uncover terror plots. It was, in other words, precisely the sort of intelligence-gathering that candidates for the 2016 presidential nomination have advocated in the wake of the terror attacks in Paris earlier this month.

It's important to note that, according to sworn testimony in 2012 from an assistant chief of the department, the surveillance program — which stretched far beyond New York City itself — likely never generated a lead for the department to act upon.

The program, part of the NYPD's Intelligence division, came to light in 2011 following reporting from the Associated Press. The department's Demographics Unit, as it came to be known, originally created a map of 28 "ancestries of interest" found in Census data -- most of which were Muslim. Eventually, undercover officers were dispatched to surveil minority communities. They were known as "rakers," as they were charged with "raking the coals" to find hot spots, the AP reported.

New York magazine described their work in a 2013 article:

The routine was almost always the same, whether they were visiting a restaurant, deli, barbershop, or travel agency. The two rakers would enter and casually chat with the owner. The first order of business was to determine his ethnicity and that of the patrons. ... Next, they’d do what the NYPD called “gauging sentiment.” Were the patrons observant Muslims? Did they wear traditionally ethnic clothes, like shalwar kameez? Were the women wearing hijabs? If the Arabic news channel Al Jazeera was playing on the TV, the police would note it and observe how people were acting. Were they laughing, smiling, or cheering at reports of U.S. casualties in Iraq and Afghanistan?

Another group of officers were known as "mosque crawlers," tasked with attending weekly sermons at mosques and reporting back what was said -- and who was in attendance. The department gathered information on people who changed their name to either be more American (in an attempt to assimilate) or more Arabic (as a sign of their faith).

Investigators covered New York City, but also as far away as Buffalo, Pennsylvania and Connecticut. They also tracked behavior online as well. All of the data, as you'd expect, was collected in databases.

The operation was the idea of then-Police Commissioner Ray Kelly, who sought the advice of a retired CIA officer named David Cohen. Cohen convinced the CIA to loan the department Lawrence Sanchez, a CIA officer who eventually took leave from the agency in order to work with the NYPD full-time. According to a critical report from the CIA inspector general, Sanchez felt as though that leave allowed him to operate outside the constraints that usually apply to CIA officers surveiling American citizens.

After the program came to light, backlash was swift. In June of 2012, a group of Muslims sued the city of New York for the surveillance, which they argued violated their 1st and 14th Amendment rights. It was at first dismissed, but an appeals court in Philadelphia overturned that decision just last month.

Judge Thomas Ambro, writing for the majority in that decision, put the spying in historical context.

What occurs here in one guise is not new. We have been down similar roads before. Jewish-Americans during the Red Scare, African-Americans during the Civil Rights Movement, and Japanese-Americans during World War II are examples that readily spring to mind. We are left to wonder why we cannot see with foresight what we see so clearly with hindsight—that “[l]oyalty is a matter of the heart and mind[,] not race, creed, or color.”

In 2012, NYPD Assistant Chief Thomas Galati was deposed in a separate lawsuit. He was asked when an investigation was determined to have begun after evidence was presented to the Demographics Unit. "Related to Demographics, I can tell you that information that have come in has not commenced an investigation," Galati said. He thought that perhaps there had been one investigation prior to his tenure with the organization, but that "I have not been able to determine that" -- and that he didn't think the investigation was a function of the Demographics Unit.

Last year, Mayor Bill de Blasio (D) shut down the program.