-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_particleSim.sh
executable file
·295 lines (249 loc) · 11.1 KB
/
run_particleSim.sh
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
function print_help()
{
echo "#######################################################################";
echo "Usage:";
echo "./run_particleSim.sh --mode <mode> --Nevts <Nevts> --targ <targ> --pid <pid> --bkg <bkg> --run1 <run1> --run2 <run2>";
echo "where:";
echo " <mode> = 0 (interactive), 1 (farm)";
echo " <Nevts> = number of events to generate";
echo " <targ> = selects target: (0,1,2,3) <==> (\"D\", \"C\", \"Fe\", \"Pb\")";
echo " <pid> = pid of detected particle. eg. (223,221,2212) for (omega,eta,proton)";
echo " <bkg> = 0 (generate events with at least one of selected particle in the final state), 1 (generate all particles but selected one), 2 (v2, prevent etas production)";
echo " <run1,run2> = integers >=0 to loop over";
echo "eg: ./run_particleSim.sh --mode 0 --Nevts 100 --targ 0 --pid 223 --bkg 0 --run1 0 --run2 0";
echo "#######################################################################";
exit 1;
}
#######################################################################
function process_args()
{
arr=("$@")
ic=0
while [ $ic -le $((${#arr[@]}-1)) ]; do
if [ "${arr[$ic]}" == "--mode" ]; then
mode=${arr[$((ic+1))]}
elif [ "${arr[$ic]}" == "--Nevts" ]; then
Nevts=${arr[$((ic+1))]}
elif [ "${arr[$ic]}" == "--targ" ]; then
targ=${arr[$((ic+1))]}
elif [ "${arr[$ic]}" == "--pid" ]; then
pid=${arr[$((ic+1))]}
elif [ "${arr[$ic]}" == "--bkg" ]; then
bkg=${arr[$((ic+1))]}
elif [ "${arr[$ic]}" == "--run1" ]; then
run1=${arr[$((ic+1))]}
elif [ "${arr[$ic]}" == "--run2" ]; then
run2=${arr[$((ic+1))]}
else
echo "*** Aborting: Unrecognized argument: ${arr[$((ic))]} ***";
print_help;
fi
((ic+=2))
done
}
#######################################################################
function check_args()
{
if [ $mode -ne 0 -a $mode -ne 1 ]; then
echo "*** Aborting: wrong mode value. Possible values are 0 or 1 ***";
print_help;
fi
if [ $Nevts -le 0 ]; then
echo "*** Aborting: Number of events should be positive ***";
print_help;
fi
if [ $targ -lt 0 -o $targ -gt 3 ]; then
echo "*** Aborting: unrecognized target. Possible values are 0, 1, 2, 3 ***";
print_help;
fi
# if [ $pid -ne 223 -a $pid -ne 221 ]; then
# echo "*** Aborting: unrecognized pid. Possible values are 223 ***";
# print_help;
# fi
if [ $run1 -lt 0 -o $run2 -lt 0 ]; then
echo "*** Aborting: run number should be >= 0 ***";
print_help;
fi
if [ $bkg -lt 0 -o $bkg -gt 2 ]; then
echo "*** Aborting: bkg option should be 0, 1 or 2 ***";
print_help;
fi
}
#######################################################################
function print_args()
{
echo "mode: $mode"
echo "Nevts: $Nevts"
echo "targ: $targ"
echo "pid: $pid"
echo "bkg: $bkg"
echo "run1: $run1"
echo "run2: $run2"
}
#######################################################################
function get_run()
{
sr=$1
srn=""
if [ $sr -lt 10 ]; then
srn="000$sr"
elif [ $sr -lt 100 ]; then
srn="00$sr"
elif [ $sr -lt 1000 ]; then
srn="0$sr"
else
srn="$sr"
fi
echo $srn
}
#######################################################################
############################### ##############################
############################### Main ##############################
############################### ##############################
#######################################################################
NARGS=14
if [ $# -ne $NARGS ]; then
echo "Missing arguments. You provided $# args. It should be $NARGS."
print_help;
fi
argArray=("$@")
process_args "${argArray[@]}"
check_args
print_args
if [[ "$bkg" == "0" ]]; then
TOPOUDIR="/volatile/clas/claseg2/${USER}/particleSim"
elif [[ "$bkg" == "1" || "$bkg" == "2" ]]; then
TOPOUDIR="/volatile/clas/claseg2/${USER}/bkgSim"
fi
SIMINDIR="${HOME}/simulations"
if [ ! -d $SIMINDIR ]; then
echo "Directory SIMINDIR:$SIMINDIR does not exist"
exit 1
fi
targName=("D" "C" "Fe" "Pb")
targType=("lt" "st" "st" "st")
targA=( 2 12 56 208)
targZ=( 1 6 26 82)
targZpos=( -30 -25 -25 -25)
targVG2=( 1 2 2 2)
tarA="${targA[$targ]}"
tarZ="${targZ[$targ]}"
tarZpos="${targZpos[$targ]}"
tarVG2="${targVG2[$targ]}"
tarName="${targName[$targ]}"
tarType="${targType[$targ]}"
simfile="particleSim${tarName}.sh"
leptobosfile=lepto${tarName}.A00
leptologfile=lepto${tarName}.log
leptoinfile=lepto${tarName}.txt
ffreadfile="ffread_eg2${tarName}_${tarType}.gsim"
gsimbosfile=gsim${tarName}.A00
gsimlogfile=gsim${tarName}.log
gppbosfile=gpp${tarName}.A00
gppntpfile=gpp${tarName}.hbook
gpplogfile=gpp${tarName}.log
tclfile=recsis${tarName}.tcl
rechisfile=recsis${tarName}_histos.hbook
recntpfile=recsis${tarName}.hbook
recbosfile=recsis${tarName}.A00
reclogfile=recsis${tarName}.log
recsislogfile=recsis${tarName}_log.log
recrootfile=recsis${tarName}.root
wrdstlogfile=WriteRootDst${tarName}.log
#Check if input files exist
if [ ! -f ${SIMINDIR}/particleSim.sh ]; then
echo "${SIMINDIR}/particleSim.sh does not exist"
exit 1
fi
if [ ! -f ${SIMINDIR}/ffread_eg2.gsim ]; then
echo "${SIMINDIR}/ffread_eg2.gsim does not exist"
exit 1
fi
if [ ! -f ${SIMINDIR}/leptotxt.pl ]; then
echo "${SIMINDIR}/leptotxt.pl does not exist"
exit 1
fi
if [ ! -f ${SIMINDIR}/recsis_eg2.tcl ]; then
echo "${SIMINDIR}/recsis_eg2.tcl does not exist"
exit 1
fi
for (( ir=$run1; ir<=$run2; ir++ )); do
echo ""
srun=$(get_run "$ir")
run="run${srun}"
if [ "${mode}" == "0" ]; then
IFARMDIR="${TOPOUDIR}/ifarm/${tarName}/${run}"
mkdir -p ${IFARMDIR}
cd ${IFARMDIR}
cp ${SIMINDIR}/particleSim.sh ${IFARMDIR}/${simfile}
cp ${SIMINDIR}/ffread_eg2.gsim ${IFARMDIR}/${ffreadfile}
cp ${SIMINDIR}/recsis_eg2.tcl ${IFARMDIR}/${tclfile}
sed -i "s|^Nevts=|Nevts=${Nevts}|g" ${simfile}
sed -i "s|^pid=|pid=${pid}|g" ${simfile}
sed -i "s|^bkg=|bkg=${bkg}|g" ${simfile}
sed -i "s|^targ=|targ=${targ}|g" ${simfile}
sed -i "s|^SIMINDIR=|SIMINDIR=${SIMINDIR}|g" ${simfile}
chmod 755 ./${simfile}
./${simfile}
elif [ "${mode}" == "1" ]; then
FARMDIR="${TOPOUDIR}/farm/${tarName}/${run}"
mkdir -p ${FARMDIR}
cd ${FARMDIR}
jobfile="${FARMDIR}/job_particle.xml"
proj="eg2a"
track="analysis" # "analysis" or "debug"
time="240" # "240" or "5" minutes
diskspace="500"
memusage="1000"
osname="general"
jobname=particleSim${tarName}_${srun}
echo "<Request>" > $jobfile
echo " <Project name=\"$proj\"></Project>" >> $jobfile
echo " <Track name=\"$track\"></Track>" >> $jobfile
echo " <TimeLimit time=\"$time\" unit=\"minutes\"></TimeLimit>" >> $jobfile
echo " <DiskSpace space=\"$diskspace\" unit=\"MB\"></DiskSpace>" >> $jobfile
echo " <Memory space=\"$memusage\" unit=\"MB\"></Memory>" >> $jobfile
echo " <CPU core=\"1\"></CPU>" >> $jobfile
echo " <OS name=\"$osname\"></OS>" >> $jobfile
echo " <Job>" >> $jobfile
echo " <Name name=\"${jobname}\"></Name>" >> $jobfile
echo " <Input src=\"file:${SIMINDIR}/particleSim.sh\" dest=\"${simfile}\"/>" >> $jobfile
echo " <Input src=\"file:${SIMINDIR}/leptotxt.pl\" dest=\"leptotxt.pl\"/>" >> $jobfile
echo " <Input src=\"file:${SIMINDIR}/ffread_eg2.gsim\" dest=\"${ffreadfile}\"/>" >> $jobfile
echo " <Input src=\"file:${SIMINDIR}/recsis_eg2.tcl\" dest=\"${tclfile}\"/>" >> $jobfile
echo " <Command><![CDATA[" >> $jobfile
echo " sed -i \"s|^Nevts=|Nevts=${Nevts}|g\" ${simfile}" >> $jobfile
echo " sed -i \"s|^pid=|pid=${pid}|g\" ${simfile}" >> $jobfile
echo " sed -i \"s|^bkg=|bkg=${bkg}|g\" ${simfile}" >> $jobfile
echo " sed -i \"s|^targ=|targ=${targ}|g\" ${simfile}" >> $jobfile
echo " sed -i \"s|^SIMINDIR=|SIMINDIR=${SIMINDIR}|g\" ${simfile}" >> $jobfile
echo " chmod 755 ./${simfile}" >> $jobfile
echo " sh ${simfile}" >> $jobfile
echo " ]]></Command>" >> $jobfile
# echo " <Output src=\"${leptoinfile}\" dest=\"${FARMDIR}/${leptoinfile}\"/>" >> $jobfile
# echo " <Output src=\"${simfile}\" dest=\"${FARMDIR}/${simfile}\"/>" >> $jobfile
# echo " <Output src=\"${ffreadfile}\" dest=\"${FARMDIR}/${ffreadfile}\"/>" >> $jobfile
# echo " <Output src=\"${tclfile}\" dest=\"${FARMDIR}/${tclfile}\"/>" >> $jobfile
# echo " <Output src=\"${leptobosfile}\" dest=\"${FARMDIR}/${leptobosfile}\"/>" >> $jobfile
# echo " <Output src=\"${leptologfile}\" dest=\"${FARMDIR}/${leptologfile}\"/>" >> $jobfile
# echo " <Output src=\"${gsimbosfile}\" dest=\"${FARMDIR}/${gsimbosfile}\"/>" >> $jobfile
# echo " <Output src=\"${gsimlogfile}\" dest=\"${FARMDIR}/${gsimlogfile}\"/>" >> $jobfile
# echo " <Output src=\"${gppbosfile}\" dest=\"${FARMDIR}/${gppbosfile}\"/>" >> $jobfile
# echo " <Output src=\"${gppntpfile}\" dest=\"${FARMDIR}/${gppntpfile}\"/>" >> $jobfile
# echo " <Output src=\"${gpplogfile}\" dest=\"${FARMDIR}/${gpplogfile}\"/>" >> $jobfile
# echo " <Output src=\"${rechisfile}\" dest=\"${FARMDIR}/${rechisfile}\"/>" >> $jobfile
# echo " <Output src=\"${recntpfile}\" dest=\"${FARMDIR}/${recntpfile}\"/>" >> $jobfile
# echo " <Output src=\"${recbosfile}\" dest=\"${FARMDIR}/${recbosfile}\"/>" >> $jobfile
# echo " <Output src=\"${reclogfile}\" dest=\"${FARMDIR}/${reclogfile}\"/>" >> $jobfile
# echo " <Output src=\"${recsislogfile}\" dest=\"${FARMDIR}/${recsislogfile}\"/>" >> $jobfile
echo " <Output src=\"${recrootfile}\" dest=\"${FARMDIR}/${recrootfile}\"/>" >> $jobfile
# echo " <Output src=\"${wrdstlogfile}\" dest=\"${FARMDIR}/${wrdstlogfile}\"/>" >> $jobfile
echo " <Stdout dest=\"${FARMDIR}/job${tarName}.out\"></Stdout>" >> $jobfile
echo " <Stderr dest=\"${FARMDIR}/job${tarName}.err\"></Stderr>" >> $jobfile
echo " </Job>" >> $jobfile
echo "</Request>" >> $jobfile
echo "Running job $jobfile..."
jsub --xml $jobfile
fi
done