-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_jetphox
executable file
·263 lines (228 loc) · 12.4 KB
/
run_jetphox
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env python3
import argparse
import os
import shutil
import sys
import subprocess
from datetime import datetime
ptbins = [1.5, 3., 5., 8., 12., 17., 23., 31., 40., 52., 66., 82., 100., 120., 140., 160., 180., 200., 220.]
name = "default"
# funcion that creates pthard bin folders (if they don't exist) and copies all needed files for building
def createpthardbins():
basedir = os.getcwd()
print("Bins for following pthard bins will be created: ")
print(ptbins)
for i in range(len(ptbins)-1):
# mkdir -p jp${i}
print("Creating jp"+str(i)+" folder")
os.makedirs(str(name)+'_jp'+str(i), exist_ok=True)
# copy all files (wildcard) from jptemplate folder to jp${i}
print("Copying files from jptemplate to jp"+str(i))
subprocess.run(['cp', '-a', basedir+'/jptemplate/.', str(name)+'_jp'+str(i)+'/'])
if __name__ == "__main__":
print("Starting run_jetphox.py")
# year_month_day
datestring = datetime.strftime(datetime.now(), '%Y_%m_%d')
parser = argparse.ArgumentParser("run_jetphox", description="Steering script to build and start a new jetphox calculation")
parser.add_argument("command", metavar="COMMAND", type=str, help="Command to run build | submit | submitperlmutter | run" )
parser.add_argument("-p", "--prefix", metavar="PREFIX", type=str, default="Output_"+datestring, help="Prefix for output files")
parser.add_argument("-i", "--pdf1", metavar="PDF1", type=str, default="CT14nlo", help="PDF set for beam 1")
parser.add_argument("-k", "--pdfmember1", metavar="PDFMEMBER1", type=str, default="0", help="PDF member for beam 1")
parser.add_argument("-l", "--pdf2", metavar="PDF2", type=str, default="CT14nlo", help="PDF set for beam 2")
parser.add_argument("-m", "--pdfmember2", metavar="PDFMEMBER2", type=str, default="0", help="PDF member for beam 2")
# scale variation
parser.add_argument("-s", "--scaleis", metavar="SCALEIS", type=str, default="1.0", help="Scale Initial State")
parser.add_argument("-t", "--scalefs", metavar="SCALEFS", type=str, default="1.0", help="Factorization Scale")
parser.add_argument("-u", "--scalerenorm", metavar="SCALEHD", type=str, default="1.0", help="Renormalization Scale")
parser.add_argument("-z", "--process", metavar="PROCESS", type=str, default="dir", help="Process to calculate: dir, onef or dirfrag")
#higherorderswitch
parser.add_argument("-o", "--higherorder", metavar="HIGHERORDERSWITCH", type=str, default="true", help="Higher order switch: true (NLO) or false (LO)")
#cme
parser.add_argument("-c", "--cme", metavar="CME", type=str, default="13000", help="Center of Mass Energy in GeV")
#minrap
parser.add_argument("-x", "--minrap", metavar="MINRAP", type=str, default="-0.8", help="Minimum Rapidity")
#maxrap
parser.add_argument("-y", "--maxrap", metavar="MAXRAP", type=str, default="0.8", help="Maximum Rapidity")
#isoconeradius
parser.add_argument("-r", "--isoconeradius", metavar="ISOCONERADIUS", type=str, default="0.4", help="Isolation Cone Radius")
#isoenergy
parser.add_argument("-e", "--isoenergy", metavar="ISOENERGY", type=str, default="5.0", help="Isolation Energy in cone in GeV")
#numberofevents
parser.add_argument("-n", "--numberofevents", metavar="NUMBEROFEVENTS", type=str, default="5000000", help="Number of Events")
#randomseed
parser.add_argument("-d", "--randomseed", metavar="RANDOMSEED", type=str, default="12345", help="Random Seed")
#directcalculation 0, 1 or 2
parser.add_argument("-a", "--directcalculation", metavar="DIRECTCALCULATION", type=str, default="2", help="Calculation of direct contribution: 0 (born only), 1 (box only), 2 (born+box)")
#JETRAPMIN
parser.add_argument("-j", "--jetrapmin", metavar="JETRAPMIN", type=str, default="-5.8", help="Minimum Jet Rapidity")
#JETRAPMAX
parser.add_argument("-q", "--jetrapmax", metavar="JETRAPMAX", type=str, default="5.8", help="Maximum Jet Rapidity")
parser.add_argument("-v", "--skipcopy", metavar="SKIPCOPY", type=str, default="false", help="Skip copying of files from jptemplate")
args = parser.parse_args()
# load environment
typehadronbeam1 = 0
typehadronbeam2 = 2
if args.pdf1 == args.pdf2:
typehadronbeam2 = 0
subprocessmin = 1
subprocessmax = 11
# make higherorderstring all capital
args.higherorder = args.higherorder.upper()
# parsed arguments, print summary
print("Summary of arguments:")
print("Prefix: "+args.prefix)
print("PDF Beam 1: "+args.pdf1)
print("PDF Member Beam 1: "+args.pdfmember1)
print("PDF Beam 2: "+args.pdf2)
print("PDF Member Beam 2: "+args.pdfmember2)
print("Scale Initial State: "+args.scaleis)
print("Factorization Scale: "+args.scalefs)
print("Renormalization Scale: "+args.scalerenorm)
print("Process: "+args.process)
print("Higher Order: "+args.higherorder)
print("Center of Mass Energy (GeV): "+args.cme)
print("Minimum Rapidity: "+args.minrap)
print("Maximum Rapidity: "+args.maxrap)
print("Isolation Cone Radius: "+args.isoconeradius)
print("Isolation Energy in Cone (GeV): "+args.isoenergy)
print("Number of Events: "+args.numberofevents)
print("Random Seed: "+args.randomseed)
print("Direct Contribution: "+args.directcalculation)
print("Minimum Jet Rapidity: "+args.jetrapmin)
print("Maximum Jet Rapidity: "+args.jetrapmax)
# make filename compatible name of outputfile
name = args.prefix
name += '_'+args.pdf1
name += '_'+args.pdfmember1
name += '_'+args.pdf2
name += '_'+args.pdfmember2
name += '_scl'+args.scaleis
name += '_'+args.scalefs
name += '_'+args.scalerenorm
name += '_'+args.process
# add cme
name += '_'+args.cme
# add minrap
name += '_ymin'+args.minrap
# add maxrap
name += '_ymax'+args.maxrap
# add isoconeradius
name += '_R'+args.isoconeradius
# add isoenergy
name += '_E'+args.isoenergy
# remove . from name
name = name.replace('.', '')
name = name.replace('-', 'neg')
print("Name of outputfile: "+name)
# check length of outputfilename
# make pdf names shorter
name = name.replace('nNNPDF30_nlo_as_0118_A208_Z82', 'nNNPDF30')
# create pthard bin folders
if args.skipcopy == "false":
print("Creating pthard bin folders")
createpthardbins()
print("Created pthard bin folders")
# build name of outputfile
basedir = os.getcwd()
# loop over pthard bins
for i in range(len(ptbins)-1):
# enter pthard bin folder
os.chdir(str(name)+'_jp'+str(i)+'/working/')
# copy files from jptemplate folder
shutil.copyfile(basedir+'/jptemplate/working/Makefile', 'Makefile')
# TODO to be continue
# cp ${BASEDIR}/configfiles/param_histo.indat_template param_histo.indat;
shutil.copyfile(basedir+'/configfiles/param_histo.indat_template', 'param_histo.indat')
# replace strings in param_histo.indat with sed
sedstring = 's/MAXRAP/'+args.maxrap+'/g'
subprocess.run(['sed', '-i', sedstring, 'param_histo.indat'])
sedstring = 's/MINRAP/'+args.minrap+'/g'
subprocess.run(['sed', '-i', sedstring, 'param_histo.indat'])
sedstring = 's/PROCESSSTRING/'+args.process+'/g'
subprocess.run(['sed', '-i', sedstring, 'param_histo.indat'])
sedstring = 's/ORDERSTRING/'+args.higherorder+'/g'
subprocess.run(['sed', '-i', sedstring, 'param_histo.indat'])
sedstring = 's/JETRAPMIN/'+args.jetrapmin+'/g'
subprocess.run(['sed', '-i', sedstring, 'param_histo.indat'])
sedstring = 's/JETRAPMAX/'+args.jetrapmax+'/g'
subprocess.run(['sed', '-i', sedstring, 'param_histo.indat'])
shutil.copyfile(basedir+'/configfiles/parameter.indat_template', 'parameter.indat')
subprocess.run(['rm', '-rf', '../'+name])
subprocess.run(['mkdir', '../'+name])
sedstring = 's/NAMEINPUTPARAMETERFILE/'+name+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/NAMEHISTODIR/'+name+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/NAMEEXECUTABLEFILE/'+name+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/TYPEHADRONBEAM1/'+str(typehadronbeam1)+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/TYPEHADRONBEAM2/'+str(typehadronbeam2)+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/LHAPDFNAME1/'+args.pdf1+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/PDFMEMBER1/'+args.pdfmember1+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/LHAPDFNAME2/'+args.pdf2+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/PDFMEMBER2/'+args.pdfmember2+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/ISSCALE/'+args.scaleis+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/RENORMSCALE/'+args.scalerenorm+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/FSSCALE/'+args.scalefs+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/PROCESSSWITCH/'+args.process+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/HIGHERORDERSWITCH/'+args.higherorder+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/CMSENERGY/'+args.cme+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/MAXRAP/'+args.maxrap+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/MINRAP/'+args.minrap+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/PTMAXGEN/'+str(ptbins[i+1])+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/PTMINGEN/'+str(ptbins[i])+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/ISOCONERADIUS/'+args.isoconeradius+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/ISOENERGY/'+args.isoenergy+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/NUMBEROFEVENTS/'+args.numberofevents+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/RANDOMSEED/'+args.randomseed+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/DIRECTCALCULATION/'+args.directcalculation+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/SUBPROCESSMIN/'+str(subprocessmin)+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/JETRAPMIN/'+args.jetrapmin+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/JETRAPMAX/'+args.jetrapmax+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
sedstring = 's/SUBPROCESSMAX/'+str(subprocessmax)+'/g'
subprocess.run(['sed', '-i', sedstring, 'parameter.indat'])
# start perl script
print("Starting perl script")
if args.command == "build":
subprocess.run(['perl', 'start.pl'])
elif args.command == "submit":
subprocess.run(['sbatch', 'submitJobSLURM.sh', 'run'+name+'.exe'])
elif args.command == "submitperlmutter":
subprocess.run(['sbatch', 'submitJobSLURMPerlmutter.sh', 'run'+name+'.exe'])
elif args.command == "run":
subprocess.run(['bash', 'submitJobSLURM.sh', 'run'+name+'.exe'])
os.chdir('../..')
#------------------------------------------------
#------------------------------------------------
# create script for merging histograms
subprocess.run(['touch', 'merge_'+name+'.sh'])
if args.process == "dir":
with open('merge_'+name+'.sh', 'w') as f:
f.write('hadd -k '+name+'.root '+name+'_jp{0..'+str(len(ptbins)-1)+'}/'+name+'/ggd'+name+'.root\n')
if args.process == "onef":
with open('merge_'+name+'.sh', 'w') as f:
f.write('hadd -k '+name+'.root ' +name+ '_jp{0..'+str(len(ptbins)-1)+'}/'+name+'/ggo'+name+'.root\n')