Test script to fit some SLS data

This calls all models in all varieties from the nappFitGaussXps.m function. Basically, to test that it is working. The data is random, so fitting is meaningless.

Contents

Random data for 2 peaks

clc
clearvars
close all

% create data table consistent with ISS data
FitList = table;
FitList.sample = 'O1s, 120eV, m30, cps, 092022';
FitList.name = {'random.ibw'};
tmpDataSelection = matches(FitList.sample,'O1s, 120eV, m30, cps, 092022'); % This filters one specific spectrum by "sample name".

% add random data on kinetic energy scale
x = linspace(105, 120, 100)';
true_params = [99900 2 113; 29000 0.9 110.5];
y = zeros(size(x));
fwhm_to_sigma = @(fwhm) fwhm / (2*sqrt(2*log(2)));
for i = 1:size(true_params,1)
    A = true_params(i,1);
    sigma = fwhm_to_sigma(true_params(i,2));
    pos = true_params(i,3);
    y = y + A * exp(-((x - pos).^2) / (2*sigma^2));
end
y = y + (-195.*x+32980);
y = y + 1000 * randn(size(x));  % add noise
figure;
plot(x, y, 'k.');
xlabel('Kinetic Energy');
ylabel('Intensity');
title('Raw Data without Shirley Tail');
if ~ismember('scientaEkin_eV', FitList.Properties.VariableNames)
    FitList.scientaEkin_eV = cell(size(FitList,1),1);
end
if ~ismember('spectrum_countsNorm', FitList.Properties.VariableNames)
    FitList.spectrum_countsNorm = cell(size(FitList,1),1);
end
FitList(tmpDataSelection,:).scientaEkin_eV{:} = x;
FitList(tmpDataSelection,:).spectrum_countsNorm{:} = y;
index= find(FitList(tmpDataSelection,:).scientaEkin_eV{:}>113,1);
FitList(tmpDataSelection,:).spectrum_countsNorm{:}(1:index) = FitList(tmpDataSelection,:).spectrum_countsNorm{:}(1:index) + 1000;

% add random data on binding energy scale
x = linspace(42, 30, 1000)';
true_params = [800 0.4 36.2; 500 0.3 38.0];
y = zeros(size(x));
fwhm_to_sigma = @(fwhm) fwhm / (2*sqrt(2*log(2)));
for i = 1:size(true_params,1)
    A = true_params(i,1);
    sigma = fwhm_to_sigma(true_params(i,2));
    pos = true_params(i,3);
    y = y + A * exp(-((x - pos).^2) / (2*sigma^2));
end
% Simulate realistic Shirley-style background using smooth tanh transition
center = 36.5; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;
y = y + 5 * randn(size(x));  % add mild noise
figure;
plot(x, y, 'k.');
xlabel('Binding Energy');
ylabel('Intensity');
title('Raw Data with Shirley Tail');
set(gca, 'XDir', 'reverse'); grid on;
if ~ismember('bindingEnergy_eV', FitList.Properties.VariableNames)
    FitList.bindingEnergy_eV = cell(size(FitList,1),1);
end
if ~ismember('spectrum_counts', FitList.Properties.VariableNames)
    FitList.spectrum_counts = cell(size(FitList,1),1);
end
FitList(tmpDataSelection,:).bindingEnergy_eV{:} = x;
FitList(tmpDataSelection,:).spectrum_counts{:} = y;

% plot
nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_countsNorm','energyScale','kinetic');
nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_counts','energyScale','binding');

TEST 1.1: Unconstrained kinetic Gauss linear

Gaussian + Linear, individual area/width/position per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [5e5 100]; % <- 2 values => 2 peaks
tmpFitParameters.peakWidth                  = [1.6 0.6];
tmpFitParameters.peakPos                    = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [1.0 0.6];
tmpFitParameters.peakWidthUpperBound        =  [2.0 1.2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [112 109];
tmpFitParameters.peakPosUpperBound          =  [114  111];
tmpFitParameters.backgroundRange            = [12 6]; % <- selects fit range around peak1

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','unconstrained','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name           peakPosition  
    ______________    ________________

    {'random.ibw'}    112.99     110.5

         name                 peakArea        
    ______________    ________________________

    {'random.ibw'}    2.1226e+05         27727

         name           peakFWHM  
    ______________    ____________

    {'random.ibw'}    2    0.88526

         name           peakBackground  
    ______________    __________________

    {'random.ibw'}    -332.34      49032

TEST 1.2: Unconstrained kinetic PV linear

Pseudo-Voigt + Linear, individual area/width/eta/position per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [5e5 100];
tmpFitParameters.peakWidth                  = [1.6 0.6];
tmpFitParameters.peakPos                    = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [1.0 0.6];
tmpFitParameters.peakWidthUpperBound        =  [2.0 1.2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [112 109];
tmpFitParameters.peakPosUpperBound          =  [114  111];
tmpFitParameters.backgroundRange            = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                   = [1 1];   % <- Gauss - Lorentzian ratio
 tmpFitParameters.peakEtaLowerBound         = [0 0 ];
 tmpFitParameters.peakEtaUpperBound         = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','unconstrained','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2

TEST 1.3: Unconstrained kinetic Gauss Shirley

Gaussian + Shirley, individual area/width/position per peak, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth             = [1.6 0.6];
tmpFitParameters.peakPos         = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.0 0.6];
tmpFitParameters.peakWidthUpperBound     =  [2.0 1.2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.001, 0.001];  % <- K controls Shirley step magnitude
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [10, 10];
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','unconstrained','backgroundMode','shirley','showFigures','off'); % <- background is now Shirley
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name           peakPosition              peakArea              peakFWHM      peakBackground
    ______________    ________________    ________________________    ____________    ______________

    {'random.ibw'}    113.01    110.51    2.1191e+05         26111    2    0.85481      0    10088  

         name          peakEta          peakShirleyK    
    ______________    __________    ____________________

    {'random.ibw'}    NaN    NaN    0.014409    0.010989

TEST 1.4: Unconstrained kinetic PV Shirley

Pseudo-Voigt + Shirley, individual area/width/eta/position per peak, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth             = [1.6 0.6];
tmpFitParameters.peakPos         = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.0 0.6];
tmpFitParameters.peakWidthUpperBound     =  [2.0 1.2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];       % <- Gauss - Lorentzian ratio
 tmpFitParameters.peakEtaLowerBound      = [0.0 0.0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.001, 0.001];   % <- K controls Shirley step magnitude
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [10, 10];
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','unconstrained','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name           peakPosition              peakArea              peakFWHM      peakBackground
    ______________    ________________    ________________________    ____________    ______________

    {'random.ibw'}    113.01    110.51    2.1524e+05         25896    2    0.85069      0    9897   

         name              peakEta              peakShirleyK    
    ______________    __________________    ____________________

    {'random.ibw'}    0.96301          1    0.013671    0.019616

TEST 1.5: Unconstrained binding Gauss linear

Gaussian + Linear, individual area/width/position per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [1e5 100];
tmpFitParameters.peakWidth                  = [1.6 1.6 ];
tmpFitParameters.peakPos                    = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound        =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [37 35];
tmpFitParameters.peakPosUpperBound          =  [39 37];

tmpFitParameters.backgroundRange            = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...    % <- process binding energy
    'mode','unconstrained','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name         peakPosition
    ______________    ____________

    {'random.ibw'}     38    36.2 

         name             peakArea    
    ______________    ________________

    {'random.ibw'}    161.41    339.54

         name              peakFWHM     
    ______________    __________________

    {'random.ibw'}    0.30274    0.39891

         name          peakBackground 
    ______________    ________________

    {'random.ibw'}    4.499    -66.192

