{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Welcome to JupyROOT 6.24/00\n" ] } ], "source": [ "import ROOT" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#ROOT.ROOT.DisableImplicitMT()\n", "#ROOT.ROOT.EnableImplicitMT(4)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ROOT.gInterpreter.Declare('#include \"df103_NanoAODHiggsAnalysis_python.h\"')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def selection_4mu(df):\n", " \"\"\"Select interesting events with four muons\"\"\"\n", " df_ge4m = df.Filter(\"nMuon==4\", \"Exactly four muons\")\n", " \n", " df_kin = df_ge4m.Filter(\"All(Muon_pt>5) && All(abs(Muon_eta)<2.4)\", \"Good muon kinematics\")\n", " df_2p2n = df_kin.Filter(\"Sum(Muon_charge)==0\",\n", " \"Two positive and two negative muons\")\n", " \n", " return df_2p2n\n", "\n", "def filter_z_candidates(df):\n", " \"\"\"Apply selection on reconstructed Z candidates\"\"\"\n", " df_z1_cut = df.Filter(\"Z_mass[0] > 40 && Z_mass[0] < 120\", \"Mass of first Z candidate in [40, 120]\")\n", " df_z2_cut = df_z1_cut.Filter(\"Z_mass[1] > 12 && Z_mass[1] < 120\", \"Mass of second Z candidate in [12, 120]\")\n", " return df_z2_cut\n", "\n", "def reco_higgs_to_4mu(df):\n", " \"\"\"Reconstruct Higgs from four muons\"\"\"\n", " # Filter interesting events\n", " df_base = selection_4mu(df)\n", " \n", " # Reconstruct Z systems\n", " df_z_idx = df_base.Define(\"Z_idx\", \"reco_zz_to_4l(Muon_pt, Muon_eta, Muon_phi, Muon_mass, Muon_charge)\")\n", " \n", " # Cut on distance between muons building Z systems\n", " df_z_dr = df_z_idx.Filter(\"filter_z_dr(Z_idx, Muon_eta, Muon_phi)\", \"Delta R separation of muons building Z system\")\n", " \n", " # Compute masses of Z systems\n", " df_z_mass = df_z_dr.Define(\"Z_mass\", \"compute_z_masses_4l(Z_idx, Muon_pt, Muon_eta, Muon_phi, Muon_mass)\")\n", " \n", " # Cut on mass of Z candidates\n", " df_z_cut = filter_z_candidates(df_z_mass)\n", " \n", " # Reconstruct H mass\n", " df_h_mass = df_z_cut.Define(\"H_mass\", \"compute_higgs_mass_4l(Z_idx, Muon_pt, Muon_eta, Muon_phi, Muon_mass)\")\n", " \n", " return df_h_mass" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "df_bkg_4mu = ROOT.RDataFrame(\"Events\", \"./Run2012BC_DoubleMuParked_Muons.root\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "df_bkg_4mu_reco = reco_higgs_to_4mu(df_bkg_4mu)\n", "\n", "df_h_bkg_4mu = df_bkg_4mu_reco.Histo1D((\"h_bkg_4mu\", \"\", 36, 70, 180), \"H_mass\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 37.2 s, sys: 502 ms, total: 37.7 s\n", "Wall time: 37.2 s\n" ] }, { "data": { "text/plain": [ "<cppyy.gbl.TH1D object at 0xb26b6b0>" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time df_h_bkg_4mu.GetValue()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "<div id=\"root_plot_1631298697945\"\n", " style=\"width: 696px; height: 472px\">\n", "</div>\n", "<script>\n", "if (typeof require !== 'undefined') {\n", "\n", " // We are in jupyter notebooks, use require.js which should be configured already\n", " require(['scripts/JSRoot.core'],\n", " function(Core) {\n", " display_root_plot_1631298697945(Core);\n", " }\n", " );\n", "\n", "} else if (typeof JSROOT !== 'undefined') {\n", "\n", " // JSROOT already loaded, just use it\n", " display_root_plot_1631298697945(JSROOT);\n", "\n", "} else {\n", "\n", " // We are in jupyterlab without require.js, directly loading jsroot\n", " // Jupyterlab might be installed in a different base_url so we need to know it.\n", " try {\n", " var base_url = JSON.parse(document.getElementById('jupyter-config-data').innerHTML).baseUrl;\n", " } catch(_) {\n", " var base_url = '/';\n", " }\n", "\n", " // Try loading a local version of requirejs and fallback to cdn if not possible.\n", " script_load(base_url + 'static/scripts/JSRoot.core.js', script_success, function(){\n", " console.error('Fail to load JSROOT locally, please check your jupyter_notebook_config.py file')\n", " script_load('https://root.cern/js/5.9.0/scripts/JSRootCore.min.js', script_success, function(){\n", " document.getElementById(\"root_plot_1631298697945\").innerHTML = \"Failed to load JSROOT\";\n", " });\n", " });\n", "}\n", "\n", "function script_load(src, on_load, on_error) {\n", " var script = document.createElement('script');\n", " script.src = src;\n", " script.onload = on_load;\n", " script.onerror = on_error;\n", " document.head.appendChild(script);\n", "}\n", "\n", "function script_success() {\n", " display_root_plot_1631298697945(JSROOT);\n", "}\n", "\n", "function display_root_plot_1631298697945(Core) {\n", " var obj = Core.parse({\"_typename\":\"TCanvas\",\"fUniqueID\":0,\"fBits\":3342344,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":1,\"fFillColor\":0,\"fFillStyle\":1001,\"fLeftMargin\":0.1,\"fRightMargin\":0.1,\"fBottomMargin\":0.1,\"fTopMargin\":0.1,\"fXfile\":2,\"fYfile\":2,\"fAfile\":1,\"fXstat\":0.99,\"fYstat\":0.99,\"fAstat\":2,\"fFrameFillColor\":0,\"fFrameLineColor\":1,\"fFrameFillStyle\":1001,\"fFrameLineStyle\":1,\"fFrameLineWidth\":1,\"fFrameBorderSize\":1,\"fFrameBorderMode\":0,\"fX1\":56.2499989755451,\"fY1\":-276.114101158387,\"fX2\":193.750001024455,\"fY2\":4912.52660115839,\"fXtoAbsPixelk\":-284.727213298901,\"fXtoPixelk\":-284.727213298901,\"fXtoPixel\":5.06181810639121,\"fYtoAbsPixelk\":446.882516675989,\"fYtoPixelk\":446.882516675989,\"fYtoPixel\":-0.0909679484627347,\"fUtoAbsPixelk\":5e-5,\"fUtoPixelk\":5e-5,\"fUtoPixel\":696,\"fVtoAbsPixelk\":472.00005,\"fVtoPixelk\":472,\"fVtoPixel\":-472,\"fAbsPixeltoXk\":56.2499989755451,\"fPixeltoXk\":56.2499989755451,\"fPixeltoX\":0.197557474208204,\"fAbsPixeltoYk\":4912.52660115839,\"fPixeltoYk\":-276.114101158387,\"fPixeltoY\":-10.9928828438915,\"fXlowNDC\":0,\"fYlowNDC\":0,\"fXUpNDC\":1,\"fYUpNDC\":1,\"fWNDC\":1,\"fHNDC\":1,\"fAbsXlowNDC\":0,\"fAbsYlowNDC\":0,\"fAbsWNDC\":1,\"fAbsHNDC\":1,\"fUxmin\":70,\"fUymin\":242.75,\"fUxmax\":180,\"fUymax\":4393.6625,\"fTheta\":30,\"fPhi\":30,\"fAspectRatio\":0,\"fNumber\":0,\"fTickx\":0,\"fTicky\":0,\"fLogx\":0,\"fLogy\":0,\"fLogz\":0,\"fPadPaint\":0,\"fCrosshair\":0,\"fCrosshairPos\":0,\"fBorderSize\":2,\"fBorderMode\":0,\"fModified\":false,\"fGridx\":false,\"fGridy\":false,\"fAbsCoord\":false,\"fEditable\":true,\"fFixedAspectRatio\":false,\"fPrimitives\":{\"_typename\":\"TList\",\"name\":\"TList\",\"arr\":[{\"_typename\":\"TFrame\",\"fUniqueID\":0,\"fBits\":8,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":1,\"fFillColor\":0,\"fFillStyle\":1001,\"fX1\":70,\"fY1\":242.75,\"fX2\":180,\"fY2\":4393.6625,\"fBorderSize\":1,\"fBorderMode\":0},{\"_typename\":\"TH1D\",\"fUniqueID\":0,\"fBits\":8,\"fName\":\"h_bkg_4mu\",\"fTitle\":\"\",\"fLineColor\":602,\"fLineStyle\":1,\"fLineWidth\":1,\"fFillColor\":0,\"fFillStyle\":1001,\"fMarkerColor\":1,\"fMarkerStyle\":1,\"fMarkerSize\":1,\"fNcells\":38,\"fXaxis\":{\"_typename\":\"TAxis\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"xaxis\",\"fTitle\":\"\",\"fNdivisions\":510,\"fAxisColor\":1,\"fLabelColor\":1,\"fLabelFont\":42,\"fLabelOffset\":0.005,\"fLabelSize\":0.035,\"fTickLength\":0.03,\"fTitleOffset\":1,\"fTitleSize\":0.035,\"fTitleColor\":1,\"fTitleFont\":42,\"fNbins\":36,\"fXmin\":70,\"fXmax\":180,\"fXbins\":[],\"fFirst\":0,\"fLast\":0,\"fBits2\":0,\"fTimeDisplay\":false,\"fTimeFormat\":\"\",\"fLabels\":null,\"fModLabs\":null},\"fYaxis\":{\"_typename\":\"TAxis\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"yaxis\",\"fTitle\":\"\",\"fNdivisions\":510,\"fAxisColor\":1,\"fLabelColor\":1,\"fLabelFont\":42,\"fLabelOffset\":0.005,\"fLabelSize\":0.035,\"fTickLength\":0.03,\"fTitleOffset\":0,\"fTitleSize\":0.035,\"fTitleColor\":1,\"fTitleFont\":42,\"fNbins\":1,\"fXmin\":0,\"fXmax\":1,\"fXbins\":[],\"fFirst\":0,\"fLast\":0,\"fBits2\":0,\"fTimeDisplay\":false,\"fTimeFormat\":\"\",\"fLabels\":null,\"fModLabs\":null},\"fZaxis\":{\"_typename\":\"TAxis\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"zaxis\",\"fTitle\":\"\",\"fNdivisions\":510,\"fAxisColor\":1,\"fLabelColor\":1,\"fLabelFont\":42,\"fLabelOffset\":0.005,\"fLabelSize\":0.035,\"fTickLength\":0.03,\"fTitleOffset\":1,\"fTitleSize\":0.035,\"fTitleColor\":1,\"fTitleFont\":42,\"fNbins\":1,\"fXmin\":0,\"fXmax\":1,\"fXbins\":[],\"fFirst\":0,\"fLast\":0,\"fBits2\":0,\"fTimeDisplay\":false,\"fTimeFormat\":\"\",\"fLabels\":null,\"fModLabs\":null},\"fBarOffset\":0,\"fBarWidth\":1000,\"fEntries\":80485,\"fTsumw\":65807,\"fTsumw2\":65807,\"fTsumwx\":6884533.55869293,\"fTsumwx2\":769458663.236388,\"fMaximum\":-1111,\"fMinimum\":-1111,\"fNormFactor\":0,\"fContour\":[],\"fSumw2\":[],\"fOption\":\"\",\"fFunctions\":{\"_typename\":\"TList\",\"name\":\"TList\",\"arr\":[{\"_typename\":\"TPaveStats\",\"fUniqueID\":0,\"fBits\":9,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":1,\"fFillColor\":0,\"fFillStyle\":1001,\"fX1\":163.500002786517,\"fY1\":3745.08247406382,\"fX2\":191.000003606081,\"fY2\":4575.26496787848,\"fX1NDC\":0.780000016093254,\"fY1NDC\":0.775000005960464,\"fX2NDC\":0.980000019073486,\"fY2NDC\":0.935000002384186,\"fBorderSize\":1,\"fInit\":1,\"fShadowColor\":1,\"fCornerRadius\":0,\"fOption\":\"brNDC\",\"fName\":\"stats\",\"fTextAngle\":0,\"fTextSize\":0,\"fTextAlign\":12,\"fTextColor\":1,\"fTextFont\":42,\"fLabel\":\"\",\"fLongest\":18,\"fMargin\":0.05,\"fLines\":{\"_typename\":\"TList\",\"name\":\"TList\",\"arr\":[{\"_typename\":\"TLatex\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"\",\"fTitle\":\"h_bkg_4mu\",\"fTextAngle\":0,\"fTextSize\":0.0368,\"fTextAlign\":0,\"fTextColor\":0,\"fTextFont\":0,\"fX\":0,\"fY\":0,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":2,\"fLimitFactorSize\":3,\"fOriginSize\":0.0368000008165836},{\"_typename\":\"TLatex\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"\",\"fTitle\":\"Entries = 80485 \",\"fTextAngle\":0,\"fTextSize\":0,\"fTextAlign\":0,\"fTextColor\":0,\"fTextFont\":0,\"fX\":0,\"fY\":0,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":2,\"fLimitFactorSize\":3,\"fOriginSize\":0.04},{\"_typename\":\"TLatex\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"\",\"fTitle\":\"Mean = 104.6\",\"fTextAngle\":0,\"fTextSize\":0,\"fTextAlign\":0,\"fTextColor\":0,\"fTextFont\":0,\"fX\":0,\"fY\":0,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":2,\"fLimitFactorSize\":3,\"fOriginSize\":0.04},{\"_typename\":\"TLatex\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"\",\"fTitle\":\"Std Dev = 27.35\",\"fTextAngle\":0,\"fTextSize\":0,\"fTextAlign\":0,\"fTextColor\":0,\"fTextFont\":0,\"fX\":0,\"fY\":0,\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":2,\"fLimitFactorSize\":3,\"fOriginSize\":0.04}],\"opt\":[\"\",\"\",\"\",\"\"]},\"fOptFit\":0,\"fOptStat\":1111,\"fFitFormat\":\"5.4g\",\"fStatFormat\":\"6.4g\",\"fParent\":{\"$ref\":3}}],\"opt\":[\"brNDC\"]},\"fBufferSize\":0,\"fBuffer\":[],\"fBinStatErrOpt\":0,\"fStatOverflows\":2,\"fArray\":[9809,3991,4196,4168,4163,3854,3527,3274,3157,2662,2587,2415,2269,2095,1947,1779,1680,1577,1493,1387,1241,1352,1154,1128,1009,938,863,823,783,710,614,575,526,516,484,431,439,4869]},{\"_typename\":\"TStyle\",\"fUniqueID\":0,\"fBits\":0,\"fName\":\"Modern\",\"fTitle\":\"Modern Style\",\"fLineColor\":1,\"fLineStyle\":1,\"fLineWidth\":1,\"fFillColor\":19,\"fFillStyle\":1001,\"fMarkerColor\":1,\"fMarkerStyle\":1,\"fMarkerSize\":1,\"fTextAngle\":0,\"fTextSize\":0.05,\"fTextAlign\":11,\"fTextColor\":1,\"fTextFont\":62,\"fXaxis\":{\"_typename\":\"TAttAxis\",\"fNdivisions\":510,\"fAxisColor\":1,\"fLabelColor\":1,\"fLabelFont\":42,\"fLabelOffset\":0.005,\"fLabelSize\":0.035,\"fTickLength\":0.03,\"fTitleOffset\":1,\"fTitleSize\":0.035,\"fTitleColor\":1,\"fTitleFont\":42},\"fYaxis\":{\"_typename\":\"TAttAxis\",\"fNdivisions\":510,\"fAxisColor\":1,\"fLabelColor\":1,\"fLabelFont\":42,\"fLabelOffset\":0.005,\"fLabelSize\":0.035,\"fTickLength\":0.03,\"fTitleOffset\":0,\"fTitleSize\":0.035,\"fTitleColor\":1,\"fTitleFont\":42},\"fZaxis\":{\"_typename\":\"TAttAxis\",\"fNdivisions\":510,\"fAxisColor\":1,\"fLabelColor\":1,\"fLabelFont\":42,\"fLabelOffset\":0.005,\"fLabelSize\":0.035,\"fTickLength\":0.03,\"fTitleOffset\":1,\"fTitleSize\":0.035,\"fTitleColor\":1,\"fTitleFont\":42},\"fBarWidth\":1,\"fBarOffset\":0,\"fColorModelPS\":0,\"fDrawBorder\":0,\"fOptLogx\":0,\"fOptLogy\":0,\"fOptLogz\":0,\"fOptDate\":0,\"fOptStat\":1111,\"fOptTitle\":1,\"fOptFile\":0,\"fOptFit\":0,\"fShowEventStatus\":0,\"fShowEditor\":0,\"fShowToolBar\":0,\"fNumberContours\":20,\"fAttDate\":{\"_typename\":\"TAttText\",\"fTextAngle\":0,\"fTextSize\":0.025,\"fTextAlign\":11,\"fTextColor\":1,\"fTextFont\":62},\"fDateX\":0.01,\"fDateY\":0.01,\"fEndErrorSize\":2,\"fErrorX\":0.5,\"fFuncColor\":2,\"fFuncStyle\":1,\"fFuncWidth\":2,\"fGridColor\":0,\"fGridStyle\":3,\"fGridWidth\":1,\"fLegendBorderSize\":1,\"fLegendFillColor\":0,\"fLegendFont\":42,\"fLegendTextSize\":0,\"fHatchesLineWidth\":1,\"fHatchesSpacing\":1,\"fFrameFillColor\":0,\"fFrameLineColor\":1,\"fFrameFillStyle\":1001,\"fFrameLineStyle\":1,\"fFrameLineWidth\":1,\"fFrameBorderSize\":1,\"fFrameBorderMode\":0,\"fHistFillColor\":0,\"fHistLineColor\":602,\"fHistFillStyle\":1001,\"fHistLineStyle\":1,\"fHistLineWidth\":1,\"fHistMinimumZero\":false,\"fHistTopMargin\":0.05,\"fCanvasPreferGL\":false,\"fCanvasColor\":0,\"fCanvasBorderSize\":2,\"fCanvasBorderMode\":0,\"fCanvasDefH\":500,\"fCanvasDefW\":700,\"fCanvasDefX\":10,\"fCanvasDefY\":10,\"fPadColor\":0,\"fPadBorderSize\":2,\"fPadBorderMode\":0,\"fPadBottomMargin\":0.1,\"fPadTopMargin\":0.1,\"fPadLeftMargin\":0.1,\"fPadRightMargin\":0.1,\"fPadGridX\":false,\"fPadGridY\":false,\"fPadTickX\":0,\"fPadTickY\":0,\"fPaperSizeX\":20,\"fPaperSizeY\":26,\"fScreenFactor\":1,\"fStatColor\":0,\"fStatTextColor\":1,\"fStatBorderSize\":1,\"fStatFont\":42,\"fStatFontSize\":0,\"fStatStyle\":1001,\"fStatFormat\":\"6.4g\",\"fStatX\":0.98,\"fStatY\":0.935,\"fStatW\":0.2,\"fStatH\":0.16,\"fStripDecimals\":true,\"fTitleAlign\":23,\"fTitleColor\":0,\"fTitleTextColor\":1,\"fTitleBorderSize\":0,\"fTitleFont\":42,\"fTitleFontSize\":0.05,\"fTitleStyle\":0,\"fTitleX\":0.5,\"fTitleY\":0.995,\"fTitleW\":0,\"fTitleH\":0,\"fLegoInnerR\":0.5,\"fLineStyle\":[\"\",\" \",\" 12 12\",\" 4 8\",\" 12 16 4 16\",\" 20 12 4 12\",\" 20 12 4 12 4 12 4 12\",\" 20 20\",\" 20 12 4 12 4 12\",\" 80 20\",\" 80 40 4 40\",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \",\" \"],\"fHeaderPS\":\"\",\"fTitlePS\":\"\",\"fFitFormat\":\"5.4g\",\"fPaintTextFormat\":\"g\",\"fLineScalePS\":3,\"fJoinLinePS\":0,\"fCapLinePS\":0,\"fTimeOffset\":788918400,\"fImageScaling\":1}],\"opt\":[\"\",\"\",\"\"]},\"fExecs\":null,\"fName\":\"c1\",\"fTitle\":\"c1\",\"fNumPaletteColor\":0,\"fNextPaletteColor\":0,\"fDISPLAY\":\"$DISPLAY\",\"fDoubleBuffer\":0,\"fRetained\":true,\"fXsizeUser\":0,\"fYsizeUser\":0,\"fXsizeReal\":20,\"fYsizeReal\":14.28571,\"fWindowTopX\":0,\"fWindowTopY\":0,\"fWindowWidth\":0,\"fWindowHeight\":0,\"fCw\":696,\"fCh\":472,\"fCatt\":{\"_typename\":\"TAttCanvas\",\"fXBetween\":2,\"fYBetween\":2,\"fTitleFromTop\":1.2,\"fXdate\":0.2,\"fYdate\":0.3,\"fAdate\":1},\"kMoveOpaque\":true,\"kResizeOpaque\":true,\"fHighLightColor\":2,\"fBatch\":true,\"kShowEventStatus\":false,\"kAutoExec\":true,\"kMenuBar\":true});\n", " Core.settings.HandleKeys = false;\n", " Core.draw(\"root_plot_1631298697945\", obj, \"\");\n", "}\n", "</script>\n" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "C1 = ROOT.TCanvas()\n", "df_h_bkg_4mu.Draw()\n", "C1.Draw()" ] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Python 3", "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.8.6" } }, "nbformat": 4, "nbformat_minor": 5 }