diff --git a/README.md b/README.md index cb6850a4..95614be3 100644 --- a/README.md +++ b/README.md @@ -304,12 +304,23 @@ git clone -b v2.0.0 https://github.com/cms-analysis/CombineHarvester.git Combine scramv1 b clean; scramv1 b ``` +I also add this to my .bashrc for convenience: + +``` +export PATH="$PATH:/uscms_data/d1/rkansal/HHbbVV/src/HHbbVV/combine" + +csubmit() { + local file=$1; shift; + python "/uscms_data/d1/rkansal/HHbbVV/src/HHbbVV/combine/submit/submit_${file}.py" "$@" +} +``` + ### Run fits and diagnostics locally All via the below script, with a bunch of options (see script): ```bash -/uscms/home/rkansal/nobackup/HHbbVV/src/HHbbVV/combine/run_blinded.sh --workspace --bfit --limits +run_blinded.sh --workspace --bfit --limits ``` ### Run fits on condor @@ -317,15 +328,25 @@ All via the below script, with a bunch of options (see script): Can run over all the resonant signals (default) or scan working points for a subset of signals (`--scan`) ```bash -python src/HHbbVV/combine/submit.py --test --scan --resonant --templates-dir 23Apr30Scan +csubmit cards --test --scan --resonant --templates-dir 23Apr30Scan ``` Generate toys and fits for F-tests (after making cards and b-only fits) ```bash -python src/HHbbVV/combine/submit_ftest.py --tag 23May2 --cards-tag 23May2 --low1 0 --low2 0 +csubmit f_test --tag 23May2 --cards-tag 23May2 --low1 0 --low2 0 ``` +Bias tests: + +```bash +for bias in 0 0.15 0.3 +do + csubmit bias --seed 42 --num-jobs 10 --toys-per-job 10 --bias $bias --submit +done +``` + + ## Misc ### Command for copying directories to PRP in background diff --git a/src/HHbbVV/combine/binder/BiasTest.ipynb b/src/HHbbVV/combine/binder/BiasTest.ipynb index e69de29b..67a274a3 100644 --- a/src/HHbbVV/combine/binder/BiasTest.ipynb +++ b/src/HHbbVV/combine/binder/BiasTest.ipynb @@ -0,0 +1,244 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from typing import List\n", + "import uproot\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import mplhep as hep\n", + "import matplotlib.ticker as mticker\n", + "import os\n", + "\n", + "plt.style.use(hep.style.CMS)\n", + "hep.style.use(\"CMS\")\n", + "formatter = mticker.ScalarFormatter(useMathText=True)\n", + "formatter.set_powerlimits((-3, 3))\n", + "plt.rcParams.update({\"font.size\": 20})" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "MAIN_DIR = \"../../../../\"\n", + "\n", + "plot_dir = f\"{MAIN_DIR}/plots/BiasTest/23Jul10Res\"\n", + "_ = os.system(f\"mkdir -p {plot_dir}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "cards_dir = \"f_tests/23May2/nTF1_2_nTF2_1\"\n", + "# biases = [0., 0.15, 0.3, 1.0]\n", + "biases = [0.0, 0.15, 0.3, 1.0]\n", + "file = uproot.open(\n", + " f\"/uscms/home/rkansal/hhcombine/cards/{cards_dir}/higgsCombinebias0.3.FitDiagnostics.mH125.*.root\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "r_dict = {\n", + " 0.3: {\n", + " \"r\": np.array(file[\"limit\"][\"trackedParam_r\"])[::4],\n", + " \"rerr\": np.array(file[\"limit\"][\"trackedError_r\"])[::4],\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'r': array([0.25547278], dtype=float32),\n", + " 'rerr': array([0.17948698], dtype=float32)}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "r_dict[0.3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from scipy import stats\n", + "\n", + "\n", + "def plot_tests(\n", + " data_ts: float,\n", + " toy_ts: np.ndarray,\n", + " name: str,\n", + " title: str = None,\n", + " bins: int = 15,\n", + " fit: str = None,\n", + " fdof2: int = None,\n", + "):\n", + " plot_max = max(np.max(toy_ts), data_ts)\n", + " # plot_max = max(np.max(toy_ts), data_ts) if fit != \"chi2\" else 200\n", + " # plot_min = min(np.min(toy_ts), data_ts, 0)\n", + " plot_min = 0\n", + " pval = p_value(data_ts, toy_ts)\n", + "\n", + " plt.figure(figsize=(12, 8))\n", + " h = plt.hist(\n", + " toy_ts,\n", + " np.linspace(plot_min, plot_max, bins + 1),\n", + " color=\"#8C8C8C\",\n", + " histtype=\"step\",\n", + " label=f\"{len(toy_ts)} Toys\",\n", + " )\n", + " plt.axvline(data_ts, color=\"#FF502E\", linestyle=\":\", label=rf\"Data ($p$-value = {pval:.2f})\")\n", + "\n", + " if fit is not None:\n", + " x = np.linspace(plot_min + 0.01, plot_max, 100)\n", + "\n", + " if fit == \"chi2\":\n", + " res = stats.fit(stats.chi2, toy_ts, [(0, 200)])\n", + " pdf = stats.chi2.pdf(x, res.params.df)\n", + " label = rf\"$\\chi^2_{{DoF = {res.params.df:.2f}}}$ Fit\"\n", + " elif fit == \"f\":\n", + " pdf = stats.f.pdf(x, 1, fdof2)\n", + " label = rf\"$F-dist_{{DoF = (1, {fdof2})}}$\"\n", + " else:\n", + " raise ValueError(\"Invalid fit\")\n", + "\n", + " plt.plot(\n", + " x,\n", + " pdf * (np.max(h[0]) / np.max(pdf)),\n", + " color=\"#1f78b4\",\n", + " linestyle=\"--\",\n", + " # alpha=0.6,\n", + " label=label,\n", + " )\n", + "\n", + " hep.cms.label(\n", + " \"Work in Progress\",\n", + " data=True,\n", + " lumi=138,\n", + " year=None,\n", + " )\n", + "\n", + " _ = plt.legend()\n", + " plt.title(title)\n", + " plt.ylabel(\"Number of Toys\")\n", + " plt.xlabel(\"Test Statistics\")\n", + "\n", + " plt.savefig(f\"{plot_dir}/{name}.pdf\", bbox_inches=\"tight\")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Nonresonant" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "o1 = 0 # order being tested\n", + "tlabel = f\"{o1}\"\n", + "\n", + "data_ts, toy_ts = test_statistics[tlabel][\"data\"][tlabel], test_statistics[tlabel][\"toys\"][tlabel]\n", + "plot_tests(data_ts, toy_ts, \"gof\" + tlabel, fit=\"chi2\", bins=20)\n", + "\n", + "ord1 = 1\n", + "tflabel = f\"{ord1}\"\n", + "data_ts, toy_ts = pval = (\n", + " test_statistics[tlabel][\"fdata\"][tflabel],\n", + " test_statistics[tlabel][\"ftoys\"][tflabel],\n", + ")\n", + "plot_tests(data_ts, toy_ts, f\"f{tlabel}_{tflabel}\", title=f\"{o1} vs. {ord1}\")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Resonant" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "o1, o2 = 2, 0 # order being tested\n", + "tlabel = f\"{o1}{o2}\"\n", + "\n", + "data_ts, toy_ts = test_statistics[tlabel][\"data\"][tlabel], test_statistics[tlabel][\"toys\"][tlabel]\n", + "plot_tests(data_ts, toy_ts, \"gof\" + tlabel, fit=\"chi2\", bins=20)\n", + "\n", + "for ord1, ord2 in [[o1 + 1, o2], [o1, o2 + 1]]:\n", + " tflabel = f\"{ord1}{ord2}\"\n", + " data_ts, toy_ts = pval = (\n", + " test_statistics[tlabel][\"fdata\"][tflabel],\n", + " test_statistics[tlabel][\"ftoys\"][tflabel],\n", + " )\n", + " plot_tests(data_ts, toy_ts, f\"f{tlabel}_{tflabel}\", title=f\"({o1}, {o2}) vs. ({ord1}, {ord2})\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python39", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.15" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/HHbbVV/combine/binder/F_test.ipynb b/src/HHbbVV/combine/binder/F_test.ipynb index 43c32835..a061d022 100644 --- a/src/HHbbVV/combine/binder/F_test.ipynb +++ b/src/HHbbVV/combine/binder/F_test.ipynb @@ -29,7 +29,7 @@ "source": [ "MAIN_DIR = \"../../../../\"\n", "\n", - "plot_dir = f\"{MAIN_DIR}/plots/FTests/23May14\"\n", + "plot_dir = f\"{MAIN_DIR}/plots/FTests/23Jul6WP06\"\n", "_ = os.system(f\"mkdir -p {plot_dir}\")" ] }, @@ -120,9 +120,10 @@ "metadata": {}, "outputs": [], "source": [ - "eos_cards_dir = \"/eos/uscms/store/user/rkansal/bbVV/cards/f_tests/23May2/\"\n", - "local_cards_dir = \"/uscms/home/rkansal/hhcombine/cards/f_tests/23May2/\"\n", - "test_orders = [(0, 0), (1, 0), (0, 1), (1, 1), (2, 1), (1, 2), (2, 0), (0, 2)]\n", + "eos_cards_dir = \"/eos/uscms/store/user/rkansal/bbVV/cards/f_tests/23Jul6WP06/\"\n", + "local_cards_dir = \"/uscms/home/rkansal/hhcombine/cards/f_tests/23Jul6WP06/\"\n", + "# test_orders = [(0, 0), (1, 0), (0, 1), (1, 1), (2, 1), (1, 2), (2, 0), (0, 2)]\n", + "test_orders = [(1, 2)]\n", "# test_orders = [(3, 1), (2, 2)]\n", "test_statistics = {}\n", "\n", @@ -293,6 +294,16 @@ "outputs": [], "source": [] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data_ts, toy_ts = tdict[\"data\"][tlabel], tdict[\"toys\"][tlabel]\n", + "plot_tests(data_ts, toy_ts, \"gof\" + tlabel, fit=\"chi2\", bins=20)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/src/HHbbVV/combine/run_blinded.sh b/src/HHbbVV/combine/run_blinded.sh index 015acd1c..4680a92c 100755 --- a/src/HHbbVV/combine/run_blinded.sh +++ b/src/HHbbVV/combine/run_blinded.sh @@ -12,6 +12,8 @@ # 7) GoF on toys (--goftoys / -t), # 8) Impacts: initial fit (--impactsinit / -i), per-nuisance fits (--impactsfits), collect (--impactscollect) # specify seed with --seed (default 42) and number of toys with --numtoys (default 100) +# 9) Bias test: run a bias test on toys (using post-fit nuisances) with expected signal strength +# given by --bias X. # # Specify resonant with --resonant / -r, otherwise does nonresonant # @@ -38,9 +40,9 @@ impactsfits=0 impactscollect=0 seed=42 numtoys=100 -biastest=0 +bias=-1 -options=$(getopt -o "wblsdrgti" --long "workspace,bfit,limits,significance,dfit,resonant,gofdata,goftoys,impactsinit,impactsfits,impactscollect,biastest,seed:,numtoys:" -- "$@") +options=$(getopt -o "wblsdrgti" --long "workspace,bfit,limits,significance,dfit,resonant,gofdata,goftoys,impactsinit,impactsfits,impactscollect,seed:,numtoys:,bias:" -- "$@") eval set -- "$options" while true; do @@ -78,9 +80,6 @@ while true; do --impactscollect) impactscollect=1 ;; - --biastest) - biastest=1 - ;; --seed) shift seed=$1 @@ -89,6 +88,10 @@ while true; do shift numtoys=$1 ;; + --bias) + shift + bias=$1 + ;; --) shift break;; @@ -261,7 +264,7 @@ if [ $dfit = 1 ]; then --setParameters ${maskunblindedargs},${setparamsblinded} \ --freezeParameters ${freezeparamsblinded} \ -n Blinded --ignoreCovWarning -v 9 2>&1 | tee $outsdir/FitDiagnostics.txt - # --saveShapes --saveNormalizations --saveWithUncertainties --saveOverallShapes \ + --saveShapes --saveNormalizations --saveWithUncertainties --saveOverallShapes \ echo "Fit Shapes" PostFitShapesFromWorkspace --dataset $dataset -w ${wsm}.root --output FitShapes.root \ @@ -319,17 +322,12 @@ if [ $impactscollect = 1 ]; then fi -if [ $biastest = 1 ]; then - echo "Bias tests" - # for bias in 0 0.15 0.3 1 - # do - # done - bias=0.3 +if [ $bias != -1 ]; then + echo "Bias test with bias $bias" combineTool.py -M FitDiagnostics --trackParameters r --trackErrors r --justFit \ - -m 125 -n "bias${bias}ggF" -d ${wsm_snapshot}.root --rMin "-20" --rMax 20 \ + -m 125 -n "bias${bias}" -d ${wsm_snapshot}.root --rMin "-20" --rMax 20 \ --snapshotName MultiDimFit --bypassFrequentistFit --toysFrequentist --expectSignal $bias \ ${unblindedparams} \ - --robustFit=1 -t 5 -s $seed -v 4 2>&1 | tee $outsdir/bias$bias.txt - # -s 1:10:1 --job-mode condor --task-name ggF$bias + --robustFit=1 -t $numtoys -s $seed -v 4 2>&1 | tee $outsdir/bias${bias}seed${seed}.txt fi diff --git a/src/HHbbVV/combine/submit/submit_bias.py b/src/HHbbVV/combine/submit/submit_bias.py new file mode 100644 index 00000000..58abdf1a --- /dev/null +++ b/src/HHbbVV/combine/submit/submit_bias.py @@ -0,0 +1,76 @@ +#!/usr/bin/python + +""" +Splits toy generation into separate condor jobs and fits lowest order + 1 models for F-tests. + +Author(s): Raghav Kansal +""" + +import argparse +import os +from math import ceil +from string import Template +import json + +import sys + +from utils import add_bool_arg, write_template, setup, parse_common_args + + +def main(args): + t2_local_prefix, t2_prefix, proxy, username, submitdir = setup(args) + + prefix = f"bias_{args.bias}_seed_{args.seed}" + local_dir = f"condor/bias/{args.tag}/{prefix}" + + # make local directory + logdir = local_dir + "/logs" + os.system(f"mkdir -p {logdir}") + + jdl_templ = f"{submitdir}/submit_bias.templ.jdl" + sh_templ = f"{submitdir}/submit_bias.templ.sh" + + # submit jobs + if args.submit: + print("Submitting jobs") + + for j in range(args.num_jobs): + localcondor = f"{local_dir}/{prefix}_{j}.jdl" + seed = args.seed + j * args.toys_per_job + jdl_args = { + "dir": local_dir, + "prefix": prefix, + "jobid": j, + "proxy": proxy, + "bias": args.bias, + "seed": seed, + } + write_template(jdl_templ, localcondor, jdl_args) + + localsh = f"{local_dir}/{prefix}_{j}.sh" + sh_args = { + "seed": seed, + "num_toys": args.toys_per_job, + "resonant": "--resonant" if args.resonant else "", + "bias": args.bias, + } + write_template(sh_templ, localsh, sh_args) + os.system(f"chmod u+x {localsh}") + + if os.path.exists(f"{localcondor}.log"): + os.system(f"rm {localcondor}.log") + + if args.submit: + os.system("condor_submit %s" % localcondor) + else: + print("To submit ", localcondor) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parse_common_args(parser) + parser.add_argument( + "--bias", help="expected signal strength to test", type=float, required=True + ) + args = parser.parse_args() + main(args) diff --git a/src/HHbbVV/combine/submit/submit_bias.templ.jdl b/src/HHbbVV/combine/submit/submit_bias.templ.jdl new file mode 100644 index 00000000..262061b0 --- /dev/null +++ b/src/HHbbVV/combine/submit/submit_bias.templ.jdl @@ -0,0 +1,16 @@ +#!/usr/bin/env condor_submit + +executable = $dir/${prefix}_$jobid.sh +should_transfer_files = YES +transfer_input_files = combined_withmasks.root,higgsCombineSnapshot.MultiDimFit.mH125.root,/uscms/home/rkansal/nobackup/HHbbVV/src/HHbbVV/combine/run_blinded.sh +transfer_output_files = higgsCombinebias${bias}.FitDiagnostics.mH125.$seed.root,outs/bias${bias}seed${seed}.txt +when_to_transfer_output = ON_EXIT_OR_EVICT +request_memory = 3000 +use_x509userproxy = true +x509userproxy = /uscms/home/rkansal/x509up_u57474 + +output = $dir/logs/${prefix}_$jobid.out +error = $dir/logs/${prefix}_$jobid.err +log = $dir/logs/${prefix}_$jobid.log + +Queue 1 \ No newline at end of file diff --git a/src/HHbbVV/combine/submit/submit_bias.templ.sh b/src/HHbbVV/combine/submit/submit_bias.templ.sh new file mode 100644 index 00000000..472d7819 --- /dev/null +++ b/src/HHbbVV/combine/submit/submit_bias.templ.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +#################################################################################################### +# Script for running bias test +# +# Author: Raghav Kansal +#################################################################################################### + +echo "Starting job on " `date` #Date/time of start of job +echo "Running on: `uname -a`" #Condor job is running on this node +echo "System software: `cat /etc/redhat-release`" #Operating System on that node + +#################################################################################################### +# Get my tarred CMSSW with combine already compiled +#################################################################################################### + +source /cvmfs/cms.cern.ch/cmsset_default.sh +xrdcp -s root://cmseos.fnal.gov//store/user/rkansal/CMSSW_11_2_0.tgz . + +echo "extracting tar" +tar -xf CMSSW_11_2_0.tgz +rm CMSSW_11_2_0.tgz +cd CMSSW_11_2_0/src/ +scramv1 b ProjectRename # this handles linking the already compiled code - do NOT recompile +eval `scramv1 runtime -sh` # cmsenv is an alias not on the workers +echo $CMSSW_BASE "is the CMSSW we have on the local worker node" +cd ../.. + +ls -lh +chmod u+x run_blinded.sh +./run_blinded.sh $resonant --bias $bias --seed $seed --numtoys $num_toys +ls -lh \ No newline at end of file diff --git a/src/HHbbVV/combine/submit.py b/src/HHbbVV/combine/submit/submit_cards.py similarity index 92% rename from src/HHbbVV/combine/submit.py rename to src/HHbbVV/combine/submit/submit_cards.py index 193b7b42..e730ecd0 100644 --- a/src/HHbbVV/combine/submit.py +++ b/src/HHbbVV/combine/submit/submit_cards.py @@ -14,6 +14,8 @@ import itertools import sys +from utils import add_bool_arg, write_template, setup, parse_common_args + def add_bool_arg(parser, name, help, default=False, no_name=None): """Add a boolean command line argument for argparse""" @@ -188,21 +190,8 @@ def write_template(templ_file: str, out_file: str, templ_args: dict): def main(args): global scan_txbb_wps, scan_thww_wps - if args.site == "lpc": - t2_local_prefix = "/eos/uscms/" - t2_prefix = "root://cmseos.fnal.gov" - - try: - proxy = os.environ["X509_USER_PROXY"] - except: - print("No valid proxy. Exiting.") - exit(1) - elif args.site == "ucsd": - t2_local_prefix = "/ceph/cms/" - t2_prefix = "root://redirector.t2.ucsd.edu:1095" - proxy = "/home/users/rkansal/x509up_u31735" - - username = os.environ["USER"] + t2_local_prefix, t2_prefix, proxy, username, submitdir = setup(args) + local_dir = f"condor/cards/{args.tag}" templates_dir = f"/store/user/{username}/bbVV/templates/{args.templates_dir}/" @@ -216,8 +205,8 @@ def main(args): os.system(f"mkdir -p {t2_local_prefix}/{cards_dir}") os.system(f"mkdir -p {t2_local_prefix}/{templates_dir}") - jdl_templ = "src/HHbbVV/combine/submit.templ.jdl" - sh_templ = "src/HHbbVV/combine/submit.templ.sh" + jdl_templ = f"{submitdir}/submit_cards.templ.jdl" + sh_templ = f"{submitdir}/submit_cards.templ.sh" samples = scan_samples if args.scan else full_samples diff --git a/src/HHbbVV/combine/submit.templ.jdl b/src/HHbbVV/combine/submit/submit_cards.templ.jdl similarity index 100% rename from src/HHbbVV/combine/submit.templ.jdl rename to src/HHbbVV/combine/submit/submit_cards.templ.jdl diff --git a/src/HHbbVV/combine/submit.templ.sh b/src/HHbbVV/combine/submit/submit_cards.templ.sh similarity index 100% rename from src/HHbbVV/combine/submit.templ.sh rename to src/HHbbVV/combine/submit/submit_cards.templ.sh diff --git a/src/HHbbVV/combine/submit_ftest.py b/src/HHbbVV/combine/submit/submit_ftest.py similarity index 85% rename from src/HHbbVV/combine/submit_ftest.py rename to src/HHbbVV/combine/submit/submit_ftest.py index 2048b7e0..f7784c4f 100644 --- a/src/HHbbVV/combine/submit_ftest.py +++ b/src/HHbbVV/combine/submit/submit_ftest.py @@ -11,9 +11,10 @@ from math import ceil from string import Template import json - import sys +from utils import add_bool_arg, write_template, setup, parse_common_args + def add_bool_arg(parser, name, help, default=False, no_name=None): """Add a boolean command line argument for argparse""" @@ -44,19 +45,7 @@ def write_template(templ_file: str, out_file: str, templ_args: dict): def main(args): - if args.site == "lpc": - t2_local_prefix = "/eos/uscms/" - t2_prefix = "root://cmseos.fnal.gov" - - try: - proxy = os.environ["X509_USER_PROXY"] - except: - print("No valid proxy. Exiting.") - exit(1) - elif args.site == "ucsd": - t2_local_prefix = "/ceph/cms/" - t2_prefix = "root://redirector.t2.ucsd.edu:1095" - proxy = "/home/users/rkansal/x509up_u31735" + t2_local_prefix, t2_prefix, proxy, username, submitdir = setup(args) username = os.environ["USER"] local_dir = f"condor/f_tests/{args.tag}_{args.low1}{args.low2}" @@ -69,11 +58,11 @@ def main(args): for i, j in [(0, 0), (0, 1), (1, 0)]: os.system( f"mkdir -p {t2_local_prefix}//store/user/rkansal/bbVV/cards/f_tests/{args.cards_tag}/" - f"nTF1_{args.low1 + i}_nTF2_{args.low2 + j}/" + f"nTF1_{args.low1 + i}_nTF2_{args.low2 + j}/outs/" ) - jdl_templ = "src/HHbbVV/combine/submit_ftest.templ.jdl" - sh_templ = "src/HHbbVV/combine/submit_ftest.templ.sh" + jdl_templ = f"{submitdir}/submit_ftest.templ.jdl" + sh_templ = f"{submitdir}/submit_ftest.templ.sh" # submit jobs if args.submit: diff --git a/src/HHbbVV/combine/submit_ftest.templ.jdl b/src/HHbbVV/combine/submit/submit_ftest.templ.jdl similarity index 100% rename from src/HHbbVV/combine/submit_ftest.templ.jdl rename to src/HHbbVV/combine/submit/submit_ftest.templ.jdl diff --git a/src/HHbbVV/combine/submit_ftest.templ.sh b/src/HHbbVV/combine/submit/submit_ftest.templ.sh similarity index 96% rename from src/HHbbVV/combine/submit_ftest.templ.sh rename to src/HHbbVV/combine/submit/submit_ftest.templ.sh index 2bb5aac4..6f648097 100644 --- a/src/HHbbVV/combine/submit_ftest.templ.sh +++ b/src/HHbbVV/combine/submit/submit_ftest.templ.sh @@ -85,6 +85,7 @@ freezeparams="rgx{pass_.*mcstat.*},rgx{fail_.*mcstat.*},rgx{.*xhy_mx.*}" model_name="nTF1_${low1}_nTF2_${low2}" toys_name="${low1}${low2}" cd ${cards_dir}/${model_name}/ +mkdir -p $outsdir ulimit -s unlimited @@ -118,6 +119,8 @@ do echo "GoF for $model_name" cd ${cards_dir}/${model_name}/ + mkdir -p $outsdir + ulimit -s unlimited combine -M GoodnessOfFit -d ${wsm_snapshot}.root --algo saturated -m 125 \ @@ -129,6 +132,9 @@ do xrdcp "higgsCombineToys${toys_name}Seed$seed.GoodnessOfFit.mH125.$seed.root" root://cmseos.fnal.gov//store/user/rkansal/bbVV/cards/f_tests/$tag/$model_name/ xrdcp $outsdir/GoF_toys${toys_name}$seed.txt root://cmseos.fnal.gov//store/user/rkansal/bbVV/cards/f_tests/$tag/$model_name/$outsdir/ + rm "higgsCombineToys${toys_name}Seed$seed.GoodnessOfFit.mH125.$seed.root" + rm "$outsdir/GoF_toys${toys_name}$seed.txt" + cd - done done \ No newline at end of file diff --git a/src/HHbbVV/combine/submit/utils.py b/src/HHbbVV/combine/submit/utils.py new file mode 100644 index 00000000..398d2037 --- /dev/null +++ b/src/HHbbVV/combine/submit/utils.py @@ -0,0 +1,69 @@ +import os +from string import Template +from pathlib import Path + + +def add_bool_arg(parser, name, help, default=False, no_name=None): + """Add a boolean command line argument for argparse""" + varname = "_".join(name.split("-")) # change hyphens to underscores + group = parser.add_mutually_exclusive_group(required=False) + group.add_argument("--" + name, dest=varname, action="store_true", help=help) + if no_name is None: + no_name = "no-" + name + no_help = "don't " + help + else: + no_help = help + group.add_argument("--" + no_name, dest=varname, action="store_false", help=no_help) + parser.set_defaults(**{varname: default}) + + +def write_template(templ_file: str, out_file: str, templ_args: dict): + """Write to ``out_file`` based on template from ``templ_file`` using ``templ_args``""" + + with open(templ_file, "r") as f: + templ = Template(f.read()) + + with open(out_file, "w") as f: + f.write( + templ.safe_substitute( + templ_args, + ) + ) + + +def setup(args): + if args.site == "lpc": + t2_local_prefix = "/eos/uscms/" + t2_prefix = "root://cmseos.fnal.gov" + + try: + proxy = os.environ["X509_USER_PROXY"] + except: + print("No valid proxy. Exiting.") + exit(1) + elif args.site == "ucsd": + t2_local_prefix = "/ceph/cms/" + t2_prefix = "root://redirector.t2.ucsd.edu:1095" + proxy = "/home/users/rkansal/x509up_u31735" + + username = os.environ["USER"] + submitdir = Path(__file__).resolve().parent + + return t2_local_prefix, t2_prefix, proxy, username, submitdir + + +def parse_common_args(parser): + parser.add_argument("--tag", default="Test", help="condor tag", type=str) + parser.add_argument("--cards-tag", default="Apr26", help="cards dir tag", type=str) + parser.add_argument( + "--site", + default="lpc", + help="computing cluster we're running this on", + type=str, + choices=["lpc", "ucsd"], + ) + parser.add_argument("--toys-per-job", default=100, help="# toys per condor job", type=int) + parser.add_argument("--num-jobs", default=10, help="# condor jobs", type=int) + parser.add_argument("--seed", default=444, help="# condor jobs", type=int) + add_bool_arg(parser, "submit", default=False, help="submit files as well as create them") + add_bool_arg(parser, "resonant", default=True, help="resonant or nonresonant") diff --git a/src/HHbbVV/postprocessing/PlotFits.ipynb b/src/HHbbVV/postprocessing/PlotFits.ipynb index f37d2521..4fd88b7f 100644 --- a/src/HHbbVV/postprocessing/PlotFits.ipynb +++ b/src/HHbbVV/postprocessing/PlotFits.ipynb @@ -40,7 +40,7 @@ "source": [ "MAIN_DIR = \"../../../\"\n", "\n", - "plot_dir = \"../../../plots/PostFit/23May16RemFeats/rem_feats_3/\"\n", + "plot_dir = \"../../../plots/PostFit/23Jul6\"\n", "_ = os.system(f\"mkdir -p {plot_dir}\")" ] }, @@ -50,11 +50,10 @@ "metadata": {}, "outputs": [], "source": [ - "# cards_dir = \"f_tests/23May14HP\"\n", - "cards_dir = \"23May16RemFeats/rem_feats_3/\"\n", + "cards_dir = \"f_tests/23May14HP\"\n", "file = uproot.open(\n", - " f\"/uscms/home/rkansal/hhcombine/cards/{cards_dir}/FitShapes.root\"\n", - " # f\"/uscms/home/rkansal/eos/bbVV/cards/{cards_dir}/FitShapes.root\"\n", + " # f\"/uscms/home/rkansal/hhcombine/cards/{cards_dir}/FitShapes.root\"\n", + " f\"/uscms/home/rkansal/eos/bbVV/cards/{cards_dir}/FitShapes.root\"\n", ")" ] }, diff --git a/src/HHbbVV/postprocessing/PlotFitsRes.ipynb b/src/HHbbVV/postprocessing/PlotFitsRes.ipynb index b41b5829..26b0da4f 100644 --- a/src/HHbbVV/postprocessing/PlotFitsRes.ipynb +++ b/src/HHbbVV/postprocessing/PlotFitsRes.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -40,21 +40,23 @@ "source": [ "MAIN_DIR = \"../../../\"\n", "\n", - "plot_dir = \"../../../plots/PostFit/23May3_21\"\n", + "plot_dir = f\"{MAIN_DIR}/plots/PostFit/23Jul6\"\n", "_ = os.system(f\"mkdir -p {plot_dir}\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "cards_dir = \"f_tests/23May2/nTF1_2_nTF2_1\"\n", - "# cards_dir = \"23May1Scan/txbb_HP_thww_0.8/NMSSM_XToYHTo2W2BTo4Q2B_MX-3000_MY-250/\"\n", + "# cards_dir = \"f_tests/23May2/nTF1_2_nTF2_1\"\n", + "cards_dir = \"f_tests/Apr26/nTF1_2_nTF2_1\"\n", + "# cards_dir = \"23May1Scan/txbb_HP_thww_0.6/NMSSM_XToYHTo2W2BTo4Q2B_MX-3000_MY-250\"\n", "file = uproot.open(\n", - " f\"/uscms/home/rkansal/hhcombine/cards/{cards_dir}/FitShapes.root\"\n", + " # f\"/uscms/home/rkansal/hhcombine/cards/{cards_dir}/FitShapes.root\"\n", " # f\"/uscms/home/rkansal/eos/bbVV/cards/{cards_dir}/FitShapes.root\"\n", + " f\"/uscms/home/rkansal/eos/bbVV/cards/{cards_dir}/higgsCombinebias0.3toys.GenerateOnly.mH125.42.root\"\n", ")" ] }, @@ -160,7 +162,7 @@ "metadata": {}, "outputs": [], "source": [ - "pass_ylim = 300\n", + "pass_ylim = 1000\n", "fail_ylim = 170000\n", "for shape, shape_label in shapes.items():\n", " for region, region_label in selection_regions.items():\n", @@ -231,7 +233,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.9.15" }, "orig_nbformat": 4, "vscode": {