TEST 1.5.2: Unconstrained binding Gauss linear

Gaussian + Linear, individual area/width/position per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [1e5 1e4 100]; % <- 3 peaks
tmpFitParameters.peakWidth                  = [1.6 1.6 1.6];
tmpFitParameters.peakPos                    = [38 37 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [1e2 1e2 1e2];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [0.2 0.2 0.2];
tmpFitParameters.peakWidthUpperBound        =  [2.0 2 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [37 37 35];
tmpFitParameters.peakPosUpperBound          =  [39 37.5 37];

tmpFitParameters.backgroundRange            = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','unconstrained','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 3

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 3 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    38.002      37.5    36.198

         name                  peakArea         
    ______________    __________________________

    {'random.ibw'}    141.14       100    331.37

         name                   peakFWHM           
    ______________    _____________________________

    {'random.ibw'}    0.27818          2    0.39199

         name          peakBackground  
    ______________    _________________

    {'random.ibw'}    3.7559    -45.397

TEST 1.6: Unconstrained binding PV linear

Pseudo-Voigt + Linear, individual area/width/eta/position per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [1e5 100]; % <- back to 2 peaks
tmpFitParameters.peakWidth                  = [1.6 1.6 ];
tmpFitParameters.peakPos                    = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound        =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [37 35];
tmpFitParameters.peakPosUpperBound          =  [39 37];
tmpFitParameters.backgroundRange            = [12 6];
% PSEUDO-VOIGT + LINEAR variant:
 tmpFitParameters.peakEta                   = [1 1];
 tmpFitParameters.peakEtaLowerBound         = [0 0 ];
 tmpFitParameters.peakEtaUpperBound         = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','unconstrained','backgroundMode','linear','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition                peakArea                       peakFWHM                peakBackground  
    ______________    __________________    __________________________    _____________________________    _________________

    {'random.ibw'}    38    36.2     NaN    166.69    339.68       NaN    0.29956      0.399        NaN    4.4343    -64.288

         name                    peakEta                 peakShirleyK   
    ______________    _____________________________    _________________

    {'random.ibw'}    0.89096          1        NaN    NaN    NaN    NaN

TEST 1.7: Unconstrained binding Gauss Shirley

Gaussian + Shirley, individual area/width/position per peak, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [1e5 100];
tmpFitParameters.peakWidth                  = [1.6 1.6 ];
tmpFitParameters.peakPos                    = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound        =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [37 35];
tmpFitParameters.peakPosUpperBound          =  [39 37];
tmpFitParameters.backgroundRange            = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK             = [0.01, 0.01];  % <- K controls Shirley step magnitude
  tmpFitParameters.peakShirleyKLowerBound   = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound   = [100, 100];
  tmpFitParameters.peakShirleyOffset        = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','unconstrained','backgroundMode','shirley','showFigures','off');

quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

2 out of 3 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.997    36.197       NaN    158.68    344.57       NaN    0.29936    0.40291        NaN     0    80.681  

         name              peakEta                   peakShirleyK          
    ______________    _________________    ________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.090928    0.060519         NaN

TEST 1.8: Unconstrained binding PV Shirley

Pseudo-Voigt + Shirley, individual area/width/eta/position per peak, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [1e5 100];
tmpFitParameters.peakWidth                  = [1.6 1.6 ];
tmpFitParameters.peakPos                    = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound        =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  [37 35];
tmpFitParameters.peakPosUpperBound          =  [39 37];
tmpFitParameters.backgroundRange            = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                   = [1 1];
 tmpFitParameters.peakEtaLowerBound         = [0 0 ];
 tmpFitParameters.peakEtaUpperBound         = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK             = [0.01, 0.01];  % <- K controls Shirley step magnitude
  tmpFitParameters.peakShirleyKLowerBound   = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound   = [100, 100];
  tmpFitParameters.peakShirleyOffset        = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','unconstrained','backgroundMode','shirley','showFigures','off');

quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.997    36.198       NaN    159.35    357.04       NaN    0.30019    0.39955        NaN     0    79.747  

         name                 peakEta                     peakShirleyK          
    ______________    _______________________    _______________________________

    {'random.ibw'}    1    0.89055        NaN    0.10961    0.052005         NaN

TEST 2.1: Position-Constrained kinetic Gaussian Linear

Gaussian + Linear, first peak position free, other peaks offset fixed

clc
clearvars tmpFitParameters;
tmpFitParameters.peakArea                   = [1e5 1e5]; % <- 2 peaks
tmpFitParameters.peakWidth                  = [2 1];
tmpFitParameters.peakPos                    = [113 -2.32]; % <- pos peak #2 is relative to peak #1
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [1E4 1E4];
tmpFitParameters.peakAreaUpperBound         =  [1E6 1E6];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [1.5 0.6];
tmpFitParameters.peakWidthUpperBound        =  [2.5 1.5];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  112.5; % <- only pos 1 is fitted
tmpFitParameters.peakPosUpperBound          =  113.5;
tmpFitParameters.backgroundRange            = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','position','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                             peakFWHM                peakBackground  
    ______________    __________________________    ______________________________________    ____________________________    __________________

    {'random.ibw'}    112.98    110.66       NaN    2.0893e+05         27722           NaN    1.9636    0.96037        NaN    -323.76      48305

         name              peakEta           peakShirleyK   
    ______________    _________________    _________________

    {'random.ibw'}    NaN    NaN    NaN    NaN    NaN    NaN

TEST 2.2: Position-Constrained kinetic PV Linear

Pseudo-Voigt + Linear, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 1e5];
tmpFitParameters.peakWidth              = [2 1];
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1E4 1E4];
tmpFitParameters.peakAreaUpperBound      =  [1E6 1E6];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.5 0.6];
tmpFitParameters.peakWidthUpperBound     =  [2.5 1.5];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112.5;
tmpFitParameters.peakPosUpperBound       =  113.5;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','position','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                             peakFWHM                peakBackground  
    ______________    __________________________    ______________________________________    ____________________________    __________________

    {'random.ibw'}    112.98    110.66       NaN    2.0881e+05         28143           NaN    1.9628    0.95856        NaN    -321.99      48089

         name                 peakEta              peakShirleyK   
    ______________    _______________________    _________________

    {'random.ibw'}    1    0.95559        NaN    NaN    NaN    NaN

TEST 2.3: Position-Constrained kinetic Gauss Shirley

Gaussian + Shirley, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
tmpFitParameters.peakArea               = [1e5 1e5];
tmpFitParameters.peakWidth              = [2 1];
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1E4 1E4];
tmpFitParameters.peakAreaUpperBound      =  [1E6 1E6];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.5 0.6];
tmpFitParameters.peakWidthUpperBound     =  [2.5 1.5];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112.5;
tmpFitParameters.peakPosUpperBound       =  113.5;
tmpFitParameters.backgroundRange        = [12 6];
 % SHIRLEY:
  tmpFitParameters.peakShirleyK           = [0.01, 0.001];
  tmpFitParameters.peakShirleyKLowerBound = [0.0, 0.0];
  tmpFitParameters.peakShirleyKUpperBound = [Inf, Inf];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','position','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM              peakBackground
    ______________    __________________________    ______________________________________    ___________________________    ______________

    {'random.ibw'}    112.98    110.66       NaN    2.1721e+05         27055           NaN    2.012    0.91594        NaN     0    9838.1  

         name              peakEta                      peakShirleyK             
    ______________    _________________    ______________________________________

    {'random.ibw'}    NaN    NaN    NaN    1.1215e-17       0.15213           NaN

TEST 2.4: Position-Constrained kinetic PV Shirley

