Calculations/MOT Capture Process Simulation/@MOTSimulator/calculateLoadingRate.m

68 lines
3.0 KiB
Mathematica
Raw Normal View History

function [LoadingRate, StandardError] = calculateLoadingRate(this, CaptureFraction, ClausingFactor, FinalDynamicalQuantities)
NumberOfLoadedAtoms = zeros(1, this.NumberOfAtoms);
AutocorrelationFunction = zeros(1, this.NumberOfAtoms);
for i = 1:this.NumberOfAtoms
FinalPosition = FinalDynamicalQuantities(i,1:3);
DivergenceAngle = atan(sqrt((FinalPosition(1)^2+FinalPosition(3)^2)/(FinalPosition(2)^2)));
if (DivergenceAngle <= this.MOTExitDivergence) && (FinalPosition(2) >= 0)
if i == 1
NumberOfLoadedAtoms(1) = 1;
else
NumberOfLoadedAtoms(i) = NumberOfLoadedAtoms(i-1) + 1;
end
else
if i == 1
NumberOfLoadedAtoms(1) = 0;
else
NumberOfLoadedAtoms(i) = NumberOfLoadedAtoms(i-1);
end
end
end
for i = 1:this.NumberOfAtoms-1
MeanLoadingRate = 0;
MeanLoadingRateShifted = 0;
for j = 1:this.NumberOfAtoms-i
MeanLoadingRate = MeanLoadingRate + NumberOfLoadedAtoms(j)/j;
MeanLoadingRateShifted = MeanLoadingRateShifted + (NumberOfLoadedAtoms(i+j))/(i+j);
AutocorrelationFunction(i) = AutocorrelationFunction(i) + ((NumberOfLoadedAtoms(j)/j).*(NumberOfLoadedAtoms(i+j)/(i+j)));
end
AutocorrelationFunction(i) = ((this.NumberOfAtoms-i)^-1 * (AutocorrelationFunction(i)) - ((this.NumberOfAtoms-i)^-1 * MeanLoadingRate * MeanLoadingRateShifted));
end
if AutocorrelationFunction(1)~=0 % In case no atom loading
AutocorrelationFunction = AutocorrelationFunction./AutocorrelationFunction(1);
x = linspace(1, this.NumberOfAtoms, this.NumberOfAtoms);
[FitObject,~] = fit(x',AutocorrelationFunction',"exp(-x/n)",'Startpoint', 100);
n = FitObject.n; % n is the autocorrelation factor
MeanLoadingRate = 0;
NumberOfBins = floor(this.NumberOfAtoms/(2*n+1));
LoadingRateError = zeros(1,NumberOfBins);
BinNumberLimit = min(NumberOfBins-1,5);
for i = 1:NumberOfBins-BinNumberLimit
LoadingRateError(i) = NumberOfLoadedAtoms(this.NumberOfAtoms-ceil((i-1)*(2*n+1))) / ...
(this.NumberOfAtoms-ceil((i-1)*(2*n+1)));
MeanLoadingRate = MeanLoadingRate + LoadingRateError(i);
end
MeanLoadingRate = MeanLoadingRate /(NumberOfBins-BinNumberLimit);
StandardError = 0;
for i = 1:NumberOfBins-BinNumberLimit
StandardError = StandardError + (MeanLoadingRate-LoadingRateError(i))^2;
end
StandardError = sqrt(StandardError/(NumberOfBins-BinNumberLimit));
LoadingRate = (MeanLoadingRate * this.calculateFreeMolecularRegimeFlux() * CaptureFraction * ClausingFactor);
else
LoadingRate = 0;
StandardError = 0;
end
end