TITLE: Measuring a presheaf's failure to be a sheaf?
QUESTION [16 upvotes]: Apologies for the vagueness of question.
Background
this thread has some nice examples of presheaves failing to be sheaves.
Question
Is there a generic way to measure "how badly" a presheaf fails at being a sheaf?
Something like an invariant that "counts", up to some notion of equivalence, sections that fail to glue or restrict properly?
Discussion
Can we do this by comparing some invariant of a presheaf $P$ and its sheafification $\tilde P$? The comments on this old math SE thread makes an attempt to argue that the Cech cohomology (taking the cover refinement limit) of the two are equal. But is there something else that we can compare between $P$ and $\tilde P$?

REPLY [11 votes]: Let $\mathcal{F}$ be a presheaf on $X$, and suppose $\mathcal{U}=\{U_i\}$ is an open cover of $X$. The Cech complex is the cochain complex whose degree $n$ piece is the direct sum of sections of $\mathcal{F}$ on the $(n+1)$-fold intersections of sets in $\mathcal{U}$. The ordinary Cech complex is supported in degrees $n\geq 0$, but the same definition works for $n=-1$: there is only one $0$-fold intersection, and it is all of $X$. So we get an extended complex supported in degrees $\geq -1$, that starts
$$
0\to \mathcal{F}(X)\to \bigoplus_{i} \mathcal{F}(U_i)\to\bigoplus_{i<j}\mathcal{F}(U_i\cap U_j)\to\ldots
$$
For this complex, $H^{-1}$ is the set of global section of $\mathcal{F}$ that restrict to $0$ on each of the open sets in $\mathcal{U}$, and $H^0$ is the set of sections on the open sets of $\mathcal{U}$ agreeing on the overlaps, modulo those coming from a global section. So $H^{-1}$ measures a failure of sections to be determined by local data, and $H^0$ measures a failure of gluing. Both $H^{-1}$ and $H^0$ vanish when $\mathcal{F}$ is a sheaf, so these cohomology groups give a measure of the failure of $\mathcal{F}$ to be a sheaf.