Ticket #7383: fitLowStats.m

File fitLowStats.m, 972 bytes (added by Mike Thomas, 7 years ago)
Line 
1NB = 10000; %Number of bins
2
3
4for x = 1:200
5        lam(x) = exp((x-75.0)/10); %Expected rate
6        Xarr = 1:NB; %Time bins
7        Yarr = randraw('po',lam(x),NB); %Actual Counts
8        Earr = sqrt(Yarr); %Errors
9        [rate(x), ~] = fminbnd(@(A) flatBG(Xarr,Yarr,Earr,A),0,10*lam(x)); %Fit using Gaussian Cost function
10        [ratePo(x),~] = fminbnd(@(A) flatBGpo(Xarr,Yarr,Earr,A),0,10*lam(x)); %Fit using Poisson Cost Function
11end
12figure;
13%Plot differences
14diff = lam-rate;
15diffPo = lam-ratePo;
16ratio = lam./rate;
17ratioPo = lam./ratePo;
18subplot(2,1,1);
19semilogx(lam,diff);
20hold on
21semilogx(lam,diffPo,'r');
22title('Poisson Fit Difference')
23xlabel('count rate')
24ylabel('count rate - calculated rate');
25legend('Least Squares', 'Poisson')
26subplot(2,1,2);
27semilogx(lam,ratio);
28hold on
29semilogx(lam,ratioPo,'r');
30title('Poisson Fit Ratio')
31xlabel('count rate')
32ylabel('count rate/calculated rate');
33legend('Least Squares', 'Poisson')
34