Pseudo-Voigt + Shirley, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 1e5];
tmpFitParameters.peakWidth              = [2 1];
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1E4 1E4];
tmpFitParameters.peakAreaUpperBound      =  [1E6 1E6];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.5 0.6];
tmpFitParameters.peakWidthUpperBound     =  [2.5 1.5];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112.5;
tmpFitParameters.peakPosUpperBound       =  113.5;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
 % SHIRLEY:
  tmpFitParameters.peakShirleyK           = [0.01, 0.001];
  tmpFitParameters.peakShirleyKLowerBound = [0.0, 0.0];
  tmpFitParameters.peakShirleyKUpperBound = [Inf, Inf];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','position','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    112.97    110.65       NaN    2.2521e+05         26167           NaN    2.01    0.89985        NaN     0    9379.8  

         name                    peakEta                            peakShirleyK             
    ______________    _____________________________    ______________________________________

    {'random.ibw'}    0.90898          1        NaN    1.1167e-17       0.16586           NaN

TEST 2.5: Position binding Gauss linear

Gaussian + Linear, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = [1.6 1.6 ];
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound     =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','position','backgroundMode','linear','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition                peakArea                       peakFWHM                peakBackground 
    ______________    __________________    __________________________    _____________________________    ________________

    {'random.ibw'}    38    36.2     NaN    161.41    339.54       NaN    0.30274    0.39891        NaN    4.499    -66.193

         name              peakEta           peakShirleyK   
    ______________    _________________    _________________

    {'random.ibw'}    NaN    NaN    NaN    NaN    NaN    NaN

TEST 2.6: Position binding PV linear

Pseudo-Voigt + Linear, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = [1.6 1.6 ];
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound     =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT + LINEAR variant:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','position','backgroundMode','linear','showFigures','on');
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition   
    ______________    __________________

    {'random.ibw'}    38    36.2     NaN

         name                 peakArea         
    ______________    _________________________

    {'random.ibw'}    166.7    339.68       NaN

         name                   peakFWHM           
    ______________    _____________________________

    {'random.ibw'}    0.29956    0.39901        NaN

         name          peakBackground  
    ______________    _________________

    {'random.ibw'}    4.4342    -64.285

         name                    peakEta           
    ______________    _____________________________

    {'random.ibw'}    0.89075          1        NaN

TEST 2.7: Position binding Gauss Shirley

Gaussian + Shirley, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = [1.6 1.6 ];
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound     =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','position','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.997    36.197       NaN    158.68    344.56       NaN    0.29935     0.4029        NaN     0    80.679  

         name              peakEta                   peakShirleyK          
    ______________    _________________    ________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.090755    0.060597         NaN

TEST 2.8: Position binding PV Shirley

Pseudo-Voigt + Shirley, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = [1.6 1.6 ];
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound     =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];  % <- 1 K for each peak
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','position','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 4 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.997    36.197       NaN    159.22    356.34       NaN    0.30002    0.39958        NaN     0    79.756  

         name                 peakEta                     peakShirleyK         
    ______________    _______________________    ______________________________

    {'random.ibw'}    1    0.89508        NaN    0.1062    0.053513         NaN

TEST 2.9: Position kinetic PV Shirley shared

Pseudo-Voigt + Shirley, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [1e5 1e5];
tmpFitParameters.peakWidth                  = [2 1];
tmpFitParameters.peakPos                    = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [1E4 1E4];
tmpFitParameters.peakAreaUpperBound         =  [1E6 1E6];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  [1.5 0.6];
tmpFitParameters.peakWidthUpperBound        =  [2.5 1.5];
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  112.5;
tmpFitParameters.peakPosUpperBound          =  113.5;
tmpFitParameters.backgroundRange            = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                   = [1 1];
 tmpFitParameters.peakEtaLowerBound         = [0 0];
 tmpFitParameters.peakEtaUpperBound         = [1.0, 1.0];
 % SHIRLEY:
  tmpFitParameters.peakShirleyK             = 0.01;  % <- same K for all peaks
  tmpFitParameters.peakShirleyKLowerBound   = 0.0;
  tmpFitParameters.peakShirleyKUpperBound   = Inf;
  tmpFitParameters.peakShirleyOffset        = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','positionShirley','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    112.99    110.67       NaN    2.0881e+05         26346           NaN    1.9658    0.9424       NaN      0    10519  

         name             peakEta                peakShirleyK         
    ______________    _______________    _____________________________

    {'random.ibw'}    1      1    NaN    0.01253    0.01253        NaN

TEST 2.10: Position kinetic Gauss Shirley Shared

Gaussian + Shirley, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
tmpFitParameters.peakArea               = [1e5 1e5];
tmpFitParameters.peakWidth              = [2 1];
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1E4 1E4];
tmpFitParameters.peakAreaUpperBound      =  [1E6 1E6];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.5 0.6];
tmpFitParameters.peakWidthUpperBound     =  [2.5 1.5];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112.5;
tmpFitParameters.peakPosUpperBound       =  113.5;
tmpFitParameters.backgroundRange        = [12 6];
 % SHIRLEY:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.0;
  tmpFitParameters.peakShirleyKUpperBound = Inf;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','positionShirley','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    112.99    110.67       NaN    2.0881e+05         26346           NaN    1.9658    0.9424       NaN      0    10519  

         name              peakEta                 peakShirleyK         
    ______________    _________________    _____________________________

    {'random.ibw'}    NaN    NaN    NaN    0.01253    0.01253        NaN

TEST 2.11: Position binding Gauss Shirley Shared

Gaussian + Shirley, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = [1.6 1.6 ];
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound     =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','positionShirley','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 4 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.997    36.197       NaN    158.03    343.26       NaN    0.29852     0.4019        NaN     0    80.547  

         name              peakEta                   peakShirleyK          
    ______________    _________________    ________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.069475    0.069475         NaN

TEST 2.12: Position binding PV Shirley Shared

Pseudo-Voigt + Shirley, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = [1.6 1.6 ];
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [0.2 0.2];
tmpFitParameters.peakWidthUpperBound     =  [2.0 2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','positionShirley','backgroundMode','shirley','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 4 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    37.997    36.197       NaN

         name                  peakArea         
    ______________    __________________________

    {'random.ibw'}    158.05    348.71       NaN

         name                   peakFWHM           
    ______________    _____________________________

    {'random.ibw'}    0.29854    0.39983        NaN

         name         peakBackground
    ______________    ______________

    {'random.ibw'}     0    80.022  

         name                 peakEta        
    ______________    _______________________

    {'random.ibw'}    1    0.94589        NaN

         name                   peakShirleyK          
    ______________    ________________________________

    {'random.ibw'}    0.069109    0.069109         NaN

TEST 3.1: widthPosition kinetic Gauss linear

Gaussian + Linear, shared width, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea                   = [5e5 100]; % <- 2 peaks
tmpFitParameters.peakWidth                  = 1.6; % <- one width for all peaks
tmpFitParameters.peakPos                    = [113 -2.32]; % <- positions relative to peak1
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound         =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound         =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound        =  1.0;
tmpFitParameters.peakWidthUpperBound        =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound          =  112;
tmpFitParameters.peakPosUpperBound          =  114;
tmpFitParameters.backgroundRange            = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPosition','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                          peakFWHM              peakBackground  
    ______________    __________________________    ______________________________________    _______________________    __________________

    {'random.ibw'}    113.04    110.72       NaN    2.0058e+05         41563           NaN    1.867    1.867      NaN    -269.69      41861

         name              peakEta           peakShirleyK   
    ______________    _________________    _________________

    {'random.ibw'}    NaN    NaN    NaN    NaN    NaN    NaN

TEST 3.2: widthPosition kinetic PV linear

Pseudo-Voigt + Linear, shared width, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112;
tmpFitParameters.peakPosUpperBound       =  114;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPosition','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM               peakBackground  
    ______________    __________________________    ______________________________________    __________________________    __________________

    {'random.ibw'}    113.04    110.72       NaN    1.9879e+05         53903           NaN    1.8688    1.8688       NaN    -224.69      36273

         name                 peakEta              peakShirleyK   
    ______________    _______________________    _________________

    {'random.ibw'}    1    0.40299        NaN    NaN    NaN    NaN

TEST 3.3: widthPosition kinetic Gauss Shirley

Gaussian + Shirley, shared width, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112;
tmpFitParameters.peakPosUpperBound       =  114;
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.001, 0.001];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [10, 10];
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPosition','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    113.04    110.72       NaN    2.0367e+05         41896           NaN    1.8806    1.8806       NaN      0    10361  

         name              peakEta                peakShirleyK        
    ______________    _________________    ___________________________

    {'random.ibw'}    NaN    NaN    NaN    0.001    0.05436        NaN

