Moved assignDataPatternsToParticle to one place.

This removes a lot of duplicate code. It also removes some clustering specific code from places where it doesn't belong.