% Default settings for plots
set(0,'DefaultAxesFontSize', 16)
set(0,'DefaultAxesLineWidth', 2)
set(0,'DefaultLineMarkerSize', 8)
set(0,'DefaultLineMarkerFaceColor', 'auto')
set(0,'DefaultLineLineWidth', 2)


%EX 5.2.5
[x,y,err,xlab,ylab,titl]=McScanLoad('/home/linda/Desktop/INSIS/TAStutorial/sim/ex5.2.5',4)
cd /home/linda/Desktop/INSIS/TAStutorial/
close all
errorbar(x,y,err,'bo');hold on
xlabel(xlab)
ylabel(ylab)
title(titl)
s=spec1d(x,y,err)
[f,g]=fits_new(s,'gauss',[max(y) x(length(x)/2) 0.5 0],[1 1 1 1])
line(x,feval('gauss',x,g.pvals))
legend('McStas data',['Gaussian fit:A=' num2str(g.pvals(1),2) '+-' num2str(g.evals(1),1) ', C:' num2str(g.pvals(2),3) '+-' num2str(g.evals(2),1) ', \sigma:' num2str(g.pvals(3),2) '+-' num2str(g.evals(3),1)])
ylim([0 1.5*max(y)])
print -depsc ex_5.2.5_focusw0.02_focush0.02.eps


[x,y,err,xlab,ylab,titl]=Mc1Dload('/home/linda/Desktop/INSIS/TAStutorial/sim/ex5.2.5/10/Lmon_samplepos.sim')
close all
errorbar(x,y,err,'bo');hold on
xlabel(xlab)
ylabel(ylab)
xlim([0 15])
%title(titl)
print -depsc ex_5.2.5_spec.eps


%EX 5.2.6
[x,y,err,xlab,ylab,titl]=McScanLoad('/home/linda/Desktop/INSIS/TAStutorial/sim/ex5.2.6',4)
cd /home/linda/Desktop/INSIS/TAStutorial/
close all
errorbar(x,y,err,'bo');hold on
xlabel(xlab)
ylabel(ylab)
title(titl)
s=spec1d(x,y,err)
[f,g]=fits_new(s,'gauss',[max(y) x(length(x)/2) 0.5 0],[1 1 1 1])
line(x,feval('gauss',x,g.pvals))
legend('McStas data',['Gaussian fit: A=' num2str(g.pvals(1),2) '+-' num2str(g.evals(1),1) ', C:' num2str(g.pvals(2),3) '+-' num2str(g.evals(2),1) ', \sigma:' num2str(g.pvals(3),2) '+-' num2str(g.evals(3),1)])
ylim([0 1.5*max(y)])
print -depsc ex_5.2.6omscan.eps

[x,y,err,xlab,ylab,titl]=Mc1Dload('/home/linda/Desktop/INSIS/TAStutorial/sim/ex5.2.6/10/Lmon_samplepos.sim')
close all
errorbar(x,y,err,'bo');hold on
xlabel(xlab)
ylabel(ylab)
%title(titl)
xlim([0 15])
ylim([0 1.1*max(y)])
print -depsc ex_5.2.6spec.eps

%EX 5.2.7
[x,y,err,xlab,ylab,titl]=McScanLoad('/home/linda/Desktop/INSIS/TAStutorial/sim/ex5.2.7omscan',4)
cd /home/linda/Desktop/INSIS/TAStutorial/
close all
errorbar(x,y,err,'bo');hold on
xlabel(xlab)
ylabel(ylab)
title(titl)
s=spec1d(x,y,err)
[f,g]=fits_new(cut(s,[19.7 22.3]),'gauss',[max(y) x(length(x)/2) 0.5 0],[1 1 1 1])
line(x,feval('gauss',x,g.pvals))
legend('McStas data',['Gaussian fit: A=' num2str(g.pvals(1),2) '+-' num2str(g.evals(1),1) ', C:' num2str(g.pvals(2),3) '+-' num2str(g.evals(2),1) ', \sigma:' num2str(g.pvals(3),2) '+-' num2str(g.evals(3),1)])
ylim([0 1.5*max(y)])
print -depsc ex_5.2.7omscan.eps

[x,y,err,xlab,ylab,titl]=Mc1Dload('/home/linda/Desktop/INSIS/TAStutorial/sim/ex_5.2.7omscan/10/Lmon_samplepos.sim')
close all
errorbar(x,y,err,'bo');hold on
xlabel(xlab)
ylabel(ylab)
%title(titl)
xlim([0 15])
ylim([0 1.1*max(y)])
print -depsc ex_5.2.7spec.eps


%EX 5.3.1
[x,y,data,z,xlab,ylab,titl]=Mc2Dload('/home/linda/Desktop/INSIS/TAStutorial/sim/ex5.3.1/PSD_4pi.sim')
close all
pcolor(x,y,log(data'));
colorbar
xlabel(xlab)
ylabel(ylab)
%title(titl)
xlim([0 15])
ylim([0 1.1*max(y)])
print -depsc ex_5.3.1.eps
