The rule of the game is to use $A$ and $F=dA$ to write a topological action, and in $d+1$-space time dimension you need to come up with a *gauge-invariant* $d+1$-form which can then be integrated over the manifold to give you the action. Such an action does not depend on metric at all. Take $U(1)$ gauge field as an example. In $2+1$, the only thing you can write down is $AF$($AAA$ vanishes identically), which is the Chern-Simons. Then in $3+1$, you can guess $FF, AAF, AAAA$. $AAF$ and $AAAA$ vanishes due to antisymmetrization of the wedge product. So you are left with $FF$. This can be generalized to other Lie groups.

This post imported from StackExchange Physics at 2015-03-21 18:34 (UTC), posted by SE-user Meng Cheng