-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.sh
419 lines (350 loc) · 11.2 KB
/
funcs.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/bin/bash
##
## Functions for doing 2017 MET Closure Tests
## Bobak Hashemi
HIST_OUTPUT_LOCATION=`cat ConfigHelper.C | grep "^TString HIST_OUTPUT_LOCATION=" |sed "s/.*HIST_OUTPUT_LOCATION=\"\(.*\)\";*/\1/g"`
PLOT_OUTPUT_LOCATION=`cat ConfigHelper.C | grep "^TString PLOT_OUTPUT_LOCATION=" | sed "s/.*PLOT_OUTPUT_LOCATION=\"\(.*\)\";*/\1/g"`
function makePlots {
if [[ $# < 1 ]]
then
echo "makePlots /path/to/config <no>(optional for no debug plots)"
return
fi
mkdirs $1 plots
conf_tmp_path=${1//.conf/.conf_tmp}
./preprocessConf.py $1
if [[ $2 == "no" ]]
then
nice -n 19 root -l -b -q "drawPlots.C(\"$conf_tmp_path\", 0)" | tee ${PLOT_OUTPUT_LOCATION}${SR_IDENTITY}`basename $conf_filename .conf`/output.txt
else
nice -n 19 root -l -b -q "drawPlots.C(\"$conf_tmp_path\")" | tee ${PLOT_OUTPUT_LOCATION}${SR_IDENTITY}`basename $conf_filename .conf`/output.txt
fi
echo https://github.com/bth5032/ZMETBabyLooper2017/commit/`git rev-parse HEAD`/ > ${PLOT_OUTPUT_LOCATION}${SR_IDENTITY}`basename $conf_filename .conf`/commiturl.txt
}
function makeHistos {
mkdirs $2 hists
conf_tmp_path=${2//.conf/.conf_tmp}
./preprocessConf.py $2
nice -n 19 root -l -b -q "doAll.C+(\"$1\", \"$conf_tmp_path\")" | tee ${HIST_OUTPUT_LOCATION}${SR_IDENTITY}/$1.output
echo https://github.com/bth5032/ZMETBabyLooper2017/commit/`git rev-parse HEAD`/ > ${HIST_OUTPUT_LOCATION}${SR_IDENTITY}/commiturl.txt
}
function setOutputLocations {
if [[ $# > 0 ]]
then
if [[ ${1:(-4)} == "conf" ]]
then
SR_IDENTITY=${1#*configs/}
SR_IDENTITY=`dirname $SR_IDENTITY`/
else
echo "You must give the location to a .conf file."
return 0
fi
fi
}
function mkdirs {
conf_filename=$1
setOutputLocations $conf_filename
if [[ $2 == "hists" ]]
then
#Make Hist output location if it's not there
if [[ ! -d ${HIST_OUTPUT_LOCATION}${SR_IDENTITY} ]]
then
mkdir -p ${HIST_OUTPUT_LOCATION}${SR_IDENTITY}
fi
#Legacy Style For Hist Configs
new_dir=`grep DEFAULT::histo_output_dir < $conf_filename`
if [[ ! -z $new_dir ]]
then
mkdir -p ${new_dir#*=}
fi
fi
if [[ $2 == "plots" ]]
then
#Make plot output location if it's not there.
if [[ ! -d ${PLOT_OUTPUT_LOCATION}${SR_IDENTITY}`basename $conf_filename .conf`"/Debug/" ]]
then
mkdir -p ${PLOT_OUTPUT_LOCATION}${SR_IDENTITY}`basename $conf_filename .conf`"/Debug/" #Make up to path/to/config/Debug
addIndexToDirTree ${PLOT_OUTPUT_LOCATION}${SR_IDENTITY}`basename $conf_filename .conf`"/Debug/" #Add index.php to each new folder
fi
#Legacy Style For Plots Configs
new_dir=`grep DEFAULT::save_dir < $conf_filename`
for l in `echo $new_dir`
do
if [[ ! -d ${l#*=} ]]
then
mkdir -p ${l#*=}"/Debug"
addIndexToDirTree ${l#*=}"/Debug"
fi
done
fi
}
function _makeAllForDir {
fname_hist=${1//\//_} #turn path into _ seperated
fname_hist=${fname_hist//__/_} #remove double underline string
fname_hist=${fname_hist%_}.hist_out #remove trailing _, add extension
fname_plots=${1//\//_} #turn path into _ seperated string
fname_plots=${fname_plots//__/_} #remove double underline
fname_plots=${fname_plots%_}.plots_out #remove trailing _, add extension
if [[ $2 == "hists" ]]
then
echo $1 > outputs/$fname_hist
makeHistosForDir $1 $3 >> outputs/$fname_hist 2>&1
elif [[ $2 == "plots" ]]
then
echo $1 > outputs/$fname_plots
makePlotsForDir $1 >> outputs/$fname_plots 2>&1
elif [[ $2 == "all" ]]
then
echo $1 > outputs/$fname_hist
makeHistosForDir $1 $3 >> outputs/$fname_hist 2>&1
echo $1 > outputs/$fname_plots
makePlotsForDir $1 >> outputs/$fname_plots 2>&1
else
echo "Please choose a step to run over, hists, plots, or all"
fi
}
function makeAllForDir {
if [[ $# < 2 ]]
then
echo "makeAllForDir <path_to_configs> <all/hists/plots> <sample_name | only if given hists or all>"
elif [[ `find $1/* -maxdepth 0 -type d | wc -l` > 0 ]]
then
for i in `find $1/* -maxdepth 0 -type d`
do
echo "recursing into $i"
makeAllForDir $i $2 $3
done
else
echo -n `basename $1`" -- "
_makeAllForDir $1 $2 $3 &
fi
}
function makeHistosForDir {
#Takes at most 2 args, the first is the name of the directory to run the run_modes over
#the second is the name of the sample config. If no sample config is given, it runs over "all"
if [[ $# < 2 ]]
then
makeHistosForDir_whichHist=all
else
makeHistosForDir_whichHist=$2
fi
if [[ -a $1/run_modes.conf ]]
then
makeHistos $makeHistosForDir_whichHist $1/run_modes.conf
else
echo "Can not find $1/run_modes.conf"
fi
}
function makePlotsForDir {
for i in `ls ${1}/*plots*.conf`
do
makePlots $i
done
}
function addIndexToDirTree {
#Adds the file at ~/public_html/ZMET2017/index.php into everything inside of the ~/public_html/ClosureTests/ directory for the directory given as $1.
topdir=$1
while [[ ${topdir%ZMET2017*} == "/home/users/bhashemi/public_html/" ]]
do
if [[ ! -a ${topdir}/index.php ]]
then
cp ~/public_html/index.php ${topdir}/index.php
fi
topdir=`dirname $topdir`
done
}
function makeAllConfigs {
if [[ $# < 2 ]]
then
echo "makeAllConfigs <all/plots/hists> <path_to_configs>"
return
fi
for i in Strong_Btag/2j/ Strong_Btag/4j/ Strong_Btag/6j/ Strong_Bveto/2j/ Strong_Bveto/4j/ Strong_Bveto/6j/ TChiHZ/ baseline/ TChiWZ/ Edge/
do
makeAllForDir $2/${i} $1
done
}
function numjobs {
psout=`ps aux | grep bsathian | grep "configs/"`
if [[ $1 == "v" ]]
then
echo "$psout" | grep "root -l"
fi
echo "scale=3; "`echo "$psout" | wc -l`"*(1/2) - 1/2" | bc;
}
function pullHists {
if [[ -z $HIST_OUTPUT_LOCATION || -z $SR_IDENTITY ]]
then
echo "please run setOutputLocations <path_to_run_modes.conf> first"
return 1
fi
scp uaf:${HIST_OUTPUT_LOCATION}${SR_IDENTITY}*.root histos/
}
function killjobs {
kill -9 `ps aux | grep "^bhashemi" | grep "root" | head -n-1 | cut -d' ' -f2 | xargs`
}
function addHists {
if [[ $# < 2 ]]
then
echo "Calls hadd for you and determines which files you mean and where to put output by file's config Name"
echo "addHists <output_fname> <input_1> <input_2> ..."
return 1
fi
if [[ -z $HIST_OUTPUT_LOCATION || -z $SR_IDENTITY ]]
then
echo "please run setOutputLocations <path_to_run_modes.conf> first"
return 1
fi
HADD_LIST=${HIST_OUTPUT_LOCATION}${SR_IDENTITY}${2}".root"
for arg in ${@:3}
do
HADD_LIST="$HADD_LIST ${HIST_OUTPUT_LOCATION}${SR_IDENTITY}${arg}.root"
done
echo "Running: hadd ${HIST_OUTPUT_LOCATION}${SR_IDENTITY}$1.root $HADD_LIST"
hadd ${HIST_OUTPUT_LOCATION}${SR_IDENTITY}$1.root $HADD_LIST
}
function makeL1PrescaleWeightHists {
OutputDir=/nfs-7/userdata/bobak/GJetsClosureTests2016/Data/
rm ${OutputDir}L1PrescaleWeight*.root
for j in nVert_HLT_Photon22_R9Id90_HE10_IsoM nVert_HLT_Photon30_R9Id90_HE10_IsoM nVert_HLT_Photon36_R9Id90_HE10_IsoM
do
for i in `getSRs`
do
output_location=${OutputDir}L1PrescaleWeight_$i.root
infile1=${OutputDir}ct_Z_Base_$i.root
infile2=${OutputDir}ct_G_Base_$i.root
hist1="zjets_nVert"
hist2="gjets_"$j
output_hist_name="rwt_"$j
root -l -b -q "makeWeightHisto_noconf.C(\"${output_location}\",\"${infile1}\",\"${infile2}\",\"${hist1}\",\"${hist2}\",\"${output_hist_name}\")"
done
done
}
function lt {
#Prints parsed latex table for config
if [[ $# < 1 ]]
then
echo "lt <path/to/plot/output_1> <path/to/plot/output_2> ..."
return
fi
for arg in ${@}
do
lt_srid=${arg#*Final_}
lt_srid=${lt_srid%.plots_out}
lt_srid=${lt_srid//_/ }
echo "\textbf{${lt_srid}:}"
echo ""
cat $arg | grep "LATEXTABLE: " | sed -e 's/^LATEXTABLE: //g' -e 's/-6001/+/g'
echo ""
done
}
function tempErr {
#Prints parsed template error table for config
if [[ $# < 1 ]]
then
echo "tempErr <path/to/plot/output_1> <path/to/plot/output_2> ..."
return
fi
for arg in ${@}
do
tempErr_srid=${arg#*Final_}
tempErr_srid=${tempErr_srid%.plots_out}
tempErr_srid=${tempErr_srid//_/ }
echo "\textbf{${tempErr_srid}:}"
echo ""
cat $arg | grep "TEMPLATEDEBUG: " | sed -e 's/^TEMPLATEDEBUG: //g' -e 's/-6001/+/g'
echo ""
done
}
function uncParse {
if [[ $# < 1 ]]
then
echo "uncParse <path/to/datacard/template>"
return
fi
cat $1 | grep -o "<[^ ]*>" | sort | uniq
}
function effTable {
#===========================================================
# Prints the efficiency table for the configuration with
# a few cosmetic fixes, such a removing {document} tags and
# changing ranges x-6001 to x+.
#
# This is mainly used for the Templates Closure Tests at the
# moment, which are default output to outputs/efficiency_table...
#===========================================================
if [[ $# < 1 ]]
then
echo "effTable <path/to/plot/output_1> <path/to/plot/output_2> ..."
return
fi
echo "\\documentclass[a4paper,landscape]{article}"
echo "\\usepackage{fullpage}"
echo "\\usepackage{float}"
echo "\\usepackage{multicol}"
echo "\\usepackage{adjustbox}"
echo "\\begin{document}"
for arg in ${@}
do
effTable_name=${arg#*table_}
effTable_name=${effTable_name%.tex}
effTable_name=${effTable_name//_/ }
echo "\\section*{$effTable_name}"
cat $arg | sed -e 's/-6001.00/+/g' -e 's,+/-,$\\pm$,g' -e 's/\[ht!\]/[H]/g' | grep -v "{document}" | grep -v "documentclass{article}" | grep -v "usepackage"
echo ""
done
echo "\\end{document}"
}
function backupConfig {
#===========================================================
# Backs up configuration with the given config directory, allows
# you to leave a message in the backup dir which tells what has
# changed in the new version.
#===========================================================
backupConfig_path=$1
if [[ $# < 1 ]]
then
echo "backupConfig configs/path/to/confdir"
read -e -p "Config Dir Path: " backupConfig_path
fi
backupConfig_path=${backupConfig_path%/} #Remove Trailing '/' if it's there.
SR_IDENTITY=${backupConfig_path#*configs/}
backupConfig_movePlots="n"
backupConfig_moveHists="n"
backupConfig_timestamp=`date +%m%d%y_%Hh%M`
backupConfig_message=
backupConfig_histdir=${HIST_OUTPUT_LOCATION}${SR_IDENTITY} #Current hists dir
backupConfig_histbak=${backupConfig_histdir}_bak${backupConfig_timestamp} #New hists dir
backupConfig_plotdir=${PLOT_OUTPUT_LOCATION}${SR_IDENTITY} #Current plots dir
backupConfig_plotbak=${backupConfig_plotdir}_bak${backupConfig_timestamp} #New plots dir
if [[ ! -d $backupConfig_path ]]
then
echo "Could not find directory: "$backupConfig_path", please try again"
return
fi
if [[ -d ${backupConfig_histdir} ]]
then
read -p "move hists at ${backupConfig_histdir} to ${backupConfig_histbak}? (y/n)" backupConfig_moveHists
else
echo "No previous hists found at ${backupConfig_histdir}"
fi
if [[ -d ${backupConfig_plotdir} ]]
then
read -p "move plots at ${backupConfig_plotdir} to ${backupConfig_plotbak}? (y/n)" backupConfig_movePlots
else
echo "No previous plots found at ${backupConfig_plotdir}"
fi
read -e -p "What changes in the next version: " backupConfig_message
if [[ "$backupConfig_moveHists" == "y" ]]
then
cp -r $backupConfig_histdir $backupConfig_histbak
echo $backupConfig_message > ${backupConfig_histbak}/backup_log.txt
echo "Moved Hists"
fi
if [[ "$backupConfig_movePlots" == "y" ]]
then
cp -r $backupConfig_plotdir $backupConfig_plotbak
echo $backupConfig_message > ${backupConfig_plotbak}/backup_log.txt
echo "Moved Plots"
fi
}