computation of the center of mass and replacement of negative values by zeros