density4<-function(z1,v=seq(-10,10,length.out=120),base_dx=0.04,min_count=3,smooth=TRUE){
count<-NULL
dx_b<-NULL
cou_c<-min_count
cou_b<-NULL
for(i in 1:length(v)){
j2<-1
count[i]<-0
cou_b[i]<-0
dx_b[i]<-0
flg<-TRUE
for(j in 1:32){
if(flg){
j2<-j
dx<-j2*base_dx
cou_c<-length(which(z1>= v[i]-dx & z1<=v[i]+dx))
}
if(cou_c>=3){
flg<-FALSE
cou_b[i]<-length(which(z1>= v[i]-dx & z1<=v[i]+dx))
count[i]<-length(which(z1>= v[i]-dx & z1<=v[i]+dx))/2/dx/length(z1)
dx_b[i]<-dx
}
}
cat(i,"\n")
}
if(smooth==TRUE){
count_smooth<-smooth.spline(v,count)$y
}else{
count_smooth<-count
}
count_smooth[which(count==0)]<-0
return(na.omit(data.frame(x=v,y=count_smooth,count=cou_b,dx=dx_b,raw_density=count)))
#plot(v,count)
}