-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_model-indep_classic_limits.sh
executable file
·478 lines (442 loc) · 17.9 KB
/
run_model-indep_classic_limits.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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#!/bin/bash
# based on https://github.com/KIT-CMS/MSSMvsSMRun2Legacy/tree/ntuple_processor
ulimit -s unlimited
TAG=$1
MODE=$2
if [[ $TAG == "auto" ]]; then
TAG="cmb_ind"
fi
defaultdir=analysis_2022_02_28/$TAG
analysis="bsm-model-indep"
hSM_treatment="hSM-in-bg"
# hSM_treatment="no-hSM-in-bg"
categorization="classic"
sm_like_hists="bsm"
[[ ! -d ${defaultdir} ]] && mkdir -p ${defaultdir}
[[ ! -d ${defaultdir}/logs ]] && mkdir -p ${defaultdir}/logs
[[ ! -d ${defaultdir}/limits/condor ]] && mkdir -p ${defaultdir}/limits/condor
[[ ! -d ${defaultdir}/limits_ind/condor ]] && mkdir -p ${defaultdir}/limits_ind/condor
defaultdir=$(readlink -f analysis_2022_02_28/$TAG)
datacarddir=${defaultdir}/datacards_${analysis}
freeze="MH=1200,r_ggH=0.005,r_bbH=0.0015"
identifier_toy_submit=$(date +%Y_%m_%d)
[[ -z $3 ]] || identifier_toy_submit=$3
xrange () {
[ "$#" != 1 ] && exit
case $1 in
"250")
echo 0.12
;;
"300")
echo 0.08
;;
"350")
echo 0.05
;;
"400")
echo 0.05
;;
"450")
echo 0.05
;;
"500")
echo 0.03
;;
"600")
echo 0.014
;;
"700")
echo 0.01
;;
"800")
echo 0.008
;;
"900")
echo 0.01
;;
"1000")
echo 0.01
;;
"1200")
echo 0.007
;;
"1400")
echo 0.005
;;
"1600")
echo 0.003
;;
"1800")
echo 0.0018
;;
"2000")
echo 0.0014
;;
"2300")
echo 0.001
;;
"2600")
echo 0.0008
;;
"2900")
echo 0.0006
;;
"3200")
echo 0.0005
;;
"3500")
echo 0.0005
;;
*)
exit 1
;;
esac
}
yrange () {
[ "$#" != 1 ] && exit
case $1 in
"250")
echo 0.12
;;
"300")
echo 0.08
;;
"350")
echo 0.06
;;
"400")
echo 0.05
;;
"450")
echo 0.06
;;
"500")
echo 0.045
;;
"600")
echo 0.022
;;
"700")
echo 0.012
;;
"800")
echo 0.008
;;
"900")
echo 0.006
;;
"1000")
echo 0.005
;;
"1200")
echo 0.003
;;
"1400")
echo 0.002
;;
"1600")
echo 0.0016
;;
"1800")
echo 0.0014
;;
"2000")
echo 0.0012
;;
"2300")
echo 0.001
;;
"2600")
echo 0.0008
;;
"2900")
echo 0.0006
;;
"3200")
echo 0.0006
;;
"3500")
echo 0.0006
;;
*)
exit 1
;;
esac
}
if [[ $MODE == "initial" ]]; then
############
# morphing
############
morph_parallel.py --output ${defaultdir}/datacards \
--analysis ${analysis} \
--sub-analysis "none" \
--hSM-treatment ${hSM_treatment} \
--categorization ${categorization} \
--sm-like-hists ${sm_like_hists} \
--eras 2016,2017,2018 \
--category-list ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/input/mssm_classic_categories.txt \
--additional-arguments "--auto_rebin=1 --real_data=1 --manual_rebin=1" \
--variable mt_tot_puppi \
--sm-gg-fractions ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/data/higgs_pt_reweighting_fullRun2.root \
--parallel 10 2>&1 | tee -a ${defaultdir}/logs/morph_mssm_log.txt
############
# combining outputs
############
mkdir -p ${datacarddir}/combined/cmb/
rsync -av --progress ${datacarddir}/201?/htt_*/* ${datacarddir}/combined/cmb/ 2>&1 | tee -a ${defaultdir}/logs/copy_datacards.txt
for ERA in 2016 2017 2018; do
for CH in et mt tt em; do
mkdir -p ${datacarddir}/${ERA}/${CH}/
rsync -av --progress ${datacarddir}/${ERA}/htt_${CH}*/* ${datacarddir}/${ERA}/${CH}/ 2>&1 | tee -a ${defaultdir}/logs/copy_datacards.txt
done
mkdir -p ${datacarddir}/${ERA}/cmb/
rsync -av --progress ${datacarddir}/${ERA}/htt_*/* ${datacarddir}/${ERA}/cmb/ 2>&1 | tee -a ${defaultdir}/logs/copy_datacards.txt
done
# Perform checks on the produced datacards
# Run datacard check from Higgs PAG
combineTool.py -M T2W \
-o ws.root \
-P HiggsAnalysis.CombinedLimit.PhysicsModel:multiSignalModel \
--PO '"map=^.*/ggh_(i|t|b).?$:r_ggH[0,0,200]"' \
--PO '"map=^.*/bbh$:r_bbH[0,0,200]"' \
-i ${datacarddir}/restore_binning/ \
-m 110 \
--X-allow-no-signal --just-check-physics-model
ValidateDatacards.py ${datacarddir}/restore_binning/combined.txt.cmb \
--jsonFile ${datacarddir}/restore_binning/validation_restore_binning.json \
--mass 110 --printLevel 1
# Check number of produced datacards
EXPECTED=$(((4+4+2+7)*3))
if [[ $(ls ${datacarddir}/combined/cmb/*.txt | wc -l) != $EXPECTED ]]; then
echo -e "\033[0;31m[ERROR]\033[0m Not all datacards have been created or written. Please check the logs..."
echo "Expected ${EXPECTED} datacards written but found only $(ls ${datacarddir}/combined/cmb/ | wc -l) in the combined directory."
fi
elif [[ $MODE == "ws" ]]; then
############
# workspace creation
############
combineTool.py -M T2W -o "ws.root" \
-P HiggsAnalysis.CombinedLimit.PhysicsModel:multiSignalModel \
--PO '"map=^.*/ggh_(i|t|b).?$:r_ggH[0,0,200]"' \
--PO '"map=^.*/bbh$:r_bbH[0,0,200]"' \
-i ${datacarddir}/combined/cmb/ \
-m 125.0 --parallel 4 | tee -a ${defaultdir}/logs/workspace_independent.txt
elif [[ $MODE == "setup" ]]; then
############
# job setup creation
############
cd ${defaultdir}/limits_ind/condor
combineTool.py -m "60,80,100,120,125,130,140,160,180,200,250,300,350,400,450,500,600,700,800,900,1000,1200,1400,1600,1800,2000,2300,2600,2900,3200,3500" \
-M AsymptoticLimits \
--rAbsAcc 0 \
--rRelAcc 0.0005 \
--boundlist ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/input/mssm_boundaries.json \
--setParameters r_ggH=0,r_bbH=0 \
--redefineSignalPOIs r_bbH \
-d ${datacarddir}/combined/cmb/ws.root \
--there -n ".bbH" \
--job-mode condor \
--dry-run \
--task-name bbH_full_cmb \
--X-rtd FITTER_NEW_CROSSING_ALGO --X-rtd FITTER_NEVER_GIVE_UP --X-rtd FITTER_BOUND \
--cminDefaultMinimizerStrategy 0 \
--cminDefaultMinimizerTolerance 0.01 \
-v 1 | tee -a ${defaultdir}/logs/job_setup_modelind_bbh.txt
combineTool.py -m "60,80,100,120,125,130,140,160,180,200,250,300,350,400,450,500,600,700,800,900,1000,1200,1400,1600,1800,2000,2300,2600,2900,3200,3500" \
-M AsymptoticLimits \
--rAbsAcc 0 \
--rRelAcc 0.0005 \
--boundlist ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/input/mssm_boundaries.json \
--setParameters r_ggH=0,r_bbH=0 \
--redefineSignalPOIs r_ggH \
-d ${datacarddir}/combined/cmb/ws.root \
--there -n ".ggH" \
--job-mode condor \
--dry-run \
--task-name ggH_full_cmb \
--X-rtd FITTER_NEW_CROSSING_ALGO --X-rtd FITTER_NEVER_GIVE_UP --X-rtd FITTER_BOUND \
--cminDefaultMinimizerStrategy 0 \
--cminDefaultMinimizerTolerance 0.01 \
-v 1 | tee -a ${defaultdir}/logs/job_setup_modelind_ggh.txt
elif [[ $MODE == "ws-gof" ]]; then
for CH in et mt tt em; do
rsync -av --progress ${datacarddir}/201?/htt_${CH}_*/* ${datacarddir}/combined/${CH}/ 2>&1 | tee -a ${defaultdir}/logs/copy_datacards.txt
done
# Copy ttbar control region to every channel to include it in the workspaces
for ERA in 2016 2017 2018; do
for CH in et mt tt; do
rsync -av --progress ${datacarddir}/${ERA}/htt_em_2_${ERA}/* ${datacarddir}/${ERA}/${CH}/ 2>&1 | tee -a ${defaultdir}/logs/copy_datacards.txt
rsync -av --progress ${datacarddir}/${ERA}/htt_em_2_${ERA}/* ${datacarddir}/combined/${CH}/ 2>&1 | tee -a ${defaultdir}/logs/copy_datacards.txt
done
done
############
# workspace creation for GoF tests
############
combineTool.py -M T2W -o "ws-gof.root" \
-i ${datacarddir}/*/{et,mt,tt,em,cmb}/ \
--channel-masks \
-m 125.0 --parallel 8 | tee -a ${defaultdir}/logs/workspace_gof_independent.txt
elif [[ $MODE == "ws-plot" ]]; then
###############
# workspace production for plots
###############
combineTool.py -M T2W -o "ws.root" \
-P HiggsAnalysis.CombinedLimit.PhysicsModel:multiSignalModel \
--PO '"map=^.*/ggh_(i|t|b).?$:r_ggH[-50,200]"' \
--PO '"map=^.*/bbh$:r_bbH[-50,0,200]"' \
--X-allow-no-signal \
-i ${datacarddir}/201?/htt_*/ \
-m 125.0 \
--parallel 8 | tee -a ${defaultdir}/logs/workspace_plots_independent.txt
elif [[ $MODE == "submit" ]]; then
############
# job submission
############
cd ${defaultdir}/limits_ind/condor
condor_submit condor_bbH_full_cmb.sub
condor_submit condor_ggH_full_cmb.sub
elif [[ $MODE == "submit-local" ]]; then
############
# job submission
############
cp scripts/run_limits_locally.py ${defaultdir}/limits_ind/condor
cd ${defaultdir}/limits_ind/condor
python3 run_limits_locally.py --cores 10 --njobs 31 --taskname condor_bbH_full_cmb.sh
python3 run_limits_locally.py --cores 10 --njobs 31 --taskname condor_ggH_full_cmb.sh
elif [[ $MODE == "collect" ]]; then
for p in gg bb
do
combineTool.py -M CollectLimits ${datacarddir}/combined/cmb/higgsCombine.${p}H*.root \
--use-dirs \
-o ${datacarddir}/combined/cmb/mssm_${p}H_cmb.json
plotMSSMLimits.py --cms-sub "Preliminary" \
--title-right "138 fb^{-1} (13 TeV)" \
--process "${p}#phi" \
--y-axis-min 0.0001 \
--y-axis-max 1000.0 \
--show exp,obs ${datacarddir}/combined/cmb/mssm_${p}H_cmb_cmb.json \
--output mssm_model-independent_${p}H_cmb \
--logx \
--logy
done
elif [[ $MODE == "prefit-plots" ]]; then
#####################
# Extract prefit shapes.
#####################
for era in 2016 2017 2018; do
prefit_postfit_shapes_parallel.py --datacard_pattern "${datacarddir}/${era}/htt_em_2_*/combined.txt.cmb" \
--workspace_name ws.root \
--output_name prefit_shapes_${freeze}.root \
--parallel 8 | tee -a ${defaultdir}/logs/extract_model_independent_shapes-combined-${freeze}.log
prefit_postfit_shapes_parallel.py --datacard_pattern "${datacarddir}/${era}/htt_*_3*/combined.txt.cmb" \
--workspace_name ws.root \
--freeze_arguments "--freeze ${freeze}" \
--output_name prefit_shapes_${freeze}.root \
--parallel 8 | tee -a ${defaultdir}/logs/extract_model_independent_shapes-combined-${freeze}.log
done
hadd -f ${datacarddir}/combined/cmb/prefit_shapes_${freeze}.root ${datacarddir}/201?/htt_*/prefit_shapes_${freeze}.root | tee -a ${defaultdir}/logs/extract_model_independent_shapes-combined-${freeze}.log
for era in 2016 2017 2018; do
bash plotting/plot_shapes_mssm_model_independent.sh \
${era} \
"${datacarddir}/combined/cmb/prefit_shapes_${freeze}.root" \
"${datacarddir}/plots/prefit_shapes_$(echo ${freeze} | sed 's/=//g; s/\./p/g')/" \
et,mt,tt,em \
$(echo $freeze | cut -d, -f1 | cut -d= -f2) \
$(echo $freeze | cut -d, -f2 | cut -d= -f2)
done
elif [[ $MODE == "fit-for-plots" ]]; then
combineTool.py -M FitDiagnostics \
-d ${datacarddir}/combined/cmb/ws.root \
-m 200 \
--setParameters r_ggH=0,r_bbH=0 --setParameterRange r_ggH=-0.00001,0.00001:r_bbH=-2,5 \
--redefineSignalPOIs r_ggH --freezeParameters r_bbH,r_ggH \
--X-rtd MINIMIZER_analytic \
--cminDefaultMinimizerStrategy 0 --cminDefaultMinimizerTolerance 0.1 \
--robustHesse 1 \
-n .combined-cmb.for_shape_unblinding \
--there \
-v 1
elif [[ $MODE == "postfit-plots" ]]; then
######################
# Extract postfit shapes.
#####################
fitfile=${datacarddir}/combined/cmb/fitDiagnostics.combined-cmb.for_shape_unblinding.root
for era in 2016 2017 2018; do
prefit_postfit_shapes_parallel.py --datacard_pattern "${datacarddir}/${era}/htt_em_2_*/combined.txt.cmb" \
--workspace_name ws.root \
--fit_arguments "-f ${fitfile}:fit_b --postfit --sampling" \
--output_name postfit_shapes_${freeze}.root \
--parallel 8 | tee -a ${defaultdir}/logs/extract_model_independent_shapes-postfit-combined-${freeze}.log
prefit_postfit_shapes_parallel.py --datacard_pattern "${datacarddir}/${era}/htt_*_3*_*/combined.txt.cmb" \
--workspace_name ws.root \
--freeze_arguments "--freeze ${freeze}" \
--fit_arguments "-f ${fitfile}:fit_b --postfit --sampling" \
--output_name postfit_shapes_${freeze}.root \
--parallel 8 | tee -a ${defaultdir}/logs/extract_model_independent_shapes-postfit-combined-${freeze}.log
done
hadd -f ${datacarddir}/combined/cmb/postfit_shapes_${freeze}.root ${datacarddir}/201?/htt_*/postfit_shapes_${freeze}.root | tee -a ${defaultdir}/logs/extract_model_independent_shapes-postfit-combined-${freeze}.log
for era in 2016 2017 2018; do
bash plotting/plot_shapes_mssm_model_independent.sh \
${era} \
"${datacarddir}/combined/cmb/postfit_shapes_${freeze}.root" \
"${datacarddir}/plots/postfit_shapes_$(echo ${freeze} | sed 's/=//g; s/\./p/g')/" \
et,mt,tt,em \
$(echo $freeze | cut -d, -f1 | cut -d= -f2) \
$(echo $freeze | cut -d, -f2 | cut -d= -f2)
done
elif [[ $MODE == "prepare-ggH-bbH-scan" ]]; then
[[ ! -d ${defaultdir}/ggH_bbH_scan_ind/condor ]] && mkdir -p ${defaultdir}/ggH_bbH_scan_ind/condor
cd ${defaultdir}/ggH_bbH_scan_ind/condor
# Run 2D likelihood scans for r_ggH and r_bbH
combineTool.py -M MultiDimFit \
--algo grid --points 225 --split-points 50 \
-m "60,80,100,120,125,130,140,160,180,200,250,300,350,400,450,500,600,700,800,900,1000,1200,1400,1600,1800,2000,2300,2600,2900,3200,3500" \
--boundlist ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/input/mssm_ggH_bbH_2D_boundaries.json \
--setParameters r_ggH=0,r_bbH=0 --redefineSignalPOIs r_ggH,r_bbH \
-d ${datacarddir}/combined/cmb/ws.root \
--job-mode condor --dry-run --task-name ggH_bbH_likelihood_scan \
--X-rtd MINIMIZER_analytic --cminDefaultMinimizerStrategy 0 --cminDefaultMinimizerTolerance 0.01 \
-n ".ggH-bbH" \
-v 1
# --there -n ".ggH-bbH"
# -m "60,80,100,120,125,130,140,160,180,200,250,300,350,400,450,500,600,700,800,900,1000,1200,1400,1600,1800,2000,2300,2600,2900,3200,3500" \
# Create asimov dataset for SM-expectation.
combineTool.py -M MultiDimFit \
--algo none \
-m "125" \
--boundlist ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/input/mssm_ggH_bbH_2D_boundaries.json \
--setParameters r_ggH=0,r_bbH=0 --redefineSignalPOIs r_ggH,r_bbH \
-d ${datacarddir}/combined/cmb/ws.root \
-t -1 --saveToys \
--there -n ".2D.ToyDataset.SM1" \
--dry-run
# -d output/mssm_201017_SMHbkg/cmb/ws.root \ TODO: maybe need different datacard here
# Copy it to correct location
# Copy only necessary in case different datacards are used for the asimov creation and the fits.
# cp output/mssm_070617_SMHbkg/cmb/higgsCombine.2D.ToyDataset.SM1.MultiDimFit.mH125.123456.root output/mssm_201017/cmb/higgsCombine.2D.ToyDataset.SM1.MultiDimFit.mH125.123456.root
# Run fits on this asimov dataset
combineTool.py -M MultiDimFit \
--algo none \
-m "60,80,100,120,125,130,140,160,180,200,250,300,350,400,450,500,600,700,800,900,1000,1200,1400,1600,1800,2000,2300,2600,2900,3200,3500" \
--boundlist ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/input/mssm_ggH_bbH_2D_boundaries.json \
--setParameters r_ggH=0,r_bbH=0 --redefineSignalPOIs r_ggH,r_bbH \
-d ${datacarddir}/combined/cmb/ws.root \
-t -1 --toysFile higgsCombine.2D.ToyDataset.SM1.MultiDimFit.mH125.123456.root \
--job-mode condor --dry-run --task-name ggH_bbH_likelihood_SM --merge 3 \
--there -n ".2D.SM1.bestfit"
elif [[ $MODE == "submit-ggH-bbH-scan" ]]; then
cd ${defaultdir}/ggH_bbH_scan_ind/condor
condor_submit condor_ggH_bbH_likelihood_scan.sub
# condor_submit condor_ggH_bbH_likelihood_SM.sub
elif [[ $MODE == "collect-ggH-bbH-scan" ]]; then
cd ${defaultdir}/ggH_bbH_scan_ind/
for mass in 60 80 100 120 125 130 140 160 180 200 250 300 350 400 450 500 600 700 800 900 1000 1200 1400 1600 1800 2000 2300 2600 2900 3200 3500; do
python3 ${CMSSW_BASE}/src/CombineHarvester/MSSMvsSMRun2Legacy/plotting/plotMultiDimFit.py \
--title-right="138 fb^{-1} (13 TeV)" \
--cms-sub="Preliminary" \
--mass $mass \
-o 2D_limit_mH${mass} \
--debug-output test_mH${mass}.root \
condor/higgsCombine.ggH-bbH.POINTS.*.mH${mass}.root
done
fi