Topological invariants and the definition of energy in quadratic gravity theory