#######################################################
# Assumption: Only the particles coming from (0,0,z) 
# Question 1: How many hits belong to those particles?
# Question 2: What is the score limit?
#######################################################

require(data.table)

path='../input/train_1/'
best_score <- function(x_window,y_window,z_window) {
sc=1:3 # 1:100
pr=1:3 # 1:100
for(i in 0:2){ # 0:99
  nev=1000+i
  dft=fread(paste0(path,'event00000',nev,'-truth.csv'),stringsAsFactors = T)
  dfp=fread(paste0(path,'event00000',nev,'-particles.csv'))
  #part00Z <-dfp[abs(vx)<0.05 & abs(vy)<0.05,particle_id]
  
  part00Z <-dfp[abs(vx)<x_window & abs(vy)<y_window & abs(vz)<z_window,particle_id]
  dft[,s1:=ifelse(particle_id %in% part00Z,1,0)]
  score <- sum(dft[s1==1,weight])
  perc <- mean(dft$s1)*100
  #cat("score",score,", no. of hits:",perc,"%\n")
  #print(score)
  sc[i+1]=score
  pr[i+1]=perc
}
cat("------------------------------------------\n")
cat("using x_window: ", x_window, ", y_window: ",y_window,", z_window: ",z_window, ":\n")
cat("score",mean(sc),", no. of hits:",mean(pr),"%\n")
}

best_score(500,500,2900) #.997
best_score(300,300,1000) #.982
best_score(100,100,1000) #.945
best_score(100,100,500) #.925
best_score(20,20,200) #.869
best_score(20,20,20) #.849
best_score(0.05,0.05,20) #.819