%% Compare D→S vs S→D Fit Values
% Author: Karthik
% Date:   2025-10-17

%% ---------- Load Fit Data ----------
basePath                = "C:\Users\Karthik-OfficePC\Documents\GitRepositories\Calculations\Data-Analyzer\+Scripts\";

% D→S direction
data                    = load(fullfile(basePath, "BECToDropletsToStripes\DToS_ASDFitData\fitOfMeanCurve.mat"));
DToS_MeanCurveFit       = data.fitOfMeanCurve;
data                    = load(fullfile(basePath, "BECToDropletsToStripes\DToS_ASDFitData\meanOfIndividualFits.mat"));
DToS_IndividualCurveFit = data.meanOfIndividualFits;
data                    = load(fullfile(basePath, "BECToDropletsToStripes\DToS_ASDFitData\scan_reference_values.mat"));
DToS_scanrefVals        = data.scan_reference_values;

data                    = load(fullfile(basePath, "BECToStripesToDroplets\SToD_ASDFitData\fitOfMeanCurve.mat"));
SToD_MeanCurveFit       = data.fitOfMeanCurve;
data                    = load(fullfile(basePath, "BECToStripesToDroplets\SToD_ASDFitData\meanOfIndividualFits.mat"));
SToD_IndividualCurveFit = data.meanOfIndividualFits;
data                    = load(fullfile(basePath, "BECToStripesToDroplets\SToD_ASDFitData\scan_reference_values.mat"));
SToD_scanrefVals        = data.scan_reference_values;

% --- Define plotting order and labels ---
params  = {'mu2','A2','sigma2'};
titles  = {'Secondary peak position (\theta)','Secondary peak amplitude','Secondary peak width (\sigma)'};
ylabels = {'\mu_2 (rad)','A_2','\sigma_2 (rad)'};
fontName = 'Bahnschrift';
fontSize = 14;

%% ========== Mean Curve Fits ==========
fig1 = figure('Name','Mean Curve Fits: D→S vs S→D', ...
    'Color','w', 'Position',[100 100 1750 550]);
tiledlayout(1,3, 'Padding','compact', 'TileSpacing','compact');

for i = 1:numel(params)
    nexttile;
    plot(DToS_scanrefVals, DToS_MeanCurveFit.(params{i}), 'o--', 'LineWidth',1.8, ...
        'MarkerSize',6, 'DisplayName','D→S');
    hold on;
    plot(SToD_scanrefVals, SToD_MeanCurveFit.(params{i}), 's--', 'LineWidth',1.8, ...
        'MarkerSize',6, 'DisplayName','S→D');
    grid on;

    set(gca, 'FontName', fontName, 'FontSize', fontSize);
    xlabel('\alpha (degrees)', 'Interpreter','tex', 'FontName',fontName, 'FontSize',fontSize);
    ylabel(ylabels{i}, 'Interpreter','tex', 'FontName',fontName, 'FontSize',fontSize);
    title(titles{i}, 'FontName',fontName, 'FontSize',fontSize+2, 'FontWeight','bold');
    legend('Location','northeast');
end

sgtitle('Comparison of Mean Curve Fits (D→S vs S→D)', ...
    'FontName',fontName, 'FontSize',fontSize+4, 'FontWeight','bold');

%% ========== Individual Curve Fits ==========
fig2 = figure('Name','Individual Curve Fits: D→S vs S→D', ...
    'Color','w', 'Position',[100 100 1750 550]);
tiledlayout(1,3, 'Padding','compact', 'TileSpacing','compact');

for i = 1:numel(params)
    nexttile;
    plot(DToS_scanrefVals, DToS_IndividualCurveFit.(params{i}), 'o--', 'LineWidth',1.8, ...
        'MarkerSize',6, 'DisplayName','D→S');
    hold on;
    plot(SToD_scanrefVals, SToD_IndividualCurveFit.(params{i}), 's--', 'LineWidth',1.8, ...
        'MarkerSize',6, 'DisplayName','S→D');
    grid on;

    set(gca, 'FontName', fontName, 'FontSize', fontSize);
    xlabel('\alpha (degrees)', 'Interpreter','tex', 'FontName',fontName, 'FontSize',fontSize);
    ylabel(ylabels{i}, 'Interpreter','tex', 'FontName',fontName, 'FontSize',fontSize);
    title(titles{i}, 'FontName',fontName, 'FontSize',fontSize+2, 'FontWeight','bold');
    legend('Location','northeast');
end

sgtitle('Comparison of Individual Curve Fits (D→S vs S→D)', ...
    'FontName',fontName, 'FontSize',fontSize+4, 'FontWeight','bold');
