rewritten harmonic potential and distance2 histogram as a template class that takes different distance policies