### gnuplot commands to generate plots of stack photometry

#set border linewidth 2.5
set term postscript color eps linewidth 2.5 font "Times-Roman,30"
#set term png linewidth 3 crop

### Magnitude difference as a function of magnitude
set xrange [-17:-8]
set yrange [-0.6:0.4]
set xlabel 'PSF magnitude'
set ylabel 'PSF magnitude difference'

# Convolved stack
set output "../stack_conv_m_dm.eps"
plot 'stack_conv.dat' using 8:68 notitle with points pt 0 lc -1

# Unconvolved stack
set output "../stack_unconv_m_dm.eps"
plot 'stack_unconv.dat' using 8:68 notitle with points pt 0 lc -1


### Histograms
set xrange [-0.4:0.2]
set xlabel 'PSF magnitude difference'
set ylabel 'Number'

# Convolved stack
set yrange [0:80]
set output "../stack_conv_hist.eps"
plot \
     'stack_conv.hist' notitle with histeps lc -1 lt -1,  \
     'stack_conv.fit' notitle with lines lc 1 lt -1

# Unconvolved stack
set yrange [0:100]
set output "../stack_unconv_hist.eps"
plot \
     'stack_unconv.hist' notitle with histeps lc -1 lt -1,  \
     'stack_unconv.fit' notitle with lines lc 1 lt -1



a = 70.0
b = -0.2
c = 0.05
g(x) = a * exp(-0.5 * ((x - b)/c)**2)
FIT_LIMIT = 1e-6
FIT_MAXITER = 100
fit g(x) 'stack_conv.hist' using 1:2 via a,b,c
