Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/rkansal47/HHbbVV into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rkansal47 committed Jun 30, 2023
2 parents af59b1e + b774bcd commit 48cbcbb
Show file tree
Hide file tree
Showing 34 changed files with 2,855 additions and 437 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ src/HHbbVV/postprocessing/outs
!paper
!paper/**

!inference_scans
!inference_scans/**

!.gitignore
!.github
Expand Down
5 changes: 3 additions & 2 deletions AnalysisPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@
- [x] Trim features
- [x] Check sculpting
- [x] Scan Txbb, BDT WPs
- [ ] Run over all kL and k_2V
- [ ] Re-run VBF with gen selection
- [x] Run over all kL and k_2V
- [x] Re-run VBF with gen selection
- [x] HH inference
- [ ] Theory uncertainties


Expand Down
59 changes: 59 additions & 0 deletions inference_scans/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# HH Inference scans

For HH limits, kl/c2v scans, etc. Adapted from https://github.com/LPC-HH/inference_scans.

- [HH Inference scans](#hh-inference-scans)
- [Setup](#setup)


## Setup

1. Make a fresh area on lxplus, for example:

```bash
mkdir ~/work/HH
```

2. Setup inference as follows
- Set up the environment in a new folder with a clean environment (no `cmsenv`, ETC.)
- Use `some_name` as the name of the environment.

```bash
git clone ssh://git@gitlab.cern.ch:7999/hh/tools/inference.git
cd inference
source setup.sh c1
```

TODO: update this with better datacard dirs and setting up card repos.

3. Add the following to the `.setups/v1.sh` file
```bash
export DHI_DATACARDS_RUN2="/afs/cern.ch/user/r/rkansal/work/hh/datacards_run2"
export DHI_DATA="/afs/cern.ch/user/r/rkansal/work/hh/inference/data"
export DHI_STORE="/eos/user/r/rkansal/bbVV/inference"
export Cbbww4q="bbww_hadronic/v1"
export VERSION="dev"
export UNBLINDED="False"
```

4. Checkout this repo outside of `inference`

```bash
cd ..
git clone https://github.com/rkansal47/HHbbVV.git
```


5. Finally, from the `inference_scans` directory in `screen` or `tmux`, run the desired script:

```bash
cd inference
source setup.sh v1 # required before running a scan
cd ../HHbbVV/inference_scans/
source run_likelihood_scan_2d_kl_c2v.sh
```

Note! Need to make persistent screens to log off lxplus while running:
https://hsf-training.github.io/analysis-essentials/shell-extras/persistent-screen.html

Also keep track of the specific lxplus node.
20 changes: 20 additions & 0 deletions inference_scans/run_upper_limits_point_r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# export DHI_CMS_POSTFIX="Supplementary"
law run PlotUpperLimitsAtPoint \
--version "$VERSION" \
--multi-datacards "$Cbbww4q" \
--datacard-names "bbVV" \
--file-types "pdf,png" \
--pois r \
--show-parameters kl,kt,C2V,CV \
--UpperLimits-workflow "htcondor" \
--UpperLimits-tasks-per-job 1 \
--x-log \
--campaign run2 \
--unblinded $UNBLINDED \
--h-lines 1 \
--save-hep-data True \
--remove-output 0,a,y
# --use-snapshot True \
# --Snapshot-workflow "local" \
24 changes: 24 additions & 0 deletions inference_scans/run_upper_limits_r_1d_c2v.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# export DHI_CMS_POSTFIX="Supplementary"
law run PlotUpperLimits \
--version "$VERSION" \
--datacards "$Cbbww4q" \
--xsec fb \
--pois r \
--scan-parameters C2V,-1,3,10 \
--UpperLimits-workflow "htcondor" \
--UpperLimits-tasks-per-job 1 \
--file-types "png,pdf" \
--campaign run2 \
--unblinded $UNBLINDED \
--y-log \
--show-parameters "kt,C2V,CV" \
--br bbww \
--save-ranges \
--remove-output 0,a,y \
--save-hep-data True \
--frozen-groups signal_norm_xsbr
# --use-snapshot True \ # for after unblinding
# --Snapshot-workflow "local" \
# --scan-parameters kl,-3,5,8 \
23 changes: 23 additions & 0 deletions inference_scans/run_upper_limits_r_1d_kl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# export DHI_CMS_POSTFIX="Supplementary"
law run PlotUpperLimits \
--version "$VERSION" \
--datacards "$Cbbww4q" \
--xsec fb \
--pois r \
--scan-parameters kl,-30,-12,7:kl,-7,-5,3:kl:kl,-2,7,19:kl,10,30,6 \
--UpperLimits-workflow "htcondor" \
--UpperLimits-tasks-per-job 1 \
--file-types "png,pdf" \
--campaign run2 \
--unblinded $UNBLINDED \
--y-log \
--show-parameters "kt,C2V,CV" \
--br bbww \
--save-ranges \
--remove-output 0,a,y \
--save-hep-data True \
--frozen-groups signal_norm_xsbr
# --use-snapshot True \ # for after unblinding
# --Snapshot-workflow "local" \
5 changes: 3 additions & 2 deletions src/HHbbVV/combine/run_blinded.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ cards_dir="./"
ws=${cards_dir}/combined
wsm=${ws}_withmasks
wsm_snapshot=higgsCombineSnapshot.MultiDimFit.mH125
CMS_PARAMS_LABEL="CMS_bbWW_hadronic"

outsdir=${cards_dir}/outs
mkdir -p $outsdir
Expand All @@ -123,8 +124,8 @@ if [ $resonant = 0 ]; then
freezeparamsblinded=""
for bin in {5..9}
do
setparamsblinded+="CMS_bbWW_boosted_ggf_qcdparam_msdbin${bin}=0,"
freezeparamsblinded+="CMS_bbWW_boosted_ggf_qcdparam_msdbin${bin},"
setparamsblinded+="${CMS_PARAMS_LABEL}_tf_dataResidual_Bin${bin}=0,"
freezeparamsblinded+="${CMS_PARAMS_LABEL}_tf_dataResidual_Bin${bin},"
done

# remove last comma
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"import pandas as pd\n",
"\n",
"# from pandas.core.common import SettingWithCopyWarning\n",
"from sample_labels import sig_key, data_key\n",
"from hh_vars import data_key\n",
"\n",
"# ignore these because they don't seem to apply\n",
"# warnings.simplefilter(action=\"ignore\", category=SettingWithCopyWarning)\n",
"\n",
"from PyPDF2 import PdfFileMerger\n",
"from PyPDF2 import PdfMerger\n",
"\n",
"from copy import deepcopy\n",
"\n",
Expand Down Expand Up @@ -49,7 +49,7 @@
"metadata": {},
"outputs": [],
"source": [
"plot_dir = \"../../../plots/ttsfs/23Feb1\"\n",
"plot_dir = \"../../../plots/ttsfs/23Jun22\"\n",
"\n",
"import os\n",
"\n",
Expand All @@ -75,7 +75,7 @@
"top_matched_key = \"TT Top Matched\"\n",
"\n",
"# data_dir = \"../../../../data/ttsfs/Dec22/\"\n",
"data_dir = \"../../../../data/ttsfs/Jan31/\"\n",
"data_dir = \"../../../../data/ttsfs/23Jun9/\"\n",
"year = \"2018\"\n",
"\n",
"# filters = [(\"('ak8FatJetPt', '0')\", \">=\", 500)]\n",
Expand All @@ -90,37 +90,8 @@
"metadata": {},
"outputs": [],
"source": [
"data_dir = \"../../../../data/ttsfs/Jan17/\"\n",
"sample = \"TTToSemiLeptonic\"\n",
"\n",
"# utils.get_cutflow(f\"{data_dir}/{year}/TTToSemiLeptonic/pickles\", year, \"TTToSemiLeptonic\")\n",
"utils.get_cutflow(f\"{data_dir}/{year}/{sample}/pickles\", year, sample)\n",
"\n",
"# import pickle\n",
"\n",
"# for i in range(68):\n",
"# with open(f\"{data_dir}/{year}/{sample}/pickles/out_{i}.pkl\", \"rb\") as file:\n",
"# out_dict = pickle.load(file)[year][sample]['cutflow']\n",
"# print(out_dict[\"all\"])\n",
"# utils.get_cutflow(f\"{data_dir}/{year}/{sample}/pickles\", year, sample)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_dir = \"../../../../data/ttsfs/Jan19/\"\n",
"\n",
"# utils.get_cutflow(f\"{data_dir}/{year}/TTToSemiLeptonic/pickles\", year, \"TTToSemiLeptonic\")\n",
"utils.get_cutflow(f\"{data_dir}/{year}/{sample}/pickles\", year, sample)\n",
"\n",
"# import pickle\n",
"\n",
"# with open(f\"{data_dir}/{year}/{sample}/pickles/out_1.pkl\", \"rb\") as file:\n",
"# out_dict = pickle.load(file)[year][sample]['cutflow']\n",
"# print(out_dict)"
"utils.get_cutflow(f\"{data_dir}/{year}/{sample}/pickles\", year, sample)"
]
},
{
Expand Down Expand Up @@ -233,16 +204,36 @@
" \"TT Unmatched\",\n",
" \"TT W Matched\",\n",
" top_matched_key,\n",
"]"
"]\n",
"\n",
"bg_colours = {\n",
" \"QCD\": \"lightblue\",\n",
" \"Single Top\": \"darkblue\",\n",
" \"TT Unmatched\": \"darkgreen\",\n",
" \"TT W Matched\": \"green\",\n",
" \"TT Top Matched\": \"orange\",\n",
" \"W+Jets\": \"darkred\",\n",
" \"Diboson\": \"red\",\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Pre plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"events_dict.keys()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -251,16 +242,17 @@
"source": [
"# {var: (bins, label)}\n",
"plot_vars = {\n",
" \"ak8FatJetMass\": ([20, 125, 225], r\"$m_{SD}$ (GeV)\"),\n",
" \"ak8FatJetPt\": ([20, 500, 1200], r\"$p_T$ (GeV)\"),\n",
" \"ak8FatJetnPFCands\": ([20, 0, 120], r\"# of PF Candidates\"),\n",
" \"ak8FatJetParticleNet_Th4q\": ([20, 0.6, 1], r\"ParticleNet $T_{H4q}$ Non-MD\"),\n",
" \"ak8FatJetParTMD_THWW4q\": ([20, 0.6, 1], r\"ParT $T_{HWW4q}$ MD\"),\n",
" \"tau21\": ([20, 0.04, 0.8], r\"$\\tau_{21}$\"),\n",
" \"tau32\": ([20, 0.2, 1], r\"$\\tau_{32}$\"),\n",
" \"tau43\": ([20, 0.42, 1], r\"$\\tau_{43}$\"),\n",
" \"tau42\": ([20, 0, 1], r\"$\\tau_{42}$\"),\n",
" \"tau41\": ([20, 0, 1], r\"$\\tau_{41}$\"),\n",
" \"ak8FatJetMass\": ([30, 50, 200], r\"$m_{SD}$ (GeV)\"),\n",
" \"ak8FatJetParticleNetMass\": ([30, 50, 200], r\"$m_{reg}$ (GeV)\"),\n",
" # \"ak8FatJetPt\": ([20, 500, 1200], r\"$p_T$ (GeV)\"),\n",
" # \"ak8FatJetnPFCands\": ([20, 0, 120], r\"# of PF Candidates\"),\n",
" # \"ak8FatJetParticleNet_Th4q\": ([20, 0.6, 1], r\"ParticleNet $T_{H4q}$ Non-MD\"),\n",
" # \"ak8FatJetParTMD_THWW4q\": ([20, 0.6, 1], r\"ParT $T_{HWW4q}$ MD\"),\n",
" # \"tau21\": ([20, 0.04, 0.8], r\"$\\tau_{21}$\"),\n",
" # \"tau32\": ([20, 0.2, 1], r\"$\\tau_{32}$\"),\n",
" # \"tau43\": ([20, 0.42, 1], r\"$\\tau_{43}$\"),\n",
" # \"tau42\": ([20, 0, 1], r\"$\\tau_{42}$\"),\n",
" # \"tau41\": ([20, 0, 1], r\"$\\tau_{41}$\"),\n",
"}\n",
"\n",
"pre_hists = {}\n",
Expand All @@ -271,24 +263,29 @@
" events_dict, var, bins, label, weight_key=\"weight\"\n",
" )\n",
"\n",
"# merger_pre_plots = PdfFileMerger()\n",
"merger_pre_plots = PdfMerger()\n",
"\n",
"# for var, var_hist in pre_hists.items():\n",
"# name = f\"{plot_dir}/pre_{var}.pdf\"\n",
"# plotting.ratioLinePlot(\n",
"# var_hist,\n",
"# plot_samples,\n",
"# year,\n",
"# bg_err=None,\n",
"# name=name,\n",
"# )\n",
"# merger_pre_plots.append(name)\n",
"for var, var_hist in pre_hists.items():\n",
" name = f\"{plot_dir}/pre_{var}.pdf\"\n",
" plotting.ratioHistPlot(\n",
" var_hist,\n",
" year,\n",
" [],\n",
" plot_samples,\n",
" # bg_err=None,\n",
" name=name,\n",
" bg_colours=bg_colours,\n",
" bg_order=plot_samples,\n",
" ratio_ylims=[0.6, 1.3],\n",
" )\n",
" merger_pre_plots.append(name)\n",
"\n",
"# merger_pre_plots.write(f\"{plot_dir}/PrePlots.pdf\")\n",
"# merger_pre_plots.close()"
"merger_pre_plots.write(f\"{plot_dir}/PrePlots.pdf\")\n",
"merger_pre_plots.close()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -367,6 +364,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down
Loading

0 comments on commit 48cbcbb

Please sign in to comment.