nts_per_photon),'%.2f') ' +/- ' num2str(std(counts_per_photon),2)];
    disp(st);
    disp(['           Offset = ' num2str(mean(offset),'%.2f') ' +/- ' num2str(std(offset),2)])

    hold(ax,'off')
    plot(ax,pos,counts_per_photon);
    xlabel(ax,'Sample')
    ylabel(ax,'Counts per photon');
    title(ax,st)
      
    counts_per_photon = mean(counts_per_photon);
    offset = mean(offset);
    
    function r = objt(m) 
    
        if fit_offset
            offset = m(2);
        else
   