TEST 3.4: widthPosition kinetic PV Shirley

Pseudo-Voigt + Shirley, shared width, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112;
tmpFitParameters.peakPosUpperBound       =  114;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0.0 0.0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.001, 0.001];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [10, 10];
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPosition','backgroundMode','shirley','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    113.04    110.72       NaN

         name                        peakArea               
    ______________    ______________________________________

    {'random.ibw'}    2.0064e+05         55404           NaN

         name                  peakFWHM         
    ______________    __________________________

    {'random.ibw'}    1.8783    1.8783       NaN

         name         peakBackground
    ______________    ______________

    {'random.ibw'}     0    9972.6  

         name                 peakEta        
    ______________    _______________________

    {'random.ibw'}    1    0.35861        NaN

         name                 peakShirleyK         
    ______________    _____________________________

    {'random.ibw'}    0.001    0.034913         NaN

TEST 3.5: widthPosition binding Gauss linear

Gaussian + Linear, shared width, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPosition','backgroundMode','linear','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition                peakArea                       peakFWHM                peakBackground  
    ______________    __________________    __________________________    _____________________________    _________________

    {'random.ibw'}    38    36.2     NaN    178.45    329.79       NaN    0.37613    0.37613        NaN    4.2762    -58.777

         name              peakEta           peakShirleyK   
    ______________    _________________    _________________

    {'random.ibw'}    NaN    NaN    NaN    NaN    NaN    NaN

TEST 3.6: widthPosition binding PV linear

Pseudo-Voigt + Linear, shared width, first peak position free, other peaks offset fixed

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT + LINEAR variant:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPosition','backgroundMode','linear','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

1 out of 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition                peakArea                       peakFWHM                peakBackground  
    ______________    __________________    __________________________    _____________________________    _________________

    {'random.ibw'}    38    36.2     NaN    177.35    347.05       NaN    0.36994    0.36994        NaN    4.2705    -59.821

         name                 peakEta              peakShirleyK   
    ______________    _______________________    _________________

    {'random.ibw'}    1    0.82672        NaN    NaN    NaN    NaN

TEST 3.7: widthPosition binding Gauss Shirley

Gaussian + Shirley, shared width, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPosition','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 11 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.198       NaN    177.53    334.34       NaN    0.37884    0.37884        NaN     0    81.607  

         name              peakEta                   peakShirleyK          
    ______________    _________________    ________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.083602    0.051366         NaN

TEST 3.8: widthPosition binding PV Shirley

Pseudo-Voigt + Shirley, shared width, first peak position free, other peaks offset fixed, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPosition','backgroundMode','shirley','showFigures','off');

quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.198       NaN    176.87    376.53       NaN    0.36743    0.36743        NaN      0    78.42  

         name                 peakEta                     peakShirleyK          
    ______________    _______________________    _______________________________

    {'random.ibw'}    1    0.63825        NaN    0.13562    0.028569         NaN

TEST 3.9: widthPosition kinetic Gauss Shirley Shared

Gaussian + Shirley, shared width, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112;
tmpFitParameters.peakPosUpperBound       =  114;
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.001;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 10;
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPositionShirley','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    113.04    110.72       NaN    2.0056e+05         40339           NaN    1.8695    1.8695       NaN      0    10531  

         name              peakEta                    peakShirleyK            
    ______________    _________________    ___________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.0091774    0.0091774          NaN

TEST 3.10: widthPosition kinetic PV Shirley Shared

Pseudo-Voigt + Shirley, shared width, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112;
tmpFitParameters.peakPosUpperBound       =  114;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0.0 0.0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.1;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 10;
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPositionShirley','backgroundMode','shirley','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    113.04    110.72       NaN

         name                        peakArea               
    ______________    ______________________________________

    {'random.ibw'}    1.9813e+05         56900           NaN

         name                  peakFWHM         
    ______________    __________________________

    {'random.ibw'}    1.8704    1.8704       NaN

         name         peakBackground
    ______________    ______________

    {'random.ibw'}      0    10166  

         name                 peakEta        
    ______________    _______________________

    {'random.ibw'}    1    0.26558        NaN

         name                    peakShirleyK            
    ______________    ___________________________________

    {'random.ibw'}    0.0060439    0.0060439          NaN

TEST 3.11: widthPosition binding Gauss Shirley Shared

Gaussian + Shirley, shared width, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];   % <- Too many parameters,
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001]; % Will run anyway
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];     % but show a warning.
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPositionShirley','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

24 out of 25 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.198       NaN    176.65    332.86       NaN    0.37769    0.37769        NaN     0    81.436  

         name              peakEta                   peakShirleyK          
    ______________    _________________    ________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.061951    0.061951         NaN

TEST 3.12: widthPosition binding PV Shirley Shared

Pseudo-Voigt + Shirley, shared width, first peak position free, other peaks offset fixed, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPositionShirley','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.198       NaN    174.65    360.94       NaN    0.36721    0.36721        NaN     0    78.743  

         name                 peakEta                      peakShirleyK          
    ______________    _______________________    ________________________________

    {'random.ibw'}    1    0.72536        NaN    0.061437    0.061437         NaN

TEST 3.13: widthPosition kinetic PV Shirley & Eta Shared

Pseudo-Voigt + Shirley, shared width, first peak position free, other peaks offset fixed, shared Shirley K, shared PV eta

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 -2.32];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  112;
tmpFitParameters.peakPosUpperBound       =  114;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = 1;
 tmpFitParameters.peakEtaLowerBound      = 0.0;
 tmpFitParameters.peakEtaUpperBound      = 1.0;
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.1;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 10;
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPositionShirleyEta','backgroundMode','shirley','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    113.04    110.72       NaN

         name                        peakArea               
    ______________    ______________________________________

    {'random.ibw'}    2.0056e+05         40339           NaN

         name                  peakFWHM         
    ______________    __________________________

    {'random.ibw'}    1.8695    1.8695       NaN

         name         peakBackground
    ______________    ______________

    {'random.ibw'}      0    10531  

         name             peakEta    
    ______________    _______________

    {'random.ibw'}    1      1    NaN

         name                    peakShirleyK            
    ______________    ___________________________________

    {'random.ibw'}    0.0091774    0.0091774          NaN

TEST 3.14: widthPosition binding PV Shirley & Eta Shared

Pseudo-Voigt + Shirley, shared width, first peak position free, other peaks offset fixed, shared Shirley K and PV eta

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 -1.8];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  37;
tmpFitParameters.peakPosUpperBound       =  39;
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = 1;
 tmpFitParameters.peakEtaLowerBound      = 0;
 tmpFitParameters.peakEtaUpperBound      = 1.0;
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPositionShirleyEta','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.198       NaN    181.63    341.72       NaN    0.37433    0.37433        NaN     0    80.449  

         name                    peakEta                         peakShirleyK          
    ______________    _____________________________    ________________________________

    {'random.ibw'}    0.90968    0.90968        NaN    0.059933    0.059933         NaN

