#! /bin/bash


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

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


# plot the fits
gnuplot <<-EOF

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

set style fill transparent solid 0.3 noborder

plot 'generic_dataset.dat' w e title "Experiment",\
     'data_gfit_dualann.res' u 1:2 w l lc rgb "red" title "Global fit",\
     'data_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 "#39a920" notitle, '' u 1:10 w l lc rgb "#39a920" title "Component4"

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

set terminal pngcairo
set output "fitting_plot.png"
replot

EOF


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

set style fill transparent solid 0.3 

plot 'variable_t0_sampled_distribution.res' 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"
set ylabel "probablity"

set style fill transparent solid 0.3 

plot 'variable_tcc_sampled_distribution.res' w boxes

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"
set ylabel "probablity"

set style fill transparent solid 0.3 

plot 'variable_tr_sampled_distribution.res' w boxes

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 "Parameter 1 vs parameter 2"
set xlabel "parameter 1"
set ylabel "parameter 2"

plot 'mcmc_sampling.trj' u 2:3

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

set terminal pngcairo
set output "1vs2_distr.png"
replot

EOF


# plot the parameters co-dependence
gnuplot <<-EOF
unset key
set title "Parameter 1 vs parameter 3"
set xlabel "parameter 1"
set ylabel "parameter 3"

plot 'mcmc_sampling.trj' u 2:4

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

set terminal pngcairo
set output "1vs3_distr.png"
replot

EOF

# plot the parameters co-dependence
gnuplot <<-EOF
unset key
set title "Parameter 2 vs parameter 3"
set xlabel "parameter 2"
set ylabel "parameter 3"

plot 'mcmc_sampling.trj' u 3:4

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

set terminal pngcairo
set output "2vs3_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

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

set terminal pngcairo
set output "mcmc_trj.png"
replot

EOF





