These two blocks look essentially identical except for the first line which selects the group.  Just put the beginGroup (and m_HistogramConfig = new ...) part in the if and use the identical code for both paths.