TEST 4.1: Width kinetic Gauss linear

Gaussian + Linear, shared width, individual areas and positions

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              =  1.6;
tmpFitParameters.peakPos                = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','width','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM               peakBackground  
    ______________    __________________________    ______________________________________    __________________________    __________________

    {'random.ibw'}    113.03    110.63       NaN    2.0228e+05         41618           NaN    1.8803    1.8803       NaN    -259.91      40642

         name              peakEta           peakShirleyK   
    ______________    _________________    _________________

    {'random.ibw'}    NaN    NaN    NaN    NaN    NaN    NaN

TEST 4.2: Width kinetic PV linear

Pseudo-Voigt + Linear, shared width, individual areas, positions, and etas

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','width','backgroundMode','linear','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM              peakBackground 
    ______________    __________________________    ______________________________________    __________________________    ________________

    {'random.ibw'}    113.04    110.61       NaN    1.9965e+05         64093           NaN    1.8879    1.8879       NaN    -172.1     29768

         name                 peakEta              peakShirleyK   
    ______________    _______________________    _________________

    {'random.ibw'}    1    0.08888        NaN    NaN    NaN    NaN

TEST 4.3: Width kinetic Gauss Shirley

Gaussian + Shirley, shared width, individual areas and positions, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        =  [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.001, 0.001];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [10, 10];
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','width','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    113.03    110.65       NaN    2.0463e+05         42032           NaN    1.8892    1.8892       NaN      0    10381  

         name              peakEta                 peakShirleyK         
    ______________    _________________    _____________________________

    {'random.ibw'}    NaN    NaN    NaN    0.001    0.049002         NaN

TEST 4.4: Width kinetic PV Shirley

Pseudo-Voigt + Shirley, shared width, individual areas, positions, and etas, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0.0 0.0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.001, 0.001];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [10, 10];
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','width','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                          peakFWHM            peakBackground
    ______________    __________________________    ______________________________________    _______________________    ______________

    {'random.ibw'}    113.04     110.6       NaN    2.0006e+05         67979           NaN    1.893    1.893      NaN     0    9671.6  

         name                    peakEta                       peakShirleyK         
    ______________    _____________________________    _____________________________

    {'random.ibw'}    1    1.7875e-12           NaN    0.001    0.016524         NaN

TEST 4.5: Width binding Gauss linear

Gaussian + Linear, shared width, individual areas and positions

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              =  1.6;
tmpFitParameters.peakPos                = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [37 35];
tmpFitParameters.peakPosUpperBound       =  [39 37];
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','width','backgroundMode','linear','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition                peakArea                       peakFWHM                peakBackground  
    ______________    __________________    __________________________    _____________________________    _________________

    {'random.ibw'}    38    36.2     NaN    178.45    329.79       NaN    0.37613    0.37613        NaN    4.2763    -58.783

         name              peakEta           peakShirleyK   
    ______________    _________________    _________________

    {'random.ibw'}    NaN    NaN    NaN    NaN    NaN    NaN

TEST 4.6: Width binding PV linear

Pseudo-Voigt + Linear, shared width, individual areas, positions, and etas

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [37 35];
tmpFitParameters.peakPosUpperBound       =  [39 37];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT + LINEAR variant:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','width','backgroundMode','linear','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 17 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name            peakPosition                peakArea                       peakFWHM                peakBackground  
    ______________    __________________    __________________________    _____________________________    _________________

    {'random.ibw'}    38    36.2     NaN    177.35    347.04       NaN    0.36994    0.36994        NaN    4.2706    -59.824

         name                 peakEta              peakShirleyK   
    ______________    _______________________    _________________

    {'random.ibw'}    1    0.82681        NaN    NaN    NaN    NaN

TEST 4.7: Width binding Gauss Shirley

Gaussian + Shirley, shared width, individual areas and positions, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [37 35];
tmpFitParameters.peakPosUpperBound       =  [39 37];
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','width','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.997    36.198       NaN    177.64    334.52       NaN    0.37898    0.37898        NaN     0    81.633  

         name              peakEta                   peakShirleyK          
    ______________    _________________    ________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.086202    0.050048         NaN

TEST 4.8: Width binding PV Shirley

Pseudo-Voigt + Shirley, shared width, individual areas, positions, and etas, Shirley K per peak

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [37 35];
tmpFitParameters.peakPosUpperBound       =  [39 37];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = [0.01, 0.01];
  tmpFitParameters.peakShirleyKLowerBound = [0.001, 0.001];
  tmpFitParameters.peakShirleyKUpperBound = [100, 100];
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','width','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 7 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.995      36.2       NaN    177.27    379.09       NaN    0.36755    0.36755        NaN     0    78.411  

         name                peakEta                    peakShirleyK          
    ______________    _____________________    _______________________________

    {'random.ibw'}    1    0.6252       NaN    0.14837    0.022886         NaN

TEST 4.9: Width kinetic Gauss Shirley Shared

Gaussian + Shirley, shared width, individual areas and positions, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        =  [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.001;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 10;
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthShirley','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    113.04    110.64       NaN    2.0225e+05         40491           NaN    1.8825    1.8825       NaN      0    10468  

         name              peakEta                    peakShirleyK            
    ______________    _________________    ___________________________________

    {'random.ibw'}    NaN    NaN    NaN    0.0086228    0.0086228          NaN

TEST 4.10: Width kinetic PV Shirley Shared

Pseudo-Voigt + Shirley, shared width, individual areas, positions, and etas, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [113 110];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [1e3 1e3];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [112 109];
tmpFitParameters.peakPosUpperBound       =  [114  111];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT:
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0.0 0.0];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.001;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 10;
  tmpFitParameters.peakShirleyOffset      = 1E4;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthShirley','backgroundMode','shirley','showFigures','off');
quickPlotKinetic(FitList,tmpDataSelection)
Validating FitParameter structure...
  Number of peaks detected: 2
Found 2 valid peaks (non-NaN)
         name                peakPosition                          peakArea                            peakFWHM             peakBackground
    ______________    __________________________    ______________________________________    __________________________    ______________

    {'random.ibw'}    113.04     110.6       NaN    1.9912e+05         67333           NaN    1.8892    1.8892       NaN     0    9850.2  

         name                    peakEta                          peakShirleyK            
    ______________    _____________________________    ___________________________________

    {'random.ibw'}    1    2.7303e-14           NaN    0.0035491    0.0035491          NaN

TEST 4.11: Width binding Gauss Shirley Shared

Gaussian + Shirley, shared width, individual areas and positions, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [37 35];
tmpFitParameters.peakPosUpperBound       =  [39 37];
tmpFitParameters.backgroundRange        = [12 6];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthShirley','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 12 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.197       NaN    176.65    332.86       NaN    0.37769    0.37769        NaN     0    81.434  

         name              peakEta                 peakShirleyK         
    ______________    _________________    _____________________________

    {'random.ibw'}    NaN    NaN    NaN    0.06196    0.06196        NaN

TEST 4.12: Width binding PV Shirley Shared

Pseudo-Voigt + Shirley, shared width, individual areas and positions, shared Shirley K

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [1e5 100];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [38 36];
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0.01 0.01];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.2;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [37 35];
tmpFitParameters.peakPosUpperBound       =  [39 37];
tmpFitParameters.backgroundRange        = [12 6];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = [1 1];
 tmpFitParameters.peakEtaLowerBound      = [0 0 ];
 tmpFitParameters.peakEtaUpperBound      = [1.0, 1.0];
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.01;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthShirley','backgroundMode','shirley','showFigures','off');
quickPlotBinding(FitList,tmpDataSelection)
xlim([34,39])
Validating FitParameter structure...
  Number of peaks detected: 2

