-
Notifications
You must be signed in to change notification settings - Fork 0
/
executer.py
78 lines (69 loc) · 4.43 KB
/
executer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os, sys, argparse
import ROOT as r
macpath = "temp_macs"
if not os.path.isdir(macpath):
os.system("mkdir -p " + macpath)
outpath = "temp_rootFiles"
if not os.path.isdir(outpath):
os.system("mkdir -p " + outpath)
#----Mac template----
mac_template = "/yourApp/det/setTargetMaterial {material} \n" + "/yourApp/det/setTargetThickness {thickness} um \n" + "/gun/particle {particle} \n" + "/gun/energy {energy} MeV \n" + "/run/initialize \n" + "/run/beamOn {N_events}\n"
#----Simulation parameters----- (Place default values a the first position in the list)
list_material = ["G4_Si", "G4_Au", "G4_Pb", "G4_Os", "G4_Cu"]
list_thickness = ["5.6", "10", "20", "30", "50"]
#list_thickness = ["500000","100000","1000000"]
list_gunParticle = ["e-","proton","gamma", "neutron"]
list_ParticleEnergy = ["100","1000","0.01","0.1","0.012", "0.05"]
N_events = "100000"
execute_mat = True
execute_thick = True
execute_part = True
execute_energ = True
if execute_mat:
for material in list_material:
rootFileName = "/Histograms_" + material + "_" + list_thickness[0] + "_" + list_gunParticle[0] + "_" + list_ParticleEnergy[0] + ".root"
macFileName = "/Run_" + material + "_" + list_thickness[0] + "_" + list_gunParticle[0] + "_" + list_ParticleEnergy[0] + ".mac"
macFile = open(macpath + macFileName,"w")
macFile.write(mac_template.format(material = material, thickness = list_thickness[0], particle = list_gunParticle[0], energy = list_ParticleEnergy[0], N_events = N_events))
macFile.close()
os.system("./build/main ./" + macpath + macFileName)
if not os.path.isdir(outpath + "/MaterialVariation"):
os.system("mkdir -p " + outpath + "/MaterialVariation")
os.system("mv ./Histograms.root ./" + outpath + "/MaterialVariation" + rootFileName)
os.system("rm ./" + macpath + "/*")
if execute_thick:
for thickness in list_thickness:
rootFileName = "/Histograms_" + list_material[0] + "_" + thickness + "_" + list_gunParticle[0] + "_" + list_ParticleEnergy[0] + ".root"
macFileName = "/Run_" + list_material[0] + "_" + thickness + "_" + list_gunParticle[0] + "_" + list_ParticleEnergy[0] + ".mac"
macFile = open(macpath + macFileName,"w")
macFile.write(mac_template.format(material = list_material[0], thickness = thickness, particle = list_gunParticle[0], energy = list_ParticleEnergy[0], N_events = N_events))
macFile.close()
os.system("./build/main ./" + macpath + macFileName)
if not os.path.isdir(outpath + "/ThicknessVariation"):
os.system("mkdir -p " + outpath + "/ThicknessVariation")
os.system("mv ./Histograms.root ./" + outpath + "/ThicknessVariation" + rootFileName)
os.system("rm ./" + macpath + "/*")
if execute_part:
for gunParticle in list_gunParticle:
rootFileName = "/Histograms_" + list_material[0] + "_" + list_thickness[0] + "_" + gunParticle + "_" + list_ParticleEnergy[0] + ".root"
macFileName = "/Run_" + list_material[0] + "_" + list_thickness[0] + "_" + gunParticle + "_" + list_ParticleEnergy[0] + ".mac"
macFile = open(macpath + macFileName,"w")
macFile.write(mac_template.format(material = list_material[0], thickness = list_thickness[0], particle = gunParticle, energy = list_ParticleEnergy[0], N_events = N_events))
macFile.close()
os.system("./build/main ./" + macpath + macFileName)
if not os.path.isdir(outpath + "/ParticleVariation"):
os.system("mkdir -p " + outpath + "/ParticleVariation")
os.system("mv ./Histograms.root ./" + outpath + "/ParticleVariation" + rootFileName)
os.system("rm ./" + macpath + "/*")
if execute_energ:
for ParticleEnergy in list_ParticleEnergy:
rootFileName = "/Histograms_" + list_material[0] + "_" + list_thickness[0] + "_" + list_gunParticle[0] + "_" + ParticleEnergy + ".root"
macFileName = "/Run_" + list_material[0] + "_" + list_thickness[0] + "_" + list_gunParticle[0] + "_" + ParticleEnergy + ".mac"
macFile = open(macpath + macFileName,"w")
macFile.write(mac_template.format(material = list_material[0], thickness = list_thickness[0], particle = list_gunParticle[0], energy = ParticleEnergy, N_events = N_events))
macFile.close()
os.system("./build/main ./" + macpath + macFileName)
if not os.path.isdir(outpath + "/EnergyVariation"):
os.system("mkdir -p " + outpath + "/EnergyVariation")
os.system("mv ./Histograms.root ./" + outpath + "/EnergyVariation" + rootFileName)
os.system("rm ./" + macpath + "/*")