
load("data_Fig3.mat")

figure('Color', 'w', 'Units','normalized', 'Position', [0.3 0.1 0.3 0.7])
subplot(3,1,1)
hold on
plot([co_dir co_dir], [-8 0], 'Color', my_B)
plot([co_rec co_rec], [-8 0], 'Color', my_R)
plot(Espec_tdse(max_ind), spec_all_tdse(max_ind), 'o', 'MarkerFaceColor', my_Green, 'MarkerEdgeColor', 'none')
plot(Espec_tdse(min_ind), spec_all_tdse(min_ind), 'o', 'MarkerEdgeColor', my_Green)
plot(Espec_tdse, spec_all_tdse, 'LineWidth', 1.5, 'Color', my_Green)
plot(Espec(Espec<max_co*Up)/Up, log10(conj(spec_plot_all(Espec<max_co*Up)).*spec_plot_all(Espec<max_co*Up))-2, 'k', 'LineWidth', 1.5);
plot(Espec(Espec>max_co*Up)/Up, log10(conj(spec_plot_all(Espec>max_co*Up)).*spec_plot_all(Espec>max_co*Up))-2, 'k--', 'LineWidth', 1.5);
xlim([0 2.5])
ylim([-6.5 -1.8])
ylabel 'log10(Yield) (arb.u.)'
box on

% Phase extrapolation
color_line = my_Greylight;
subplot(3,1,2)
hold on
plot([co_dir co_dir], [-1 25], 'Color', my_B)
plot([co_rec co_rec], [-1 25], 'Color', my_R)
scatter(E_soll, S_soll, 3+50*w_soll, my_R, 'filled')
scatter(E_solld, S_solld, 3+50*w_solld, my_B, 'filled')
plot(Espec/Up, fit_results.Theta_Fit_list_rec(:, cep_index)/pi + fit_results.offset_rec(cep_index), '--', 'Color', color_line, 'LineWidth', 1.5)
plot(Espec_hist_rec(roi_rec)/Up, fit_results.theta_eff_rec(roi_rec,cep_index)/pi + fit_results.offset_rec(cep_index), 'Color', color_line, 'LineWidth', 1.5)
plot(Espec/Up, fit_results.Theta_Fit_list_dir(:, cep_index)/pi + fit_results.offset_dir(cep_index), '--', 'Color', color_line, 'LineWidth', 1.5)
plot(Espec_hist_dir(roi_dir)/Up, fit_results.theta_eff_dir(roi_dir,cep_index)/pi + fit_results.offset_dir(cep_index), 'Color', color_line, 'LineWidth', 1.5)
xlim([0 2.5])
ylim([2 16])
box on
ylabel 'Phase [pi]'

% Phase analysis
subplot(3,1,3)
hold on
fill(X, Y1, [0.8 1 0.8], 'EdgeColor', 'none')
fill(X, Y2, [0.8 0.8 1], 'EdgeColor', 'none')
fill(X, Y3, [1 0.9 0.8], 'EdgeColor', 'none')
plot([co_dir co_dir], [-1 15], 'Color', my_B)
plot([co_rec co_rec], [-1 15], 'Color', my_R)
plot(Espec(Espec<max_co*Up)/Up, total_relative_phase(Espec<max_co*Up) / pi + 2, 'k', 'LineWidth', 1.5);
plot(Espec(Espec>max_co*Up)/Up, total_relative_phase(Espec>max_co*Up) / pi + 2, 'k--', 'LineWidth', 1.5);
plot(Espec_tdse(max_ind), phase_max_list + 2, 'o', 'MarkerFaceColor', my_Green, 'MarkerEdgeColor', 'none')
plot(Espec_tdse(min_ind), phase_min_list + 2, 'o', 'MarkerEdgeColor', my_Green)
xlabel 'Energy (Up)'
ylabel 'Relative spectral Phase (\pi)'
box on
xlim([0 2.5])
ylim([0 14])