GlobalSearch stopped because it analyzed all the trial points.

All 14 local solver runs converged with a positive local solver exit flag.
Found 2 valid peaks (non-NaN)
         name                peakPosition                    peakArea                       peakFWHM               peakBackground
    ______________    __________________________    __________________________    _____________________________    ______________

    {'random.ibw'}    37.998    36.198       NaN    174.65    360.96       NaN    0.36721    0.36721        NaN     0    78.737  

         name                 peakEta                      peakShirleyK          
    ______________    _______________________    ________________________________

    {'random.ibw'}    1    0.72518        NaN    0.061454    0.061454         NaN

Random data for 5 peaks

clc
close all
% binding
x = linspace(50, 30, 1000)';
true_params = [800 1.6 36.2; 500 1.6 38.0;1000 0.3 39.0;800 1.6 40;500 1.6 40.5];
y = zeros(size(x));
fwhm_to_sigma = @(fwhm) fwhm / (2*sqrt(2*log(2)));
for i = 1:size(true_params,1)
    A = true_params(i,1);
    sigma = fwhm_to_sigma(true_params(i,2));
    pos = true_params(i,3);
    y = y + A * exp(-((x - pos).^2) / (2*sigma^2));
end
% Simulate realistic Shirley-style background using smooth tanh transition
center = 36.2; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;

center = 38; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;

center = 40; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;

center = 40.5; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;


y = y + 5 * randn(size(x));  % add mild noise
figure;
plot(x, y, 'k.');
xlabel('Binding Energy');
ylabel('Intensity');
title('Raw Data with Shirley Tail');
set(gca, 'XDir', 'reverse'); grid on;
hold on;
if ~ismember('bindingEnergy_eV', FitList.Properties.VariableNames)
    FitList.bindingEnergy_eV = cell(size(FitList,1),1);
end
if ~ismember('spectrum_counts', FitList.Properties.VariableNames)
    FitList.spectrum_counts = cell(size(FitList,1),1);
end
FitList(tmpDataSelection,:).bindingEnergy_eV{:} = x;
FitList(tmpDataSelection,:).spectrum_counts{:} = y;

nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_counts','energyScale','binding');


% kinetic
x = linspace(30, 45, 1000)';
true_params = [800 1.6 36.2; 500 1.6 38.0;1000 0.3 39.0;800 1.6 40;500 1.6 40.5];
y = zeros(size(x));
fwhm_to_sigma = @(fwhm) fwhm / (2*sqrt(2*log(2)));
for i = 1:size(true_params,1)
    A = true_params(i,1);
    sigma = fwhm_to_sigma(true_params(i,2));
    pos = true_params(i,3);
    y = y + A * exp(-((x - pos).^2) / (2*sigma^2));
end
y = y + 5 * randn(size(x));  % add mild noise
figure;
plot(x, y, 'k.');
xlabel('Kinetic Energy');
ylabel('Intensity');
title('Raw Data without Shirley Tail');
grid on;
hold on;

FitList(tmpDataSelection,:).scientaEkin_eV{:} = x;
FitList(tmpDataSelection,:).spectrum_countsNorm{:} = y;

nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_countsNorm','energyScale','kinetic');

Test 5.0 Custom ModelunconstrainedAndWidthPosition, kinetic, linear

Custom: Gaussian + Linear, shared width for 2 peaks, individual area/position for 5 peaks (peak count must match hardcoded equation: 5 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 5e5 5e5 5e5 5e5];
tmpFitParameters.peakWidth              = [1.6 0.6];
tmpFitParameters.peakPos                = [-1.8 38 39 41 41] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0 0 0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.0 0.1];
tmpFitParameters.peakWidthUpperBound     =  [2.0 1.2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [-1.8 38 39 41 41]-1;
tmpFitParameters.peakPosUpperBound       =  [-1.8 38 39 41 41]+1;
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','unconstrainedAndWidthPosition','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5
Found 5 valid peaks (non-NaN)
         name                         peakPosition                
    ______________    ____________________________________________

    {'random.ibw'}    36.2    37.997        39        40    40.507

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1359.5     853.1     321.4    1373.6    840.22

         name                              peakFWHM                     
    ______________    __________________________________________________

    {'random.ibw'}    1.5961     1.5961    0.30004     1.5961     1.5961

         name             peakBackground    
    ______________    ______________________

    {'random.ibw'}    -0.031208        1.246

Test 5.1 Custom ModelunconstrainedAndWidthPosition, binding, linear

Custom: Gaussian + Linear, shared width for 2 peaks, individual area/position for 5 peaks (peak count must match hardcoded equation: 5 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 5e5 5e5 5e5 5e5];
tmpFitParameters.peakWidth              = [1.6 0.6];
tmpFitParameters.peakPos                = [-1.8 38 39 41 41] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0 0 0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1.0 0.1];
tmpFitParameters.peakWidthUpperBound     =  [2.0 1.2];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [-1.8 38 39 41 41]-1;
tmpFitParameters.peakPosUpperBound       =  [-1.8 38 39 41 41]+1;
tmpFitParameters.backgroundRange        = [12 12];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','unconstrainedAndWidthPosition','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5

GlobalSearch stopped because it analyzed all the trial points.

27 out of 30 local solver runs converged with a positive local solver exit flag.
Found 5 valid peaks (non-NaN)
         name                          peakPosition                 
    ______________    ______________________________________________

    {'random.ibw'}    36.218    38.036    39.001    40.146    41.171

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1333.6    853.51    329.61    2055.8    219.92

         name                              peakFWHM                     
    ______________    __________________________________________________

    {'random.ibw'}    1.5999     1.5999    0.30481     1.5999     1.5999

         name          peakBackground  
    ______________    _________________

    {'random.ibw'}    11.364    -54.982

Test 5.3 Custom widthPositionAmineAreaRatio, kinetic, linear

Custom: Gaussian + Linear, shared width, constrained area ratios, 5 peaks with position/area constraints (peak count must match hardcoded equation: 5 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 5e5 1 5e5 5e5];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 1.8 2.8 3.8 5.5 6] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0 0 0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  34;
tmpFitParameters.peakPosUpperBound       =  36;
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPositionAmineAreaRatio','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5
Found 5 valid peaks (non-NaN)
         name                    peakPosition           
    ______________    __________________________________

    {'random.ibw'}    36    37.8    38.8    39.8    41.5

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1716.2    592.77    592.77    2423.3    905.56

         name               peakFWHM       
    ______________    _____________________

    {'random.ibw'}    2    2    2    2    2

         name           peakBackground  
    ______________    __________________

    {'random.ibw'}    -21.402     667.62

Test 5.4 Custom gasAndTwoAcidBasePairs, kinetic, linear

Custom: Gaussian + Linear, 2 shared widths, constrained to acid-base pair model, 5 peaks (peak count must match hardcoded equation: 5 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 5e5 5e5 5e5 5e5];
tmpFitParameters.peakWidth              = [1 0.3];
tmpFitParameters.peakPos                = [-1 36 39 -1 41] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [100 100 100 100 100];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1 0.1];
tmpFitParameters.peakWidthUpperBound     =  [1.6 1];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [-1 37 39 -1 41]-1 ;
tmpFitParameters.peakPosUpperBound       =  [-1 37 39 -1 41]+1 ;
tmpFitParameters.backgroundRange        = [12 12];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','gasAndTwoAcidBasePairs','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5
Found 5 valid peaks (non-NaN)
         name                         peakPosition                
    ______________    ____________________________________________

    {'random.ibw'}    36.2    37.997        39    39.997    40.504

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1359.3    852.88    321.29    1360.3    853.74

         name                              peakFWHM                     
    ______________    __________________________________________________

    {'random.ibw'}    1.5959     1.5959    0.29999     1.5959     1.5959

         name            peakBackground   
    ______________    ____________________

    {'random.ibw'}    -0.02561      1.0647

