#! /bin/bash


PathToScript="../../.."

time python3 $PathToScript/ppmc3fitting.py -d dataset.def -c channels.def -v variables.def  -r regularization.def

#exit
# plot the fits
gnuplot <<-EOF


set title "LKEe fit results"
set xlabel "pump-probe delay"
set ylabel "product yield"

set style fill transparent solid 0.3 noborder

plot 'flu_lkee.dat' u 1:2:4 w e title "Experiment",\
     'lkee_gfit_dualann.res' u 1:2 w l lc rgb "red" title "Global fit",\
     'lkee_mcmc_sampling.res' u 1:(\$2-\$3):(\$2+\$3) w filledcu lc rgb "blue" notitle, '' u 1:2 w l lc rgb "blue" title "Total MCMC sampling",\
     '' u 1:(\$4-\$5):(\$4+\$5) w filledcu lc rgb "#52f22e" notitle, '' u 1:4 w l lc rgb "#52f22e" title "Component1",\
     '' u 1:(\$6-\$7):(\$6+\$7) w filledcu lc rgb "#49d929" notitle, '' u 1:6 w l lc rgb "#49d929" title "Component2",\
     '' u 1:(\$8-\$9):(\$8+\$9) w filledcu lc rgb "#41c124" notitle, '' u 1:8 w l lc rgb "#41c124" title "Component3"

pause mouse "Click any mouse button on selected data point\n"

set terminal pngcairo
set output "lkee_fitting_plot.png"
replot

EOF


gnuplot <<-EOF


set title "FLU^{2+} fit results"
set xlabel "pump-probe delay"
set ylabel "product yield"

set style fill transparent solid 0.3 noborder

plot 'flu-dication_yield.dat' u 1:2:4 w e title "Experiment",\
     'dication_gfit_dualann.res' u 1:2 w l lc rgb "red" title "Global fit",\
     'dication_mcmc_sampling.res' u 1:(\$2-\$3):(\$2+\$3) w filledcu lc rgb "blue" notitle, '' u 1:2 w l lc rgb "blue" title "Total MCMC sampling",\
     '' u 1:(\$4-\$5):(\$4+\$5) w filledcu lc rgb "#52f22e" notitle, '' u 1:4 w l lc rgb "#52f22e" title "Component1",\
     '' u 1:(\$6-\$7):(\$6+\$7) w filledcu lc rgb "#49d929" notitle, '' u 1:6 w l lc rgb "#49d929" title "Component2",\
     '' u 1:(\$8-\$9):(\$8+\$9) w filledcu lc rgb "#41c124" notitle, '' u 1:8 w l lc rgb "#41c124" title "Component3",\
     '' u 1:(\$10-\$11):(\$10+\$11) w filledcu lc rgb "#41c124" notitle, '' u 1:10 w l lc rgb "#41c124" title "Component4"

pause mouse "Click any mouse button on selected data point\n"

set terminal pngcairo
set output "flu_dication_plot.png"
replot

EOF




# plot the t0 distribution
gnuplot <<-EOF
unset key
set title "Deviation from known t0 distribution from MCMC sampling"
set xlabel "t0, fs"
set ylabel "probablity"

set style fill transparent solid 0.3 
t0 = 12.649
plot 'variable_t0_sampled_distribution.res' u ((\$1-t0)*1e3):2 w boxes

pause mouse "Click any mouse button on selected data point\n"

set terminal pngcairo
set output "t0_distr.png"
replot

EOF

# plot the tcc distribution
gnuplot <<-EOF
unset key
set title "tcc distribution from MCMC sampling"
set xlabel "tcc, fs"
set ylabel "probablity"

set style fill transparent solid 0.3 

plot 'variable_tcca_sampled_distribution.res' u (\$1*1e3):2 w boxes title "tccA",\
     'variable_tccb_sampled_distribution.res' u (\$1*1e3):2 w boxes title "tccB",\
     'variable_tccc_sampled_distribution.res' u (\$1*1e3):2 w boxes title "tccC"

pause mouse "Click any mouse button on selected data point\n"

set terminal pngcairo
set output "tcc_distr.png"
replot

EOF

# plot the tr distribution
gnuplot <<-EOF
#unset key
set title "tr distribution from MCMC sampling"
set xlabel "tr, fs"
set ylabel "probablity"

set style fill transparent solid 0.3 

plot 'variable_trfront_sampled_distribution.res' u (\$1*1e3):2  w boxes title "Pump is pump channel",\
     'variable_trback_sampled_distribution.res'  u (\$1*1e3):2  w boxes title "Probe is pump channel"

pause mouse "Click any mouse button on selected data point\n"

set terminal pngcairo
set output "tr_distr.png"
replot

EOF


# plot the parameters co-dependence
gnuplot <<-EOF
unset key
set title "MCMC sampling trajectory"
set xlabel "Step number"
set ylabel "LSQ + Regularization functional"

plot 'mcmc_sampling.trj' u 1:(\$7+\$8) w l title "LSQ+Reg", '' u 1:7 w l title "LSQ"

pause mouse "Click any mouse button on selected data point\n"

set terminal pngcairo
set output "mcmc_trj.png"
replot

EOF





