 
for i=1:length(CSingleStates)
    
CSingleStates(1,i).monocounts=SinglePhotonizer(CSingleStates(1,i).counts);
end

for i=1:length(CSingleStates)
CSingleStates(1,i).int10=timewindow(CSingleStates(1,i).counts,10);
CSingleStates(1,i).int20=timewindow(CSingleStates(1,i).counts,20);
CSingleStates(1,i).int50=timewindow(CSingleStates(1,i).counts,50);
CSingleStates(1,i).int100=timewindow(CSingleStates(1,i).counts,100);
end

for i=1:length(CSingleStates)
CSingleStates(1,i).eff10=efficiency(CSingleStates(1,i).int10);
CSingleStates(1,i).eff20=efficiency(CSingleStates(1,i).int20);
CSingleStates(1,i).eff50=efficiency(CSingleStates(1,i).int50);
CSingleStates(1,i).eff100=efficiency(CSingleStates(1,i).int100);
end
for i=1:length(SingleStateSeries)
VarMean10(i,1:2)=SingleStateSeries(1,i).varmeanNP10;   
VarMean15(i,1:2)=SingleStateSeries(1,i).varmeanNP15;
VarMean20(i,1:2)=SingleStateSeries(1,i).varmeanNP20;
VarMean21(i,1:2)=SingleStateSeries(1,i).varmeanNP21;
VarMean25(i,1:2)=SingleStateSeries(1,i).varmeanNP25;
VarMean30(i,1:2)=SingleStateSeries(1,i).varmeanNP30;
end
for i=1:length(SingleStateSeries)
    l=length(SingleStateSeries(1,i).counts)  ; 
VarMean10(i,3)=l;
VarMean15(i,3)=l;
VarMean20(i,3)=l;
VarMean21(i,3)=l;
VarMean25(i,3)=l;
VarMean30(i,3)=l;
end
for i=1:length(SingleStateSeries)

    NP10=NPanalyse(SinglePhotonizer(SingleStateSeries(1,i).counts),5,10);
    NP15=NPanalyse(SinglePhotonizer(SingleStateSeries(1,i).counts),5,15);
    NP20=NPanalyse(SinglePhotonizer(SingleStateSeries(1,i).counts),5,20);
    NP21=NPanalyse(SinglePhotonizer(SingleStateSeries(1,i).counts),5,21);
    NP25=NPanalyse(SinglePhotonizer(SingleStateSeries(1,i).counts),5,25);
    NP30=NPanalyse(SinglePhotonizer(SingleStateSeries(1,i).counts),5,30);
    SingleStateSeries(1,i).varmeanNP10=[var(NP10),mean(NP10)];
    SingleStateSeries(1,i).varmeanNP15=[var(NP15),mean(NP15)];
    SingleStateSeries(1,i).varmeanNP20=[var(NP20),mean(NP20)];
    SingleStateSeries(1,i).varmeanNP21=[var(NP21),mean(NP21)];
    SingleStateSeries(1,i).varmeanNP25=[var(NP25),mean(NP25)];
    SingleStateSeries(1,i).varmeanNP30=[var(NP30),mean(NP30)];
    clear NP10 NP15 NP20 NP21 NP25 NP30
end

%% Night job

for i=1:length(CSingleStates)
    exN=max(max(CSingleStates(1,i).counts));
%     maxW=length(CSingleStates(1,i).monocounts);
%     totalD=length(find(CSingleStates(1,i).monocounts(:,1)));
%     totalA=length(find(CSingleStates(1,i).monocounts(:,2)));
    
CSingleStates(1,i).maxCounts=exN;
% CSingleStates(1,i).NP2_10=NPanalyse(CSingleStates(1,i).monocounts, 2, 10);
% CSingleStates(1,i).NP2_20=NPanalyse(CSingleStates(1,i).monocounts, 2, 20);
% 
% CSingleStates(1,i).NPmaxP=NPanalyse(CSingleStates(1,i).monocounts, exN, exN);
% CSingleStates(1,i).NPmaxPtw1=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+1);
CSingleStates(1,i).NPhalfmaxPtwmax=NPanalyse(CSingleStates(1,i).monocounts, ceil(exN/2), exN);
CSingleStates(1,i).NPmaxminus10Ptwmax=NPanalyse(CSingleStates(1,i).monocounts, exN-10, exN);
CSingleStates(1,i).NPmaxPtw2=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+2);
CSingleStates(1,i).NPmaxPtw3=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+3);
CSingleStates(1,i).NPmaxPtw4=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+4);
CSingleStates(1,i).NPmaxPtw5=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+5);
CSingleStates(1,i).NPmaxPtw6=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+6);
CSingleStates(1,i).NPmaxPtw7=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+7);
CSingleStates(1,i).NPmaxPtw8=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+8);
CSingleStates(1,i).NPmaxPtw9=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+9);
CSingleStates(1,i).NPmaxPtw10=NPanalyse(CSingleStates(1,i).monocounts, exN, exN+10);
CSingleStates(1,i).NPmaxPtw2p5max=NPanalyse(CSingleStates(1,i).monocounts, exN, ceil(1.5*exN));
CSingleStates(1,i).NPmaxPtw2max=NPanalyse(CSingleStates(1,i).monocounts, exN, 2*exN);
CSingleStates(1,i).NPmaxPtw2p5max=NPanalyse(CSingleStates(1,i).monocounts, exN, ceil(2.5*exN));
CSingleStates(1,i).NPmaxPtw3max=NPanalyse(CSingleStates(1,i).monocounts, exN, 3*exN);
CSingleStates(1,i).NPmaxPtw2p5max=NPanalyse(CSingleStates(1,i).monocounts, exN, ceil(3.5*exN));
CSingleStates(1,i).NPmaxPtw3max=NPanalyse(CSingleStates(1,i).monocounts, exN, 4*exN);
end




