2015-04-22 13:48:03 -04:00
|
|
|
subroutine slope(y,npts,xpk)
|
|
|
|
|
|
|
|
! Remove best-fit slope from data in y(i). When fitting the straight line,
|
2016-06-29 15:10:57 -04:00
|
|
|
! ignore the peak around xpk +/- 2 bins
|
2015-04-22 13:48:03 -04:00
|
|
|
|
|
|
|
real y(npts)
|
|
|
|
|
|
|
|
sumw=0.
|
|
|
|
sumx=0.
|
|
|
|
sumy=0.
|
|
|
|
sumx2=0.
|
|
|
|
sumxy=0.
|
|
|
|
sumy2=0.
|
|
|
|
do i=1,npts
|
2017-10-21 20:09:01 -04:00
|
|
|
if(abs(i-xpk).gt.4.0) then
|
2015-04-22 13:48:03 -04:00
|
|
|
sumw=sumw + 1.0
|
2015-11-17 20:28:12 -05:00
|
|
|
x=i
|
|
|
|
sumx=sumx + x
|
2015-04-22 13:48:03 -04:00
|
|
|
sumy=sumy + y(i)
|
2015-11-17 20:28:12 -05:00
|
|
|
sumx2=sumx2 + x*x
|
|
|
|
sumxy=sumxy + x*y(i)
|
2015-04-22 13:48:03 -04:00
|
|
|
sumy2=sumy2 + y(i)**2
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
|
|
|
|
delta=sumw*sumx2 - sumx**2
|
|
|
|
a=(sumx2*sumy - sumx*sumxy) / delta
|
|
|
|
b=(sumw*sumxy - sumx*sumy) / delta
|
|
|
|
|
2015-11-17 20:28:12 -05:00
|
|
|
sq=0.
|
2015-04-22 13:48:03 -04:00
|
|
|
do i=1,npts
|
2015-11-17 20:28:12 -05:00
|
|
|
y(i)=y(i)-(a + b*i)
|
|
|
|
if(abs(i-xpk).gt.2.0) sq=sq + y(i)**2
|
2015-04-22 13:48:03 -04:00
|
|
|
enddo
|
2015-11-17 20:28:12 -05:00
|
|
|
rms=sqrt(sq/(sumw-2.0))
|
|
|
|
y=y/rms
|
2015-04-22 13:48:03 -04:00
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine slope
|
|
|
|
|