{ "cells": [ { "cell_type": "markdown", "id": "64cc14dd", "metadata": {}, "source": [ "# StandardProfileInspectorDemo\n", "Standard demo of the ProfileInspector class\n", "StandardProfileInspectorDemo\n", "\n", "This is a standard demo that can be used with any ROOT file\n", "prepared in the standard way. You specify:\n", " - name for input ROOT file\n", " - name of workspace inside ROOT file that holds model and data\n", " - name of ModelConfig that specifies details for calculator tools\n", " - name of dataset\n", "\n", "With default parameters the macro will attempt to run the\n", "standard hist2workspace example and read the ROOT file\n", "that it produces.\n", "\n", "The actual heart of the demo is only about 10 lines long.\n", "\n", "The ProfileInspector plots the conditional maximum likelihood estimate\n", "of each nuisance parameter in the model vs. the parameter of interest.\n", "(aka. profiled value of nuisance parameter vs. parameter of interest)\n", "(aka. best fit nuisance parameter with p.o.i fixed vs. parameter of interest)\n", "\n", "\n", "\n", "\n", "**Author:** Kyle Cranmer \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:36 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "a46376e1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:28.553447Z", "iopub.status.busy": "2026-05-19T20:36:28.553333Z", "iopub.status.idle": "2026-05-19T20:36:28.569612Z", "shell.execute_reply": "2026-05-19T20:36:28.568983Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"TFile.h\"\n", "#include \"TROOT.h\"\n", "#include \"TCanvas.h\"\n", "#include \"TList.h\"\n", "#include \"TMath.h\"\n", "#include \"TSystem.h\"\n", "#include \"RooWorkspace.h\"\n", "#include \"RooAbsData.h\"\n", "\n", "#include \"RooStats/ModelConfig.h\"\n", "#include \"RooStats/ProfileInspector.h\"\n", "\n", "using namespace RooFit;\n", "using namespace RooStats;" ] }, { "cell_type": "markdown", "id": "692c242c", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 2, "id": "d20256cf", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:28.571152Z", "iopub.status.busy": "2026-05-19T20:36:28.571038Z", "iopub.status.idle": "2026-05-19T20:36:28.924652Z", "shell.execute_reply": "2026-05-19T20:36:28.917416Z" } }, "outputs": [], "source": [ "const char *infile = \"\";\n", "const char *workspaceName = \"combined\";\n", "const char *modelConfigName = \"ModelConfig\";\n", "const char *dataName = \"obsData\";" ] }, { "cell_type": "markdown", "id": "45c2c28a", "metadata": {}, "source": [ "-------------------------------------------------------\n", "First part is just to access a user-defined file\n", "or create the standard example file if it doesn't exist" ] }, { "cell_type": "code", "execution_count": 3, "id": "667d890d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:28.926687Z", "iopub.status.busy": "2026-05-19T20:36:28.926491Z", "iopub.status.idle": "2026-05-19T20:36:29.271148Z", "shell.execute_reply": "2026-05-19T20:36:29.264383Z" } }, "outputs": [], "source": [ "const char *filename = \"\";\n", "if (!strcmp(infile, \"\")) {\n", " filename = \"results/example_combined_GaussExample_model.root\";\n", " bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code\n", " // if file does not exists generate with histfactory\n", " if (!fileExist) {\n", " // Normally this would be run on the command line\n", " cout << \"will run standard hist2workspace example\" << endl;\n", " gROOT->ProcessLine(\".! prepareHistFactory .\");\n", " gROOT->ProcessLine(\".! hist2workspace config/example.xml\");\n", " cout << \"\\n\\n---------------------\" << endl;\n", " cout << \"Done creating example input\" << endl;\n", " cout << \"---------------------\\n\\n\" << endl;\n", " }\n", "\n", "} else\n", " filename = infile;\n", "\n", "TFile *file = TFile::Open(filename);" ] }, { "cell_type": "markdown", "id": "f8626efa", "metadata": {}, "source": [ "-------------------------------------------------------\n", "Tutorial starts here\n", "-------------------------------------------------------" ] }, { "cell_type": "markdown", "id": "c5b26a42", "metadata": {}, "source": [ "get the workspace out of the file" ] }, { "cell_type": "code", "execution_count": 4, "id": "4e58c01c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:29.277395Z", "iopub.status.busy": "2026-05-19T20:36:29.277256Z", "iopub.status.idle": "2026-05-19T20:36:29.658042Z", "shell.execute_reply": "2026-05-19T20:36:29.657634Z" } }, "outputs": [], "source": [ "RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);" ] }, { "cell_type": "markdown", "id": "5f87f89a", "metadata": {}, "source": [ "get the modelConfig out of the file" ] }, { "cell_type": "code", "execution_count": 5, "id": "f6c4382a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:29.659954Z", "iopub.status.busy": "2026-05-19T20:36:29.659817Z", "iopub.status.idle": "2026-05-19T20:36:29.869206Z", "shell.execute_reply": "2026-05-19T20:36:29.868710Z" } }, "outputs": [], "source": [ "ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);" ] }, { "cell_type": "markdown", "id": "6ada3274", "metadata": {}, "source": [ "get the modelConfig out of the file" ] }, { "cell_type": "code", "execution_count": 6, "id": "f5d61050", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:29.870637Z", "iopub.status.busy": "2026-05-19T20:36:29.870494Z", "iopub.status.idle": "2026-05-19T20:36:30.087923Z", "shell.execute_reply": "2026-05-19T20:36:30.082260Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_74:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration\n", " RooAbsData *data = w->data(dataName);\n", " ^\n" ] } ], "source": [ "RooAbsData *data = w->data(dataName);" ] }, { "cell_type": "markdown", "id": "570b4ce1", "metadata": {}, "source": [ "-----------------------------\n", "now use the profile inspector" ] }, { "cell_type": "code", "execution_count": 7, "id": "37bc9a3b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:30.094161Z", "iopub.status.busy": "2026-05-19T20:36:30.094022Z", "iopub.status.idle": "2026-05-19T20:36:30.307059Z", "shell.execute_reply": "2026-05-19T20:36:30.305404Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_75:3:40: error: reference to 'data' is ambiguous\n", "TList *list = p.GetListOfProfilePlots(*data, mc);\n", " ^\n", "input_line_74:2:14: note: candidate found by name lookup is 'data'\n", " RooAbsData *data = w->data(dataName);\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:344:5: note: candidate found by name lookup is 'std::data'\n", " data(initializer_list<_Tp> __il) noexcept\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:312:5: note: candidate found by name lookup is 'std::data'\n", " data(_Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:323:5: note: candidate found by name lookup is 'std::data'\n", " data(const _Container& __cont) noexcept(noexcept(__cont.data()))\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/range_access.h:334:5: note: candidate found by name lookup is 'std::data'\n", " data(_Tp (&__array)[_Nm]) noexcept\n", " ^\n", "input_line_75:3:1: warning: 'list' shadows a declaration with the same name in the 'std' namespace; use '::list' to reference this declaration\n", "TList *list = p.GetListOfProfilePlots(*data, mc);\n", "^\n" ] } ], "source": [ "ProfileInspector p;\n", "TList *list = p.GetListOfProfilePlots(*data, mc);" ] }, { "cell_type": "markdown", "id": "53aa84d0", "metadata": {}, "source": [ "now make plots" ] }, { "cell_type": "code", "execution_count": 8, "id": "5faad06b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:30.310237Z", "iopub.status.busy": "2026-05-19T20:36:30.310092Z", "iopub.status.idle": "2026-05-19T20:36:30.521886Z", "shell.execute_reply": "2026-05-19T20:36:30.521500Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_76:3:9: error: cannot use arrow operator on a type\n", "if (list->GetSize() > 4) {\n", " ^\n", "input_line_76:4:15: error: use of class template 'list' requires template arguments\n", " double n = list->GetSize();\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_list.h:633:11: note: template is declared here\n", " class list : protected _List_base<_Tp, _Alloc>\n", " ^\n", "input_line_76:10:15: error: use of class template 'list' requires template arguments\n", " c1->Divide(list->GetSize());\n", " ^\n", "/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_list.h:633:11: note: template is declared here\n", " class list : protected _List_base<_Tp, _Alloc>\n", " ^\n", "input_line_76:11:25: error: expected '(' for function-style cast or type construction\n", "for (int i = 0; i < list->GetSize(); ++i) {\n", " ~~~~^\n", "input_line_76:13:8: error: cannot use arrow operator on a type\n", " list->At(i)->Draw(\"al\");\n", " ^\n" ] } ], "source": [ "TCanvas *c1 = new TCanvas(\"c1\", \"ProfileInspectorDemo\", 800, 200);\n", "if (list->GetSize() > 4) {\n", " double n = list->GetSize();\n", " int nx = (int)sqrt(n);\n", " int ny = TMath::CeilNint(n / nx);\n", " nx = TMath::CeilNint(sqrt(n));\n", " c1->Divide(ny, nx);\n", "} else\n", " c1->Divide(list->GetSize());\n", "for (int i = 0; i < list->GetSize(); ++i) {\n", " c1->cd(i + 1);\n", " list->At(i)->Draw(\"al\");\n", "}\n", "\n", "cout << endl;" ] }, { "cell_type": "markdown", "id": "4c80b951", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 9, "id": "68de98a4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:30.543404Z", "iopub.status.busy": "2026-05-19T20:36:30.543255Z", "iopub.status.idle": "2026-05-19T20:36:30.776940Z", "shell.execute_reply": "2026-05-19T20:36:30.774984Z" } }, "outputs": [], "source": [ "%jsroot on\n", "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }