It sounds like you have a single measurement at a single point (X=100
, e=5000
), and also know the value of the FWHM (FWHM = 4
).
If this is indeed the case, you can compute the standard deviation sigma
like so:
sigma = FWHM/ 2/sqrt(2*log(2));
and you can make bins like so:
[N, binCtr] = hist(sigma*randn(e,1) + X, Nbins);
where N
is the amount of electrons in each bin, binCtr
are the bin centers, Nbins
is the amount of bins you want to use.
If the number of electrons gets large, you could run out of memory. In such cases, it's better to do the same thing but in smaller batches, like so:
% Example data
FWHM = 4;
e = 100000;
X = 100;
Nbins = 100;
% your std. dev.
sigma = FWHM/ 2/sqrt(2*log(2));
% Find where to start with the bin edges. That is, find the point
% where the PDF indicates that at most 1 electron is expected to fall
f = @(x, mu, sigma) exp(-0.5*((x-mu)/sigma).^2)/sigma/sqrt(2*pi);
g = @(y) quadgk(@(x)f(x,X,sigma), -inf, y)*e - 1;
h = fzero(g, X-FWHM*3);
% Create initial bin edges
binEdges = [-inf linspace(h, 2*X-h, Nbins-2) +inf];
% Bin electrons in batches
c = e;
done = false;
step = 5e3;
Nout = zeros(Nbins,1);
while ~done
% electrons still to be binned
c = c - step;
% Last step
if c <= 0
step = c+step;
c = 0;
done = true;
end
% Bin the next batch
N = histc(sigma*randn(step,1) + X, binEdges);
Nout = Nout + N;
end
% Bin edges must now be re-defined
binEdges =[...
2*binEdges(2)-binEdges(3),...
binEdges(2:end-1),...
2*binEdges(end-1)-binEdges(end-2)];