-
Notifications
You must be signed in to change notification settings - Fork 0
/
embeddded_tauES_ul2018.sh
executable file
·327 lines (291 loc) · 13 KB
/
embeddded_tauES_ul2018.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
export PYTHONPATH=$PYTHONPATH:$PWD/Dumbledraw
CHANNEL=$1
ERA=$2
NTUPLETAG=$3
TAG=$4
MODE=$5
VARIABLES="m_vis"
ulimit -s unlimited
source utils/setup_ul_samples.sh $NTUPLETAG $ERA
output_shapes="taues_shapes-${ERA}-${CHANNEL}-${NTUPLETAG}-${TAG}"
CONDOR_OUTPUT=output/condor_shapes/${ERA}-${CHANNEL}-${NTUPLETAG}-${TAG}
shapes_output=output/${ERA}-${CHANNEL}-${NTUPLETAG}-${TAG}/${output_shapes}
shapes_output_synced=output/${ERA}-${CHANNEL}-${NTUPLETAG}-${TAG}/synced
shapes_rootfile=${shapes_output}.root
shapes_rootfile_synced=${shapes_output_synced}_synced.root
# Datacard Setup
datacard_output="datacards/${NTUPLETAG}-${TAG}/${ERA}_taues"
# print the paths to be used
echo "KINGMAKER_BASEDIR: $KINGMAKER_BASEDIR"
echo "BASEDIR: ${BASEDIR}"
echo "output_shapes: ${output_shapes}"
echo "FRIENDS: ${FRIENDS}"
categories=("DM0" "DM1" "DM10_11" "Inclusive")
printf -v categories_string '%s,' "${categories[@]}"
echo "Using Cateogires ${categories_string%,}"
if [[ $MODE == "COPY" ]]; then
source utils/setup_root.sh
echo "##############################################################################################"
echo "# Copy sample to ceph, it not there yet #"
echo "##############################################################################################"
# if the xsec friends directory does not exist, create it
if [ ! -d "$BASEDIR/$ERA" ]; then
mkdir -p $BASEDIR/$ERA
fi
if [ "$(ls -A $BASEDIR/$ERA)" ]; then
echo "Ntuples already copied to ceph"
else
echo "Copying ntuples to ceph"
rsync -avhPl $KINGMAKER_BASEDIR$ERA/ $BASEDIR$ERA/
fi
exit 0
elif [[ $MODE == "COPY_XROOTD" ]]; then
source utils/setup_root.sh
echo "##############################################################################################"
echo "# Copy sample to ceph, it not there yet #"
echo "##############################################################################################"
echo "[INFO] Copying ntuples to ceph via xrootd"
echo "xrdcp -r $KINGMAKER_BASEDIR_XROOTD$ERA/ $BASEDIR$ERA/"
if [ ! -d "$BASEDIR/$ERA" ]; then
mkdir -p $BASEDIR/$ERA
fi
xrdcp -r $KINGMAKER_BASEDIR_XROOTD$ERA $BASEDIR
exit 0
fi
# echo "##############################################################################################"
# echo "# unset multicore bit #"
# echo "##############################################################################################"
# python3 unset_rootbit.py --basepath ${BASEDIR}
if [[ $MODE == "XSEC" ]]; then
source utils/setup_root.sh
echo "##############################################################################################"
echo "# Checking xsec friends directory #"
echo "##############################################################################################"
# if the xsec friends directory does not exist, create it
if [ ! -d "$XSEC_FRIENDS" ]; then
mkdir -p $XSEC_FRIENDS
fi
# if th xsec friends dir is empty, run the xsec friends script
if [ "$(ls -A $XSEC_FRIENDS)" ]; then
echo "xsec friends dir already exists"
else
echo "xsec friends dir is empty"
echo "running xsec friends script"
python3 friends/build_friend_tree.py --basepath $BASEDIR --outputpath $XSEC_FRIENDS --nthreads 20
fi
exit 0
fi
echo "##############################################################################################"
echo "# Producing shapes for ${CHANNEL}-${ERA}-${NTUPLETAG} #"
echo "##############################################################################################"
# if the output folder does not exist, create it
if [ ! -d "$shapes_output" ]; then
mkdir -p $shapes_output
fi
if [[ $MODE == "CONTROL" ]]; then
source utils/setup_root.sh
python shapes/produce_shapes.py --channels $CHANNEL \
--directory $NTUPLES \
--${CHANNEL}-friend-directory $XSEC_FRIENDS $FF_FRIENDS \
--era $ERA --num-processes 4 --num-threads 3 \
--optimization-level 1 --skip-systematic-variations \
--special-analysis "TauES" \
--control-plot-set ${VARIABLES} \
--output-file $shapes_output
fi
if [[ $MODE == "LOCAL" ]]; then
source utils/setup_root.sh
python shapes/produce_shapes.py --channels $CHANNEL \
--directory $NTUPLES \
--${CHANNEL}-friend-directory $FRIENDS \
--era $ERA --num-processes 4 --num-threads 4 \
--optimization-level 1 \
--special-analysis "TauES" \
--control-plot-set ${VARIABLES} \
--output-file $shapes_output
fi
if [[ $MODE == "CONDOR" ]]; then
source utils/setup_root.sh
echo "[INFO] Running on Condor"
echo "[INFO] Condor output folder: ${CONDOR_OUTPUT}"
bash submit/submit_shape_production_ul.sh $ERA $CHANNEL \
"singlegraph" $TAG 0 $NTUPLETAG $CONDOR_OUTPUT "TauES"
echo "[INFO] Jobs submitted"
fi
if [[ $MODE == "MERGE" ]]; then
source utils/setup_root.sh
echo "[INFO] Merging outputs located in ${CONDOR_OUTPUT}"
hadd -j 5 -n 600 -f $shapes_rootfile ${CONDOR_OUTPUT}/../analysis_unit_graphs-${ERA}-${CHANNEL}-${NTUPLETAG}-${TAG}/*.root
fi
if [[ $MODE == "PLOT-CONTROL" ]]; then
source utils/setup_root.sh
echo "##############################################################################################"
echo "# plotting #"
echo "##############################################################################################"
bash ./shapes/do_estimations.sh 2018 ${shapes_rootfile} 1
for CATEGORY in "${categories[@]}"; do
python3 plotting/plot_shapes_control.py -l --era Run${ERA} --input ${shapes_rootfile} --variables ${VARIABLES} --channels ${CHANNEL} --embedding --fake-factor --category $CATEGORY
python3 plotting/plot_shapes_control.py -l --era Run${ERA} --input ${shapes_rootfile} --variables ${VARIABLES} --channels ${CHANNEL} --embedding --category $CATEGORY
python3 plotting/plot_shapes_control.py -l --era Run${ERA} --input ${shapes_rootfile} --variables ${VARIABLES} --channels ${CHANNEL} --fake-factor --category $CATEGORY
python3 plotting/plot_shapes_control.py -l --era Run${ERA} --input ${shapes_rootfile} --variables ${VARIABLES} --channels ${CHANNEL} --category $CATEGORY
done
fi
if [[ $MODE == "SYNC" ]]; then
source utils/setup_root.sh
echo "##############################################################################################"
echo "# Additional estimations #"
echo "##############################################################################################"
bash ./shapes/do_estimations.sh 2018 ${shapes_rootfile} 1 "TauES"
echo "##############################################################################################"
echo "# synced shapes #"
echo "##############################################################################################"
# if the output folder does not exist, create it
if [ ! -d "$shapes_output_synced" ]; then
mkdir -p $shapes_output_synced
fi
python shapes/convert_to_synced_shapes.py -e $ERA \
-i ${shapes_rootfile} \
-o ${shapes_output_synced} \
--variable-selection ${VARIABLES} \
--special "TauES" \
-n 1
POSTFIX="-ML"
inputfile="htt_${CHANNEL}.inputs-sm-Run${ERA}${POSTFIX}.root"
hadd -f $shapes_output_synced/$inputfile $shapes_output_synced/${ERA}-${CHANNEL}*.root
exit 0
fi
if [[ $MODE == "DATACARD" ]]; then
source utils/setup_cmssw.sh
# inputfile
POSTFIX="-ML"
TAG=
inputfile="htt_${CHANNEL}.inputs-sm-Run${ERA}${POSTFIX}.root"
$CMSSW_BASE/bin/slc7_amd64_gcc700/MorphingTauES_UL \
--base_path=$PWD \
--input_folder_mt=$shapes_output_synced \
--real_data=true \
--classic_bbb=true \
--verbose=true \
--postfix=$POSTFIX \
--auto_rebin=false \
--rebin_categories=false \
--era=$ERA \
--output="output/$datacard_output"
# THIS_PWD=${PWD}
# echo $THIS_PWD
# cd output/$datacard_output/
# echo $PWD
# echo "$(ls -l)"
# for FILE in htt_mt_*/*.txt; do
# sed -i '$s/$/\n * autoMCStats 0.0/' $FILE
# done
# cd $THIS_PWD
# for INPUT in output/$datacard_output/htt_mt_*; do
# echo "[INFO] Add datacards to workspace from path ${INPUT}"
# #OUTPUT=${ERA}_workspace.root
# WORKSPACE=${INPUT}/workspace.root
# echo "[INFO] Write workspace to ${WORKSPACE}"
# combineTool.py -M T2W -o ${WORKSPACE} -i ${INPUT}
# done
combineTool.py -M T2W -i output/$datacard_output/htt_mt_*/ -o workspace.root --parallel 4 --X-no-check-norm
exit 0
fi
if [[ $MODE == "FIT" ]]; then
source utils/setup_cmssw.sh
for INPUT in output/$datacard_output/htt_mt_Inclusive; do
echo "[INFO] Fit workspace from path ${INPUT}"
WORKSPACE=${INPUT}/workspace.root
combine \
-M MultiDimFit \
-n _initialFit_Test \
--algo singles \
--redefineSignalPOIs taues,r \
--setParameterRanges taues=-2.5,2.5:r=0.8,1.2 \
--robustFit 1 \
-m 0 -d ${WORKSPACE} \
--setParameters taues=-1.5,r=1.0 \
--setRobustFitAlgo=Minuit2 \
--setRobustFitStrategy=0 \
--setRobustFitTolerance=0.2 \
--X-rtd FITTER_NEW_CROSSING_ALGO \
--X-rtd FITTER_NEVER_GIVE_UP \
--X-rtd FITTER_BOUND \
--cminFallbackAlgo "Minuit2,0:0.1" \
--cminFallbackAlgo "Minuit,0:0.1"
combineTool.py -M MultiDimFit -d ${WORKSPACE} \
--algo grid \
--X-rtd MINIMIZER_analytic --cminDefaultMinimizerStrategy 0 \
-P taues -m 0 \
--redefineSignalPOIs taues,r \
--setParameterRanges taues=-2.05,-0.45:r=0.8,1.2 \
--floatOtherPOIs 1 \
--points 30 \
--robustFit 1 \
--setRobustFitAlgo=Minuit2 \
--setRobustFitStrategy=0 \
--setRobustFitTolerance=0.2 \
--X-rtd FITTER_NEW_CROSSING_ALGO \
--X-rtd FITTER_NEVER_GIVE_UP \
--X-rtd FITTER_BOUND \
--cminFallbackAlgo "Minuit2,0:0.1" \
--cminFallbackAlgo "Minuit,0:0.1" \
-n ${ERA}_taues
cp higgsCombine${ERA}_taues.MultiDimFit.mH0.root ${INPUT}
done
exit 0
fi
if [[ $MODE == "POSTFIT" ]]; then
source utils/setup_cmssw.sh
for INPUT in output/$datacard_output/htt_mt_Inclusive; do
CATEGORY=$(basename $INPUT)
python fitting/plot1DScan.py \
--main ${INPUT}/higgsCombine${ERA}_taues.MultiDimFit.mH0.root \
--POI taues --remin-main \
--output ${ERA}_${CATEGORY}_taues_plot_nll \
--translate fitting/translate.json \
--y-max 2.5 --main-color 2
done
exit 0
fi
if [[ $MODE == "PLOT-POSTFIT" ]]; then
source utils/setup_cmssw.sh
for RESDIR in output/$datacard_output/htt_mt_Inclusive; do
WORKSPACE=${RESDIR}/workspace.root
echo "[INFO] Printing fit result for category $(basename $RESDIR)"
FILE=${RESDIR}/postfitshape.root
FITFILE=${RESDIR}/fitDiagnostics.${ERA}.root
combine \
-n .$ERA \
-M FitDiagnostics \
-d $WORKSPACE \
--redefineSignalPOIs taues,r \
--setParameterRanges taues=-2.0,-0.5:r=0.8,1.2 \
--robustFit 1 -v1 \
--robustHesse 1 \
--X-rtd MINIMIZER_analytic \
--cminDefaultMinimizerStrategy 0
mv fitDiagnostics.2018.root $FITFILE
echo "[INFO] Building Prefit/Postfit shapes"
PostFitShapesFromWorkspace -w ${WORKSPACE} \
-m 125 -d ${RESDIR}/combined.txt.cmb \
-o ${FILE} \
-f ${FITFILE}:fit_s --postfit
done
source utils/setup_root.sh
i=1
for RESDIR in output/$datacard_output/htt_mt_Inclusive; do
WORKSPACE=${RESDIR}/workspace.root
CATEGORY=$(basename $RESDIR)
FILE=${RESDIR}/postfitshape.root
FITFILE=${RESDIR}/fitDiagnostics.${ERA}.root
# create output folder if it does not exist
if [ ! -d "output/postfitplots/" ]; then
mkdir -p output/postfitplots/
fi
echo "[INFO] Postfits plots for category $CATEGORY"
python3 plotting/plot_shapes_tauID_postfit.py -l --era ${ERA} --input ${FILE} --channel ${CHANNEL} --embedding --fake-factor --single-category $CATEGORY --categories "None" -o output/postfitplots/ --prefit
python3 plotting/plot_shapes_tauID_postfit.py -l --era ${ERA} --input ${FILE} --channel ${CHANNEL} --embedding --fake-factor --single-category $CATEGORY --categories "None" -o output/postfitplots/
i=$((i + 1))
done
exit 0
fi