From d709981f1b39c1a9c8a82057d78c6846268780dd Mon Sep 17 00:00:00 2001 From: rkansal47 Date: Thu, 14 Mar 2024 18:07:11 -0500 Subject: [PATCH] vbf kinematics notebook --- .../VBF_binder/VBFKinematicsStudy.ipynb | 228 ++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 src/HHbbVV/VBF_binder/VBFKinematicsStudy.ipynb diff --git a/src/HHbbVV/VBF_binder/VBFKinematicsStudy.ipynb b/src/HHbbVV/VBF_binder/VBFKinematicsStudy.ipynb new file mode 100644 index 00000000..7ae8b0d5 --- /dev/null +++ b/src/HHbbVV/VBF_binder/VBFKinematicsStudy.ipynb @@ -0,0 +1,228 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "7b82bb87", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "import mplhep as hep\n", + "import matplotlib.ticker as mticker\n", + "import numpy as np\n", + "\n", + "import uproot\n", + "import awkward as ak\n", + "from coffea import nanoevents\n", + "\n", + "from coffea.nanoevents.methods.base import NanoEventsArray\n", + "from coffea.analysis_tools import Weights, PackedSelection\n", + "from coffea.nanoevents.methods import nanoaod\n", + "from coffea.nanoevents.methods import vector\n", + "from coffea.lookup_tools.dense_lookup import dense_lookup\n", + "\n", + "from HHbbVV.processors.utils import pad_val\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\": 24})" + ] + }, + { + "cell_type": "markdown", + "id": "09429b8f", + "metadata": {}, + "source": [ + "Look at single SM VBF HH signal NanoAOD file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42e7add7", + "metadata": {}, + "outputs": [], + "source": [ + "events = nanoevents.NanoEventsFactory.from_root(\n", + " \"root://cmseos.fnal.gov///store/user/lpcpfnano/cmantill/v2_3/2018/HH/VBF_HHTobbVV_CV_1_C2V_1_C3_1_TuneCP5_13TeV-madgraph-pythia8/VBF_HHTobbVV_CV_1_C2V_1_C3_1/220808_150149/0000/nano_mc2018_1-1.root\",\n", + " schemaclass=nanoevents.NanoAODSchema,\n", + ").events()\n", + "\n", + "Z_PDGID = 23\n", + "W_PDGID = 24\n", + "HIGGS_PDGID = 25\n", + "GEN_FLAGS = [\"fromHardProcess\", \"isLastCopy\"]" + ] + }, + { + "cell_type": "markdown", + "id": "7f076483", + "metadata": {}, + "source": [ + "Get generator-level Higgs and Vs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1dfff6ce", + "metadata": {}, + "outputs": [], + "source": [ + "higgs = events.GenPart[\n", + " (abs(events.GenPart.pdgId) == HIGGS_PDGID) * events.GenPart.hasFlags(GEN_FLAGS)\n", + "]\n", + "\n", + "vs = events.GenPart[((abs(events.GenPart.pdgId) == 24)) * events.GenPart.hasFlags(GEN_FLAGS)]" + ] + }, + { + "cell_type": "markdown", + "id": "398dfc82", + "metadata": {}, + "source": [ + "Reproduce AK4 jet selections from skimmer" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "748e3109", + "metadata": {}, + "outputs": [], + "source": [ + "ak4_jet_selection = { # noqa: RUF012\n", + " \"pt\": 25,\n", + " \"eta\": 2.7,\n", + " \"jetId\": \"tight\",\n", + " \"puId\": \"medium\",\n", + " \"dR_fatjetbb\": 1.2,\n", + " \"dR_fatjetVV\": 0.8,\n", + "}\n", + "\n", + "# ak8 jet preselection\n", + "preselection = { # noqa: RUF012\n", + " \"pt\": 300.0,\n", + " \"eta\": 2.4,\n", + " \"VVmsd\": 50,\n", + " # \"VVparticleNet_mass\": [50, 250],\n", + " # \"bbparticleNet_mass\": [92.5, 162.5],\n", + " \"bbparticleNet_mass\": 50,\n", + " \"VVparticleNet_mass\": 50,\n", + " \"bbFatJetParticleNetMD_Txbb\": 0.8,\n", + " \"jetId\": 2, # tight ID bit\n", + " \"DijetMass\": 800, # TODO\n", + " # \"nGoodElectrons\": 0,\n", + "}\n", + "\n", + "num_jets = 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7b03b61b", + "metadata": {}, + "outputs": [], + "source": [ + "fatjets = events.FatJet\n", + "\n", + "# particlenet xbb vs qcd\n", + "\n", + "txbb = pad_val(\n", + " fatjets.particleNetMD_Xbb / (fatjets.particleNetMD_QCD + fatjets.particleNetMD_Xbb),\n", + " num_jets,\n", + " axis=1,\n", + ")\n", + "\n", + "# bb VV assignment\n", + "\n", + "bb_mask = txbb[:, 0] >= txbb[:, 1]\n", + "bb_mask = np.stack((bb_mask, ~bb_mask)).T" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "629523e9", + "metadata": {}, + "outputs": [], + "source": [ + "jets = events.Jet\n", + "\n", + "# dR_fatjetVV = 0.8 used from last two cells of VBFgenInfoTests.ipynb with data generated from SM signal vbf\n", + "# https://github.com/rkansal47/HHbbVV/blob/vbf_systematics/src/HHbbVV/VBF_binder/VBFgenInfoTests.ipynb\n", + "# (0-14R1R2study.parquet) has columns of different nGoodVBFJets corresponding to R1 and R2 cuts\n", + "vbf_jet_mask = (\n", + " jets.isTight\n", + " & (jets.pt > ak4_jet_selection[\"pt\"])\n", + " & (np.abs(jets.eta) < 4.7)\n", + " # medium puId https://twiki.cern.ch/twiki/bin/viewauth/CMS/PileupJetIDUL\n", + " & ((jets.pt > 50) | ((jets.puId & 2) == 2))\n", + " & (\n", + " ak.all(\n", + " jets.metric_table(\n", + " ak.singletons(ak.pad_none(fatjets, num_jets, axis=1, clip=True)[bb_mask])\n", + " )\n", + " > ak4_jet_selection[\"dR_fatjetbb\"],\n", + " axis=-1,\n", + " )\n", + " )\n", + " & (\n", + " ak.all(\n", + " jets.metric_table(\n", + " ak.singletons(ak.pad_none(fatjets, num_jets, axis=1, clip=True)[~bb_mask])\n", + " )\n", + " > ak4_jet_selection[\"dR_fatjetVV\"],\n", + " axis=-1,\n", + " )\n", + " )\n", + ")\n", + "\n", + "vbf_jets = jets[vbf_jet_mask]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d2998910", + "metadata": {}, + "outputs": [], + "source": [ + "etas = pad_val(vbf_jets.eta, 2, axis=1)\n", + "\n", + "plt.rcParams.update({\"font.size\": 24})\n", + "plt.figure(figsize=(12, 12))\n", + "plt.hist(np.abs(etas[:, 0] - etas[:, 1]), np.arange(0, 6, 0.25), histtype=\"step\", density=True)\n", + "plt.xlabel(r\"$\\eta_{jj}$\")\n", + "plt.ylabel(\"Events (A. U.)\")\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}