%%
for i=1:length(CSingleStates)

end

for i=1:length(CSingleStates)
check(i,1)=length(CSingleStates(1,i).NPhalfmaxPtwmax);
check(i,2)=length(CSingleStates(1,i).NPmaxminus10Ptwmax);
% check(i,3)=length(CSingleStates(1,i).NP2max_Wmax);
% check(i,4)=length(CSingleStates(1,i).NPmax_HWmax);
% check(i,5)=length(CSingleStates(1,i).NP2max_HWmax);
end

for i=1:length(CSingleStates)
check2(i,1:2)=size(CSingleStates(1,i).NP2_20);
check2(i,3:4)=size(CSingleStates(1,i).NP10_200);
end
for i=1:length(CSingleStates)
check3(i,1)=length(CSingleStates(1,i).NP100_200);
check3(i,2)=length(CSingleStates(1,i).NP100_1000);
check3(i,3)=length(CSingleStates(1,i).NP200_Wmax);
check3(i,4)=length(CSingleStates(1,i).NPtotA_Wmax);
check3(i,5)=length(CSingleStates(1,i).NPtotD_Wmax);
check3(i,6)=length(CSingleStates(1,i).NPtotAD_Wmax);
check3(i,7)=length(CSingleStates(1,i).NPtotA_HWmax);
check3(i,8)=length(CSingleStates(1,i).NPtotD_HWmax);
check3(i,9)=length(CSingleStates(1,i).NPtotAD_HWmax);
end
%% NP successors
succesNP(:,1)=find(check3(:,2))
longest=max(check3(:,2))
NProbeEffi1001000=zeros(longest,length(succesNP));

for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).NP100_1000);
NProbeEffi1001000(1:ende,i)=CSingleStates(1,succesNP(i,1)).NP100_1000;
end

longest=length(CSingleStates(1,36).eff100);
NProbeEffiRefCor=zeros(longest,length(succesNP));
for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).eff100);
NProbeEffiTW100RefCor(1:ende,i)=CSingleStates(1,succesNP(i,1)).eff100;
end


longest=length(CSingleStates(1,36).counts);
NProbeEffiRefCorCounts=zeros(longest,length(succesNP)*2);

for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).counts);
NProbeEffiRefCorCounts(1:ende,i:i+1)=CSingleStates(1,succesNP(i,1)).counts;
end


longest=length(CSingleStates(1,36).monocounts);
NProbeEffiRefMono=zeros(longest,length(succesNP)*2);

for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).monocounts);
NProbeEffiRefMono(1:ende,i:i+1)=CSingleStates(1,succesNP(i,1)).monocounts;
end



%% Export

for i=1:length(CSingleStates)
ende=length(CSingleStates(1,succesNP(i,1)).NP100_1000);
a(:,i)=NProbeEffi1001000(1:ende,i);
name=['stateFRETnp-',num2str(succesNP(i,1)),'_org',CSingleStates(1,succesNP(i,1)).names(17:20),'.dat'];
save (name, 'a', '-ascii', '-double')
clear a
clear name
end

for i=1:length(CSingleStates)
...
end


NPtester.maxCount=max(max(CSingleStates(1,i).counts));
    maxW=length(CSingleStates(1,i).monocounts);
    maxND=find(CSingleState(1,i).monocounts(:,1))
    maxNA=find(CSingleState(1,i).monocounts(:,2))

k=0
for s=1:2
    figure;
    
        for i=1:36
    
        dur=length(CSingleStates(1,i+k).eff100);
            subplot(12,3,i)
    plot(CSingleStates(1,i+k).eff100)
    set(gca,'xtick',[],'ytick',[], 'YColor','b','xtick',[dur/2:dur/2:dur],'ytick',[0:0.5:1], 'YColor','b','XTickLabel',{num2str(dur/2),num2str(dur)});
    title([num2str(k+i) ' part ' CSingleStates(1,i).part])
    xyPos=get(gca,'Position')-[0.09 -0.05 0 0];
    xyPos(1,3:4)=[0.3 0.06]
    set(gca, 'Position',xyPos,...
           'XLim',[1,dur]);
        end
    k=k+36;
    
end
    
    
    
    