In condensed matter physics or quantum field theory we often write down terms in our Lagrangian which are invariant under given symmetries. The standard model for example is invariant under $SU(3)\times SU(2) \times U(1)$ (spare spontaneous symmetry breaking) - whilst a typical free energy in the Heisenberg model is: $$H=\int d^3\vec r\left(\frac{1}{2} \nabla_i M_j \nabla_i M_j+a_2 \vec M \cdot \vec M+a_4(\vec M \cdot \vec M)^2+\cdots\right)$$
It is clear in this case that is invariant under $SO(3)$ and $O(3)$.
My question is - in general what terms can we add to Lagrangian (in CPM and QFT) to make it invariant under solely $SO(n)$ ($SU(n)$) rather then $O(n)$ ($U(n)$)?