pro centroid,pos,sig,centroid,integral ; pos inputs the pixel positions, sig inputs the signal ; centroid returns the centroid, integral returns the integral s=size(pos) last=s(1)-1 wsum=0. integral=0. for i=0,last do begin wsum=wsum+pos(i)*sig(i) integral=integral+sig(i) endfor centroid=wsum/integral return end