dateBH=Import["/home/lau/Lucru/Proiecte/FractalSky/2micron/FinalList/BHMassF/CandidateSourcesWithoutOutlinersUsingEllipticals.csv"];
dateabove10to7=Flatten[Reap[Do[If[1*10^8≤dateBH[[i,9]]≤1*10^10,Sow[dateBH[[i]]]],{i,Length[dateBH]}]][[2]],1];
Length[dateabove10to7]
dateBH=dateabove10to7;

redshift=Range[Length[dateBH]];
Do[redshift[[i]]=dateBH[[i,8]],{i,Length[dateBH]}]
Log[10,redshift[[1]]]

nrintervale=15;
numarSelectieCompleta=Range[nrintervale+1];numar=Table[0,{nrintervale}];
flux=Table[(10^i),{i,6,10,.5}];
flux=Table[(10^i),{i,Log[10,Min[redshift]],Log[10,Max[redshift]],((Log[10,Max[redshift]]-Log[10,Min[redshift]])/nrintervale)}];
flux=Table[i,{i,0,0.025,0.025/nrintervale}]
adunatemase=numar;
Do[adunatemase[[i]]=Flatten[Reap[Do[If[flux[[i]]≤redshift[[j]]≤flux[[i+1]],numar[[i]]++;Sow[dateBH[[i,9]]]],{j,Length[redshift]}]][[2]],1],{i,nrintervale}];
numar
mediamase=Flatten[Reap[Do[Sow[Mean[adunatemase[[i]]]],{i,Length[adunatemase]}]][[2]],1]

deprintat=Transpose[{Drop[flux,1],numar}];
alfagasit=alfa/.FindFit[deprintat,alfa*s,{alfa},s]

Needs["Histograms`"]
poza=Histogram[(numar),FrequencyData->True,HistogramCategories->flux,Frame->True,FrameLabel->{"z", "N"},TextStyle->{FontFamily->"Times",FontSize->12},ImageSize->450,PlotRange->{{-1.5,1.5},{0,1.5}}]

Export["/home/lau/Lucru/Proiecte/FractalSky/2micron/FinalList/BHMassF/PlotsBHMFBHSelected/HistogramNOverZAbove108.eps",poza]

punctele=ListPlot[deprintat];
alfagasit=alfa/.FindFit[Drop[deprintat,-5],alfa*s^3,{alfa},s]
(*alfagasit=6*10^7*)
fit=Plot[alfagasit*s^3,{s,0,0.0153966},PlotStyle->Directive[Thick]];
histcufit=Show[poza,fit]
Show[punctele,fit]

Export["/home/lau/Lucru/Proiecte/FractalSky/2micron/FinalList/BHMassF/PlotsBHMFBHSelected/HistogramNOverZAllWithZFit.eps",histcufit]

alfagasit=2.843431601453441`*^11;
betagasit=1.9054888536775378`;
coeficient=s/.Solve[alfagasit*s^betagasit==1*10^8,s][[1]]
nrintervale=10;
flux=Table[i,{i,0,coeficient,coeficient/nrintervale}]
numar=Table[0,{Length[flux]-1}];
adunatemase=numar;
Do[adunatemase[[i]]=Flatten[Reap[Do[If[flux[[i]]≤redshift[[j]]≤flux[[i+1]],numar[[i]]++;Sow[dateBH[[i,9]]]],{j,Length[redshift]}]][[2]],1],{i,nrintervale}];
numar

coeficient=0.015396581445283454`;
numarintervale=Total[{4,12,35,46,52,66,105,114,153,232}]
nass=(numarintervale/((4/3)Pi*(coeficient^3)))
fit2=Plot[4*Pi*nass*(coeficient/nrintervale)*s^2,{s,0,0.0153966},PlotStyle->Directive[Thick,Black]]

expecteduniform=N[Table[((i+1)^3-i^3),{i,0,9}]](Total[numar])/(1000)
alfa3gasit=alfa/.Solve[alfa*10^3*flux[[2]]^3==expecteduniform[[10]],alfa][[1]]

deprintat2=Transpose[{Drop[flux-flux[[2]],1],expecteduniform}];
punctele2=ListPlot[deprintat2];
alfa2gasit=alfa/.FindFit[deprintat2,alfa*s^3,{alfa},s]
fit21=Plot[alfa2gasit*s^3,{s,0,0.0153966},PlotStyle->Directive[Thick]];
histogramWithCumFit=Show[poza,fit2,PlotRange->All,Frame->True,FrameLabel->{"z", "N"},TextStyle->{FontFamily->"Times",FontSize->12},ImageSize->450]
Show

Export["/home/lau/Lucru/Proiecte/FractalSky/2micron/FinalList/BHMassF/PlotsBHMFBHSelected/HistogramNOverZAllWithZFitExpectedCorrected.eps",histogramWithCumFit]

N[271*Total[numar]/1000]