Recognize this strange expression from linear algebra? I've come across an odd-looking expression and oh how I wish I had a more elegant description of it.  Maybe someone who enjoys symmetric bilinear forms in characteristic two will recognize it?  Or someone who chooses bases and recognizes sums with indices instantly?  
Here's the setup:  $X$ is a finite-rank free ${\mathbb Z}$-module, of rank $r$, with basis $\{ x_1, \ldots, x_r \}$.  $g \in GL_r({\mathbb Z})$ is a matrix (change of basis matrix).  Finally, $C \in (X \otimes X) \otimes {\mathbb Z / 2 \mathbb Z}$ is a symmetric tensor, modulo $2$.  Concretely, with respect to the basis, $C = (c_{ij})$ with $c_{ij} \in {\mathbb Z / 2 \mathbb Z}$ and $c_{ij} = c_{ji}$ for all $1 \leq i,j \leq r$.
From $g$ and $C$, I am encountering the vector $a = \sum_j a_j x_j \in X \otimes {\mathbb Z / 2 \mathbb Z}$, where 
$$a_j = \left( \sum_{i=1}^r c_{ii} \frac{ g_{ij} (g_{ij} - 1)}{2} \right) + \sum_{k < \ell} c_{k \ell} g_{k j} g_{\ell j}.$$
I'm encountering this vector in two very specific settings related to metaplectic groups.  It looks like this vector $a$ should come from something "natural" in linear algebra or combinatorics.
Has anyone seen a vector like $a$ before?  Contexts?
 A: You never use that $g\in \mathrm{GL}_r(\mathbb Z)$, but only that it is a matrix.  So I will consider $g \in \mathrm{Mat}_r(\mathbb Z) = \mathrm{End}(X)$.  I never know whether to write $\mathrm{Sym}^2(X)$ or not when in characteristic $2$.  Your thing is in the invariant, as opposed to coinvariant, subspace.  So I guess the $2$ should be raised.  Your choice of basis determines a map $\mathrm{diag} : \mathrm{Sym}^2(X) \to X$, which records the diagonal entries of the symmetric matrix (i.e. $\mathrm{diag}(c)_i = c_{ii}$).  Note that this map is not canonical without a choice of basis: at least when you replace $\mathbb Z$ by $\mathbb C$, say, $\mathrm{Sym}^2(X)$ is an irrep of $\mathrm{SL}(X)$ for $\dim X \geq 2$.  (Or consider how the action of $-1$ on $X$ lifts to $\mathrm{Sym}(X)$.)
Recall that $\mathrm{Sym}$ is functorial, so that $\mathrm{End}(X)$ acts also on $\mathrm{Sym}^2(X)$.  This action is given by $(g\cdot c)_{ij} = \sum_{kl} c_{kl}g_{ki}g_{lj}$.
So, following Steve Huntsman's suggestion, the first thing to look at is $2a$.  It is nothing but
$$ 2a = \mathrm{diag}(g\cdot c) - g\cdot \mathrm{diag}(c). $$
Of course, your expression makes clear that this vanishes mod $2$.  So perhaps the first question to ask is:
Question: Why do $g\cdot$ and $\mathrm{diag}$ commute in characteristic $2$?
An answer: Consider the canonical maps $\mathrm{Sym}^2(X) \to X^{\otimes 2} \to \mathrm{Sym}_2(X)$, where the last term is the coinvariant space $X^{\otimes 2}/(\mathbb Z/2)$.  When $2$ is invertible, this composition is an isomorphism.  But when $2=0$, this map vanishes on the off-diagonal terms, and is nothing but a version of $\mathrm{diag}$.  Its image is the image in $\mathrm{Sym}_2(X)$ of $X$ under the "Frobenius" map $x \mapsto x\otimes x$ (which is linear in characteristic $2$ and not otherwise).
Ok, but that's not the whole story, because $\mathrm{diag}(g \cdot c)$ and $g\cdot \mathrm{diag}(c)$ depend only on the image of $g$ in $\mathrm{Mat}_r(\mathbb Z/2)$, whereas your $a$ depends on $g \in \mathrm{Mat}_r(\mathbb Z/4)$.
So what's happening?  You have a map
$$ \mathrm{End}(X) \to \mathrm{Hom}\bigl(\mathrm{Sym}^2(X),X\bigr) : g \mapsto \mathrm{diag}\circ g - g\circ \mathrm{diag} = [\mathrm{diag},g]. $$
Let's mod out by $4$ and $2$:
$$ \begin{matrix}
\mathrm{End}\otimes \mathbb Z/4 & \overset{[\mathrm{diag},-]}\longrightarrow & \mathrm{Hom} \otimes \mathbb Z/4 \\
\downarrow & & \downarrow \\
\mathrm{End}\otimes \mathbb Z/2 & \overset{[\mathrm{diag},-]}\longrightarrow & \mathrm{Hom} \otimes \mathbb Z/2 \\
\end{matrix} $$
But the bottom arrow is $0$.  So the top arrow factors through
$$ \ker \bigl( \mathrm{Hom}\otimes \mathbb Z/4 \to \mathrm{Hom}\otimes \mathbb Z/2\bigr) \cong \mathrm{Hom} \otimes \mathbb Z/2 $$
where the congruence is because $\mathrm{Hom}$ is free.
This is one version of your map $a$.  I mean, the diagram chase gave us a linear map $\mathrm{End}(X) \to \mathrm{Hom}(\mathrm{Sym}^2(X),X) \otimes Z/2$, which is nothing but a linear map $\mathrm{End}(X) \otimes \mathrm{Sym}^2(X) \otimes \mathbb Z/2 \to X \otimes \mathbb Z/2$.  I think this is $(g,c) \mapsto a$.
Also, I'm sure that I'm supposed to have said the word "cocycle" somewhere in this answer.  So pretend I did.

Edit: Except for fixing a $0$ to a $2$ somewhere, what's above is what I wrote when this answer was accepted.  But it can't be correct, at least not starting with the sentence "So what's happening?".  The problem is that the action of $\mathrm{End}(X)$ on $\mathrm{Sym}(X)$ is not linear except when $2=0$, so my whole "you have this commuting square" thing is nonsense.
I'm sure that the hint "cocycle" is correct.  I'm not sure how to make it so.
Anyway, what is true is that $\mathrm{diag}$ is a natural transformation (and $\mathrm{Sym}$ a linear functor) when $2=0$ and not otherwise.  With $\mathbb Z/4$ coefficients, linearity fails, but its failure is in the kernel of $\mathbb Z/4 \to \mathbb Z/2$, which is a copy of $\mathbb Z/2$.  So in that sense what I wrote is correct: the vector $a$ is the failure of linearity, after recognizing that this failure is necessarily in the kernel and identifying this kernel with $\mathbb Z/2$.
