generate_CCQE_events.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 import subprocess
3 import threading
4 import os
5 import sys
6 
7 mode_prefix = sys.argv[1]
8 nucZs = [6]
9 nucAs = [12]
10 if mode_prefix == "EFF":
11  nucZs = [1, 2, 6, 10, 13, 18, 26, 82 ]
12  nucAs = [2, 4, 12, 20, 27, 40, 56, 208]
13 
14 
15 energy = "3.0"
16 
17 num_ev = "50000"
18 neut_pdgs = ["14", "-14"]
19 if mode_prefix == "EFF":
20  neut_pdgs = ["14"]
21 spline_dir = "../../../../splines/"
22 spline_suffix = "QE_splines.xml"
23 start_run = 500000
24 end_run = 500010
25 data_dir = "./data/" + mode_prefix + "/"
26 
27 spline = spline_dir + mode_prefix + "_" + spline_suffix
28 
29 cmds = []
30 
31 
32 subprocess.call(["mkdir", data_dir])
33 
34 for neut_pdg in neut_pdgs:
35  data_dir = "./data/" + mode_prefix + "/" + "nu_" + neut_pdg + "/"
36  subprocess.call(["mkdir", data_dir])
37  for runnum in range(start_run, end_run + 1):
38  for i in range(len(nucZs)):
39  nucZ = nucZs[i]
40  nucA = nucAs[i]
41  folder = data_dir + str(nucZ) + "_" + str(nucA)
42  cmd = ["mkdir", folder]
43  subprocess.call(cmd)
44  target = str(1000000000+nucA*10+nucZ*10000)
45 
46  cmd1 = ["gevgen", "-r", str(runnum), "-n", num_ev, "-p", neut_pdg, "-t", target,"-e", energy,
47  "--cross-sections", spline, "--seed", str(runnum), "--event-generator-list", "CCQE"]
48  cmd2 = ["gntpc", "-i", "gntp." + str(runnum) + ".ghep.root", "-f", "gst"]
49  cmds.append([cmd1, cmd2, folder])
50 
51 num_threads = 32
52 
53 mutex = threading.Lock()
54 
56  while True:
57  mutex.acquire()
58  if len(cmds) == 0:
59  mutex.release()
60  return
61  cmd = cmds.pop()
62  mutex.release()
63  subprocess.call(cmd[0], cwd = cmd[2])
64  subprocess.call(cmd[1], cwd = cmd[2])
65 
66 threads = []
67 for i in range(num_threads):
68  t = threading.Thread(target=generate_genie_files)
69  t.daemon=True
70  t.start()
71  threads.append(t)
72 for t in threads:
73  t.join()