clearvars -except cmaps
clear global
close all

global_var

load('../pfm_summary/autoconv_test_pfm.mat')
cmi = 1-str2num(str2mat(extractAfter(pfm(1).misc.var1_str,lettersPattern)))';
dmr = str2num(str2mat(extractAfter(pfm(2).misc.var2_str,lettersPattern)))';

figure('position',[0 0 1000 600])
tl = tiledlayout('flow');

for ifig = 1:4
   nexttile
   if ifig < 3
      cat_text = ' (original AMP)';
   else
      cat_text = ' (unified category AMP)';
   end
   hold on
   for its = 1:2
      if mod(ifig,2) == 1
         xx=cmi;
         yy1=pfm(ifig).rain_M1_path.(bintype{its}).mr';
         yy2=ones(size(yy1));
         pt=patch([xx fliplr(xx)], [yy1 fliplr(yy2)], color_order{its},'edgecolor','none',...
            'FaceAlpha', .2);
         set(get(get(pt,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

         plot(cmi, pfm(ifig).rain_M1_path.(bintype{its}).mr,'-*', 'linewidth',2)
         set(gca,'XScale','log')
         xlabel('Initial L2 (collector) mode mass fraction')
         title(['(',char(96+ifig),') D_{L2m} = 50 \mum', cat_text])
         xticks([1e-5 1e-4 1e-3 1e-2 1e-1 1])
      else
         xx=dmr;
         yy1=pfm(ifig).rain_M1_path.(bintype{its}).mr;
         yy2=ones(size(yy1));
         pt=patch([xx fliplr(xx)], [yy1 fliplr(yy2)], color_order{its},'edgecolor','none',...
            'FaceAlpha', .2);
         set(get(get(pt,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

         plot(dmr, pfm(ifig).rain_M1_path.(bintype{its}).mr,'-*', 'linewidth',2)
         xlabel('Initial L2 (collector) mode D_m [\mum]')
         xlim([30 100])
         xticks([30:10:100])
         title(['(',char(96+ifig),') X_{L2} = 10^{-3}', cat_text])
      end
      ylim([0.7 1.05])
   end
   grid
   legend('TAU', 'SBM', 'location', 'best')
   hold off
   set(gca,'fontsize', 16)
end

ylabel(tl, 'AMP/bin ratio in RWP', 'fontsize', 18)
title(tl, 'Effects of autoconversion on AMP/bin RWP ratio', 'fontsize', 20, 'fontweight', 'bold')

exportgraphics(gcf,'plots/pngs/16 autoconv_rwp.png', 'Resolution', 300)
exportgraphics(gcf,'plots/16 autoconv_rwp.pdf')