Test 5.5 Custom gasAndTwoAcidBasePairs, binding, linear

Custom: Gaussian + Linear, 2 shared widths, constrained to acid-base pair model, 5 peaks (peak count must match hardcoded equation: 5 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 5e5 5e5 5e5 5e5];
tmpFitParameters.peakWidth              = [1 0.3];
tmpFitParameters.peakPos                = [-1 36 39 -1 41] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [100 100 100 100 100];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  [1 0.1];
tmpFitParameters.peakWidthUpperBound     =  [1.6 1];
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [-1 37 39 -1 41]-1 ;
tmpFitParameters.peakPosUpperBound       =  [-1 37 39 -1 41]+1 ;
tmpFitParameters.backgroundRange        = [12 12];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','gasAndTwoAcidBasePairs','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 5 valid peaks (non-NaN)
         name                         peakPosition                 
    ______________    _____________________________________________

    {'random.ibw'}    36.21        38        39    40.068    40.791

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1311.7     840.6     330.9    1780.9    478.83

         name                              peakFWHM                     
    ______________    __________________________________________________

    {'random.ibw'}    1.5726     1.5726    0.30548     1.5726     1.5726

         name          peakBackground  
    ______________    _________________

    {'random.ibw'}    12.414    -90.617

Test 5.6 Custom widthPositionAreaRatio, kinetic, linear

Custom: Gaussian + Linear, shared width, fixed area ratios from first peak, 5 peaks (peak count must match hardcoded equation: 5 peaks)

% pos 2-5 of area bounds and position bounds are not used for fitting, but
% function requires during input validation that these vectors are non NaN
% and have same length as peakArea. Therefore we need a workaround: set
% values to 0.
clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 1 1 1 1]; % <- area ratio rel to peak #1
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 2 3 4 5] ; % <- position relative to peak #1
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0 0 0]; % <- workaround
tmpFitParameters.peakAreaUpperBound      =  [Inf 0 0 0 0];% <- workaround
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.5;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [34 0 0 0 0];% <- workaround
tmpFitParameters.peakPosUpperBound       =  [36 0 0 0 0];% <- workaround
tmpFitParameters.backgroundRange        = [12 12];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','widthPositionAreaRatio','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5
Found 5 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    36    38    39    40    41

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    975.33    975.33    975.33    975.33    975.33

         name                            peakFWHM                   
    ______________    ______________________________________________

    {'random.ibw'}    1.6527    1.6527    1.6527    1.6527    1.6527

         name           peakBackground  
    ______________    __________________

    {'random.ibw'}    -4.4239      157.4

Test 5.7 Custom widthPositionAreaRatio, binding, linear

Custom: Gaussian + Linear, shared width, fixed area ratios from first peak, 5 peaks (peak count must match hardcoded equation: 5 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 1 1 1 1];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 2 3 4 5] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0 0 0]; % <- workaround
tmpFitParameters.peakAreaUpperBound      =  [Inf 0 0 0 0];% <- workaround
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  0.5;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [34 0 0 0 0];% <- workaround
tmpFitParameters.peakPosUpperBound       =  [36 0 0 0 0];% <- workaround
tmpFitParameters.backgroundRange        = [12 12];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','widthPositionAreaRatio','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 5

GlobalSearch stopped because it analyzed all the trial points.

All 5 local solver runs converged with a positive local solver exit flag.
Found 5 valid peaks (non-NaN)
         name                peakPosition       
    ______________    __________________________

    {'random.ibw'}    36    38    39    40    41

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    961.76    961.76    961.76    961.76    961.76

         name                            peakFWHM                   
    ______________    ______________________________________________

    {'random.ibw'}    1.6351    1.6351    1.6351    1.6351    1.6351

         name          peakBackground  
    ______________    _________________

    {'random.ibw'}    10.816    -31.968

Random data for 4 peaks

clc
close all
% binding
x = linspace(50, 30, 1000)';
true_params = [800 1.6 36; 400 1.6 37.0;800 1.6 40;500 1.6 41];
y = zeros(size(x));
fwhm_to_sigma = @(fwhm) fwhm / (2*sqrt(2*log(2)));
for i = 1:size(true_params,1)
    A = true_params(i,1);
    sigma = fwhm_to_sigma(true_params(i,2));
    pos = true_params(i,3);
    y = y + A * exp(-((x - pos).^2) / (2*sigma^2));
end
% Simulate realistic Shirley-style background using smooth tanh transition
center = 36; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;

center = 37; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;

center = 40; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;

center = 401; width = 3;
shirley_step = 75 + 45 * (1 + tanh((x - center)/width))/2;
y = y + shirley_step;


y = y + 5 * randn(size(x));  % add mild noise
figure;
plot(x, y, 'k.');
xlabel('Binding Energy');
ylabel('Intensity');
title('Raw Data with Shirley Tail');
set(gca, 'XDir', 'reverse'); grid on;
hold on;
if ~ismember('bindingEnergy_eV', FitList.Properties.VariableNames)
    FitList.bindingEnergy_eV = cell(size(FitList,1),1);
end
if ~ismember('spectrum_counts', FitList.Properties.VariableNames)
    FitList.spectrum_counts = cell(size(FitList,1),1);
end
FitList(tmpDataSelection,:).bindingEnergy_eV{:} = x;
FitList(tmpDataSelection,:).spectrum_counts{:} = y;

nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_counts','energyScale','binding');


% kinetic
x = linspace(30, 45, 1000)';
true_params = [800 1.6 36; 400 1.6 37.0;800 1.6 40;400 1.6 41];
y = zeros(size(x));
fwhm_to_sigma = @(fwhm) fwhm / (2*sqrt(2*log(2)));
for i = 1:size(true_params,1)
    A = true_params(i,1);
    sigma = fwhm_to_sigma(true_params(i,2));
    pos = true_params(i,3);
    y = y + A * exp(-((x - pos).^2) / (2*sigma^2));
end
y = y + 5 * randn(size(x));  % add mild noise
figure;
plot(x, y, 'k.');
xlabel('Kinetic Energy');
ylabel('Intensity');
title('Raw Data without Shirley Tail');
grid on;
hold on;

FitList(tmpDataSelection,:).scientaEkin_eV{:} = x;
FitList(tmpDataSelection,:).spectrum_countsNorm{:} = y;

nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_countsNorm','energyScale','kinetic');

Test 6.0 Custom TwoSpinOrbitDoublet, kinetic, linear

Custom: Gaussian + Linear, shared width, positions are relative, spin-orbit doublet pair model with intensity ratios, 4 peaks (peak count must match hardcoded equation: 4 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 0.5 5e5 0.5];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 1 4] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0  0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [34 NaN 3];
tmpFitParameters.peakPosUpperBound       =  [36 NaN 5];
tmpFitParameters.backgroundRange        = [12 6];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','TwoSpinOrbitDoublet','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 4
Found 4 valid peaks (non-NaN)
         name                        peakPosition               
    ______________    __________________________________________

    {'random.ibw'}    36        37    40.001    41.001       NaN

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1364.3    682.16    1365.7    682.87       NaN

         name                            peakFWHM                   
    ______________    ______________________________________________

    {'random.ibw'}    1.6027    1.6027    1.6027    1.6027       NaN

         name            peakBackground   
    ______________    ____________________

    {'random.ibw'}    -0.12453      3.7123

Test 6.1 Custom TwoSpinOrbitDoublet, binding, linear

