templated mass center functions