import os
import numpy as np



Runname = "DelayTestThirds_uboone_EventRateplot_ns"
if not os.path.exists(Runname):
    os.makedirs(Runname)
    os.makedirs(Runname+"/Parfiles")
    os.makedirs(Runname+"/Events")
nl ="\n"

masses = np.linspace(0,1,30)
#masses = [0.1]
runfile = open(Runname+"/runner.sh","w")
signalmode = "ns"
detector = 'uboone'
for mv in masses:
    print(mv)
    
    mx = mv/3  #this seems to be a standard
    fh = open(Runname+"/Parfiles/par_"+signalmode+"_mv_{0}.dat".format(mv),"w")
    modelpars=["epsilon 1e-03",nl,"dark_matter_mass {0}".format(mx),nl,"dark_photon_mass {0}".format(mv),nl,"alpha_D 0.5"]
    runpars=[nl,"POT 6e20",nl,"pi0_per_POT 0.9",nl,"samplesize 20000",nl,"burn_max 1000",nl,"burn_timeout 20000",nl,"beam_energy 8.9"]
    outputpars=[nl,"output_mode comprehensive",nl,"#max_scatter_energy 0.9",nl,"#min_scatter_energy 0.035",nl,"#dm_energy_resolution 0.01"]
    fh.writelines(modelpars)
    fh.writelines(runpars)
    fh.writelines(outputpars)
    


#the code fails if we use a  mode is not kinetically allowed this prevents that    
    if (mx*2)<0.1349:
        productionmode = "all" # all modes
    elif (mx*2)<0.5478:
        productionmode = "nopi" # no pion decay
    else:
        productionmode = "justbrem" # just V brem


        
    print(productionmode)    



    with open("Parstruct/prodmodefiles/prodmode{0}.dat".format(productionmode)) as file_1:
        for line in file_1:
            fh.write(line)
    with open("Parstruct/signalmodefiles/signalmode{0}.dat".format(signalmode)) as file_2:
        for line in file_2:
            fh.write(line)
    
    with open("Parstruct/detectorfiles/"+detector+".dat") as file_3:
        for line in file_3:
            fh.write(line)


    fh.write(nl)
    fh.write("output_file "+Runname+"/Events/events_"+signalmode+"_mv_{0}.hepevt".format(mv))
    fh.write(nl) 
    fh.write("summary_file "+Runname+"/Events/summary.dat")
    runfile.write("./bin/BDNMC "+Runname+"/Parfiles/par_"+signalmode+"_mv_{0}.dat;".format(mv))
    fh.close()
    


runfile.close()


import os
import numpy as np



Runname = "DelayTestThirds_uboone_EventRateplot_ns"
if not os.path.exists(Runname):
    os.makedirs(Runname)
    os.makedirs(Runname+"/Parfiles")
    os.makedirs(Runname+"/Events")
nl ="\n"

masses = np.linspace(0,1,30)
#masses = [0.1]
runfile = open(Runname+"/runner.sh","w")
signalmode = "ns"
detector = 'uboone'
for mv in masses:
    print(mv)
    
    mx = mv/3  #this seems to be a standard
    fh = open(Runname+"/Parfiles/par_"+signalmode+"_mv_{0}.dat".format(mv),"w")
    modelpars=["epsilon 1e-03",nl,"dark_matter_mass {0}".format(mx),nl,"dark_photon_mass {0}".format(mv),nl,"alpha_D 0.5"]
    runpars=[nl,"POT 6e20",nl,"pi0_per_POT 0.9",nl,"samplesize 20000",nl,"burn_max 1000",nl,"burn_timeout 20000",nl,"beam_energy 8.9"]
    outputpars=[nl,"output_mode comprehensive",nl,"#max_scatter_energy 0.9",nl,"#min_scatter_energy 0.035",nl,"#dm_energy_resolution 0.01"]
    fh.writelines(modelpars)
    fh.writelines(runpars)
    fh.writelines(outputpars)
    


#the code fails if we use a  mode is not kinetically allowed this prevents that    
    if (mx*2)<0.1349:
        productionmode = "all" # all modes
    elif (mx*2)<0.5478:
        productionmode = "nopi" # no pion decay
    else:
        productionmode = "justbrem" # just V brem


        
    print(productionmode)    



    with open("Parstruct/prodmodefiles/prodmode{0}.dat".format(productionmode)) as file_1:
        for line in file_1:
            fh.write(line)
    with open("Parstruct/signalmodefiles/signalmode{0}.dat".format(signalmode)) as file_2:
        for line in file_2:
            fh.write(line)
    
    with open("Parstruct/detectorfiles/"+detector+".dat") as file_3:
        for line in file_3:
            fh.write(line)


    fh.write(nl)
    fh.write("output_file "+Runname+"/Events/events_"+signalmode+"_mv_{0}.hepevt".format(mv))
    fh.write(nl) 
    fh.write("summary_file "+Runname+"/Events/summary.dat")
    runfile.write("./bin/BDNMC "+Runname+"/Parfiles/par_"+signalmode+"_mv_{0}.dat;".format(mv))
    fh.close()
    


runfile.close()


#masses = [0.1] #this seems to be a standard #the code fails if we use a  mode is not kinetically allowed this prevents that # all modes # no pion decay # just V brem