Custom: Gaussian + Linear, spin-orbit doublet pair model with intensity ratios, 4 peaks (peak count must match hardcoded equation: 4 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 0.5 5e5 0.5];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 1 4] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0  0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [34 NaN 3];
tmpFitParameters.peakPosUpperBound       =  [36 NaN 5];
tmpFitParameters.backgroundRange        = [12 12];

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','TwoSpinOrbitDoublet','backgroundMode','linear','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 4

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 4 valid peaks (non-NaN)
         name                        peakPosition               
    ______________    __________________________________________

    {'random.ibw'}    36        37    40.062    41.062       NaN

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1380.1    690.03    1528.5    764.25       NaN

         name                         peakFWHM                 
    ______________    _________________________________________

    {'random.ibw'}    1.661    1.661    1.661    1.661      NaN

         name          peakBackground  
    ______________    _________________

    {'random.ibw'}    9.5173    0.47017

Test 6.2 Custom TwoSpinOrbitDoublet, kinetic, Shirley

Custom: Pseudo-Voigt + Shirley, spin-orbit doublet pair model with intensity ratios, shared Shirley K, 4 peaks (peak count must match hardcoded equation: 4 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 0.5 5e5 0.5];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 1 4] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0  0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [34 NaN 3];
tmpFitParameters.peakPosUpperBound       =  [36 NaN 5];
tmpFitParameters.backgroundRange        = [12 12];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = 1;
 tmpFitParameters.peakEtaLowerBound      = 0;
 tmpFitParameters.peakEtaUpperBound      = 1.0;
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.0001;
  tmpFitParameters.peakShirleyKLowerBound = 0;
  tmpFitParameters.peakShirleyKUpperBound = 0.0001;
  tmpFitParameters.peakShirleyOffset      = 0;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_countsNorm','energyScale','kinetic',...
    'mode','TwoSpinOrbitDoubletPseudoVoigtShirley','backgroundMode','shirley','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 4
Found 4 valid peaks (non-NaN)
         name                        peakPosition               
    ______________    __________________________________________

    {'random.ibw'}    36        37    40.001    41.001       NaN

         name                           peakArea                  
    ______________    ____________________________________________

    {'random.ibw'}    1362    681.01    1362.5    681.25       NaN

         name                            peakFWHM                   
    ______________    ______________________________________________

    {'random.ibw'}    1.6001    1.6001    1.6001    1.6001       NaN

         name         peakBackground 
    ______________    _______________

    {'random.ibw'}    0    1.9145e-08

         name                    peakEta           
    ______________    _____________________________

    {'random.ibw'}    1      1      1      1    NaN

         name                                 peakShirleyK                         
    ______________    _____________________________________________________________

    {'random.ibw'}    6.422e-13    6.422e-13    6.422e-13    6.422e-13          NaN

Test 6.3 Custom TwoSpinOrbitDoubletPseudoVoigtShirley, binding, Shirley

Custom: Pseudo-Voigt + Shirley, spin-orbit doublet pair model with intensity ratios, shared Shirley K, 4 peaks (peak count must match hardcoded equation: 4 peaks)

clearvars tmpFitParameters;
clc
tmpFitParameters.peakArea               = [5e5 0.5 5e5 0.5];
tmpFitParameters.peakWidth              = 1.6;
tmpFitParameters.peakPos                = [36 1 4] ;
% Bounds for areas (lower and upper)
tmpFitParameters.peakAreaLowerBound      =  [0 0 0  0];
tmpFitParameters.peakAreaUpperBound      =  [Inf Inf Inf Inf];
% Bounds for widths
tmpFitParameters.peakWidthLowerBound     =  1.0;
tmpFitParameters.peakWidthUpperBound     =  2.0;
% Bounds for positions
tmpFitParameters.peakPosLowerBound       =  [34 NaN 3];
tmpFitParameters.peakPosUpperBound       =  [36 NaN 5];
tmpFitParameters.backgroundRange        = [12 12];
% PSEUDO-VOIGT
 tmpFitParameters.peakEta                = 1;
 tmpFitParameters.peakEtaLowerBound      = 0;
 tmpFitParameters.peakEtaUpperBound      = 1.0;
% SHIRLEY variant:
  tmpFitParameters.peakShirleyK           = 0.1;
  tmpFitParameters.peakShirleyKLowerBound = 0.001;
  tmpFitParameters.peakShirleyKUpperBound = 100;
  tmpFitParameters.peakShirleyOffset      = 80;

FitList = nappFitGaussXps(FitList,tmpFitParameters,tmpDataSelection,...
    'tableVariable','spectrum_counts','energyScale','binding',...
    'mode','TwoSpinOrbitDoubletPseudoVoigtShirley','backgroundMode','shirley','showFigures','on');
Validating FitParameter structure...
  Number of peaks detected: 4

GlobalSearch stopped because it analyzed all the trial points.

All 2 local solver runs converged with a positive local solver exit flag.
Found 4 valid peaks (non-NaN)
         name                         peakPosition                 
    ______________    _____________________________________________

    {'random.ibw'}    35.99     36.99    40.037    41.037       NaN

         name                            peakArea                   
    ______________    ______________________________________________

    {'random.ibw'}    1397.3    698.64    1495.5    747.77       NaN

         name                         peakFWHM                 
    ______________    _________________________________________

    {'random.ibw'}    1.651    1.651    1.651    1.651      NaN

         name         peakBackground
    ______________    ______________

    {'random.ibw'}     0    305.54  

         name                    peakEta           
    ______________    _____________________________

    {'random.ibw'}    1      1      1      1    NaN

         name                               peakShirleyK                      
    ______________    ________________________________________________________

    {'random.ibw'}    0.029178    0.029178    0.029178    0.029178         NaN

Helper Functions

function quickPlotKinetic(FitList,tmpDataSelection)
% Plot Data
close all
nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_countsNorm','energyScale','kinetic');
ax = gca;
lines = findobj(ax, '-regexp', 'Type', 'line');
set(lines, 'LineStyle', 'none', 'Marker', 'o', 'MarkerSize', 5);
nappAddFitToPlot(FitList,tmpDataSelection,'energyScale','kinetic')
try
    disp(FitList(tmpDataSelection,["name","peakPosition","peakArea","peakFWHM","peakBackground"]))

    disp(FitList(tmpDataSelection,["name","peakEta","peakShirleyK"]))
catch
    disp(FitList(tmpDataSelection,["sample","name","peakPosition","peakArea","peakFWHM"]))
end
end

function quickPlotBinding(FitList,tmpDataSelection)
% Plot Data
close all
nappPlot(FitList,tmpDataSelection,'tableVariable','spectrum_counts','energyScale','binding');
ax = gca;
lines = findobj(ax, '-regexp', 'Type', 'line');
set(lines, 'LineStyle', 'none', 'Marker', 'o', 'MarkerSize', 5);
nappAddFitToPlot(FitList,tmpDataSelection,'energyScale','binding')
try
    disp(FitList(tmpDataSelection,["name","peakPosition","peakArea","peakFWHM","peakBackground"]))

    disp(FitList(tmpDataSelection,["name","peakEta","peakShirleyK"]))
catch
    disp(FitList(tmpDataSelection,["sample","name","peakPosition","peakArea","peakFWHM"]))
end
end
Found 2 valid peaks (non-NaN)
         name         peakPosition            peakArea              peakFWHM        peakBackground  
    ______________    ____________    ________________________    ____________    __________________

    {'random.ibw'}    113    110.5    2.1207e+05         29330    2    0.87332    -325.54      48185

         name           peakEta      peakShirleyK
    ______________    ___________    ____________

    {'random.ibw'}    1    0.8266     NaN    NaN