Added model with 5 features: acid-base, gas-phase, acid-base. Both acid-base (feature 1,2,4,5) have one fixed and one relative BE. Position and width of gas-phase feature is unconstrained.

This commit is contained in:
bartels-rausch committed 2023-11-16 07:14:25 +01:00
1 parent 1aa130982f
commit 3a0a97fe88
1 file changed
+101 -9
+101 -9
View File
@@ -66,7 +66,7 @@ function DataTable = nappFitGaussXps(DataTable,~,varargin)
% spectrum range
% tmpFitParameters.backgroundRange = [5 5];
%
% % „ unconstrainedAndWidthPosition" mode (novel: rel distance fit parameter)
% % „unconstrainedAndWidthPosition" mode (novel: rel distance fit parameter)
% tmpFitParameters.peakArea = [abs#1 abs#2 abs#3 abs#4 abs#5];
% tmpFitParameters.peakWidth = [abs#1,2,4,5 abs#3];
% tmpFitParameters.peakPos = [rel#1 abs#2 abs#3 abs#4 abs#5];
@@ -80,6 +80,21 @@ function DataTable = nappFitGaussXps(DataTable,~,varargin)
% spectrum range
% tmpFitParameters.backgroundRange = [5 5];
%
% % „gasAndTwoAcidBasePairs" mode (novel: rel distance fit parameter)
% tmpFitParameters.peakArea = [abs#1 abs#2 abs#3 abs#4 abs#5];
% tmpFitParameters.peakWidth = [abs#1,2,4,5 abs#3];
% tmpFitParameters.peakPos = [rel#1 abs#2 abs#3 rel#4 abs#5]; % rel#4
% is realative to abs#5, rel#1 is relative to abs#2
%
% tmpFitParameters.peakAreaUpperBond = [#1 #2 #3 #4 #5];
% tmpFitParameters.peakWidthUpperBond = [#1,2,4,5 #3];
% tmpFitParameters.peakPosUpperBond = [#1 #2 #3 #4 #5];
% tmpFitParameters.peakAreaLowerBond = [#1 #2 #3 #4 #5];
% tmpFitParameters.peakWidthLowerBond = [#1,2,4,5 #3];
% tmpFitParameters.peakPosLowerBond = [#1 #2 #3 #4 #5];
% spectrum range
% tmpFitParameters.backgroundRange = [5 5];
%
%
% tableSelection (optional): logical array to filter data table
% tableVariable (optional): select source: image(default),'imageRoh'
@@ -108,7 +123,7 @@ function DataTable = nappFitGaussXps(DataTable,~,varargin)
defaultTableVariable = 'spectrum_countsPerSecond';
expectedTableVariable = {'spectrum_counts','spectrum_countsPerSecond','spectrum_countsNorm'};
defaultMode = 'widthPosition';
expectedMode = {'unconstrained','widthPosition','position','width','unconstrainedAndWidthPosition'};
expectedMode = {'unconstrained','widthPosition','position','width','unconstrainedAndWidthPosition','gasAndTwoAcidBasePairs'};
defaultTableSelection = true(size(DataTable,1),1);
defaultShowFigures = 'on';
expectedShowFigures = {'on','off'};
@@ -118,7 +133,7 @@ expectedEnergyScale = {'kinetic','binding'};
% Parse input
p = inputParser;
addRequired(p,'DataTable',@istable); % TODO: allow combinedSpectrum input.
addRequired(p,'DataTable',@istable);
addRequired(p,'FitParameter',@isstruct);
addOptional(p,'tableSelection',defaultTableSelection,@islogical);
addParameter(p,'tableVariable',defaultTableVariable,...
@@ -309,6 +324,42 @@ elseif matches(p.Results.mode,'unconstrainedAndWidthPosition') % Novum, also the
p.Results.FitParameter.peakAreaUpperBond(1,5) p.Results.FitParameter.peakPosUpperBond(1,5) ... % Gauss peak 4
Inf Inf ... % linear background
p.Results.FitParameter.peakPosUpperBond(1,1)]; % shift upper bond
elseif matches(p.Results.mode,'gasAndTwoAcidBasePairs') % Novum, also the distance between peaks is a fit parameter.
% [Gauss = area/(width*sqrt(pi/2)) * exp(-2*(x-position)^2/width^2)]
yfcn1 = @(tmpB,x)...
tmpB(1)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - (tmpB(3)+tmpB(14))).^2/tmpB(2).^2)) ... % Gauss peak 1: width and position
+ tmpB(4)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(3)).^2/tmpB(2).^2))... % Gauss peak 2: width and position
+ tmpB(5)/(tmpB(6)*sqrt(pi/2))*exp(-2.*((x(:,1) - tmpB(7)).^2/tmpB(6).^2))... % Gauss peak 3: unconstrained
+ tmpB(8)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1) - (tmpB(11)+tmpB(9))).^2/tmpB(2).^2))... % Gauss peak 4: width and position
+ tmpB(10)/(tmpB(2)*sqrt(pi/2))*exp(-2.*((x(:,1)- tmpB(11)).^2/tmpB(2).^2))... % Gauss peak 5: width and position
+ tmpB(12).*x(:,1)+tmpB(13); % linear background
% initial value
B0= [p.Results.FitParameter.peakArea(1,1) p.Results.FitParameter.peakWidth(1,1) p.Results.FitParameter.peakPos(1,2)... % Gauss peak 1
p.Results.FitParameter.peakArea(1,2) ... % Gauss peak 2
p.Results.FitParameter.peakArea(1,3) p.Results.FitParameter.peakWidth(1,2) p.Results.FitParameter.peakPos(1,3)... % Gauss peak 3
p.Results.FitParameter.peakArea(1,4) p.Results.FitParameter.peakPos(1,4)... % Gauss peak 4
p.Results.FitParameter.peakArea(1,5) p.Results.FitParameter.peakPos(1,5)... % Gauss peak 5
1 0 ... % linear background
p.Results.FitParameter.peakPos(1,1)];
% lower bonds
lb = [p.Results.FitParameter.peakAreaLowerBond(1,1) p.Results.FitParameter.peakWidthLowerBond(1,1) p.Results.FitParameter.peakPosLowerBond(1,2) ... % Gauss peak 1
p.Results.FitParameter.peakAreaLowerBond(1,2) ... % Gauss peak 2
p.Results.FitParameter.peakAreaLowerBond(1,3) p.Results.FitParameter.peakWidthLowerBond(1,2) p.Results.FitParameter.peakPosLowerBond(1,3) ... % Gauss peak 3
p.Results.FitParameter.peakAreaLowerBond(1,4) p.Results.FitParameter.peakPosLowerBond(1,4) ...
p.Results.FitParameter.peakAreaLowerBond(1,5) p.Results.FitParameter.peakPosLowerBond(1,5) ...% Gauss peak 4
-Inf -Inf ... % linear background
p.Results.FitParameter.peakPosLowerBond(1,1)];
% upper bond
ub = [p.Results.FitParameter.peakAreaUpperBond(1,1) p.Results.FitParameter.peakWidthUpperBond(1,1) p.Results.FitParameter.peakPosUpperBond(1,2) ... % Gauss peak 1
p.Results.FitParameter.peakAreaUpperBond(1,2) ... % Gauss peak 2
p.Results.FitParameter.peakAreaUpperBond(1,3) p.Results.FitParameter.peakWidthUpperBond(1,2) p.Results.FitParameter.peakPosUpperBond(1,3) ... % Gauss peak 3
p.Results.FitParameter.peakAreaUpperBond(1,4) p.Results.FitParameter.peakPosUpperBond(1,4) ...
p.Results.FitParameter.peakAreaUpperBond(1,5) p.Results.FitParameter.peakPosUpperBond(1,5) ... % Gauss peak 4
Inf Inf ... % linear background
p.Results.FitParameter.peakPosUpperBond(1,1)]; % shift upper bond
end
for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
@@ -401,6 +452,13 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
tmpB(8) tmpB(2) tmpB(9)...
tmpB(12) tmpB(13) ...
tmpB(10) tmpB(2) tmpB(11)];
elseif matches(p.Results.mode,'gasAndTwoAcidBasePairs')
B = [tmpB(1) tmpB(2) tmpB(3)+tmpB(14)...
tmpB(4) tmpB(2) tmpB(3)...
tmpB(5) tmpB(6) tmpB(7)...
tmpB(8) tmpB(2) tmpB(11)+tmpB(9)...
tmpB(12) tmpB(13) ...
tmpB(10) tmpB(2) tmpB(11)];
end
% print out result table and result plots based on B. Because B has the
@@ -414,6 +472,30 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
disp('Fit results')
disp(p.Results.DataTable(p.Results.tableSelection,:).name{ii});
disp(' ' );
if (B(1) <= 1 || B(4) <= 1)
disp(cell2table({sprintf('%.1f',B(3)),...
sprintf('%.1f',B(2)*sqrt(log(4))),...
sprintf('%.1f',B(2)),...
sprintf('%.3f',B(1));...
sprintf('%.1f',B(6)),...
sprintf('%.1f',B(5)*sqrt(log(4))),...
sprintf('%.1f',B(5)),...
sprintf('%.3f',B(4));...
sprintf('%.1f',B(9)),...
sprintf('%.1f',B(8)*sqrt(log(4))),...
sprintf('%.1f',B(8)),...
sprintf('%.3f',B(7));...
sprintf('%.1f',B(12)),...
sprintf('%.1f',B(11)*sqrt(log(4))),...
sprintf('%.1f',B(11)),...
sprintf('%.3f',B(10)); ...
sprintf('%.1f',B(17)),...
sprintf('%.1f',B(16)*sqrt(log(4))),...
sprintf('%.1f',B(16)),...
sprintf('%.3f',B(15))},...
'VariableNames',{'position';'FWHW';'width';'area'},...
'RowNames',{'peak1','peak2','peak3','peak4','peak5'})); % 'RowNames',{'peak1','peak2','peak3','peak4','peak5'}));
else
disp(cell2table({sprintf('%.1f',B(3)),...
sprintf('%.1f',B(2)*sqrt(log(4))),...
sprintf('%.1f',B(2)),...
@@ -436,7 +518,7 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
sprintf('%7.0f',B(15))},...
'VariableNames',{'position';'FWHW';'width';'area'},...
'RowNames',{'peak1','peak2','peak3','peak4','peak5'})); % 'RowNames',{'peak1','peak2','peak3','peak4','peak5'}));
end
% plot result
% eliminate NaN in B
B(isnan(B))=0.01;
@@ -460,11 +542,11 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
yData_pk4= Gauss(xGaussPlot ,B(10), B(12), B(11));
yData_pk5= Gauss(xGaussPlot ,B(15), B(17), B(16));
bkgrd = linear(xGaussPlot,B(13),B(14));
% plot data
plot(x1,y1,'.')
hold on
% plot fit
h = plot(xGaussPlot,yData_pk1+yData_pk2+yData_pk3+yData_pk4+yData_pk5+bkgrd);
hold on
h.LineWidth=2;
h.Color = PsiFarbe.dunkelblau;
% plot each gauss peak
@@ -484,10 +566,20 @@ for ii = 1:size(p.Results.DataTable(p.Results.tableSelection,:),1)
h.LineWidth=1.5;
h.Color = PsiFarbe.gelb;
plot(xGaussPlot, bkgrd);
set(ax(1),'Xdir','reverse');
if x1(1)<= x1(end)
xlabel('Kinetic Energy [eV]');
else
set(ax(1),'Xdir','reverse');
xlabel('Binding Energy [eV]');
end
% plot data
plot(x1,y1,'o',"MarkerFaceColor","white")
legend OFF
xlabel('Binding Energy [eV]');
if matches(p.Results.tableVariable,'spectrum_countsPerSecond')
ylabel('PE Intensity [counts per second]');
else
ylabel('PE intensity [-]');
end
grid on
end
% Write results to List, we need all fitting results