Standard Profile Inspector Demo

Standard demo of the ProfileInspector class StandardProfileInspectorDemo

This is a standard demo that can be used with any ROOT file prepared in the standard way. You specify:

  • name for input ROOT file
  • name of workspace inside ROOT file that holds model and data
  • name of ModelConfig that specifies details for calculator tools
  • name of dataset

With default parameters the macro will attempt to run the standard hist2workspace example and read the ROOT file that it produces.

The actual heart of the demo is only about 10 lines long.

The ProfileInspector plots the conditional maximum likelihood estimate of each nuisance parameter in the model vs. the parameter of interest. (aka. profiled value of nuisance parameter vs. parameter of interest) (aka. best fit nuisance parameter with p.o.i fixed vs. parameter of interest)

Author: Kyle Cranmer
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, February 24, 2020 at 03:34 AM.

In [1]:
%%cpp -d
#include "TFile.h"
#include "TROOT.h"
#include "TCanvas.h"
#include "TList.h"
#include "TMath.h"
#include "TSystem.h"
#include "RooWorkspace.h"
#include "RooAbsData.h"

#include "RooStats/ModelConfig.h"
#include "RooStats/ProfileInspector.h"
In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;
using namespace RooStats;

Arguments are defined.

In [3]:
const char *infile = "";
const char *workspaceName = "combined";
const char *modelConfigName = "ModelConfig";
const char *dataName = "obsData";

First part is just to access a user-defined file or create the standard example file if it doesn't exist

In [4]:
const char *filename = "";
if (!strcmp(infile, "")) {
   filename = "results/example_combined_GaussExample_model.root";
   bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
   // if file does not exists generate with histfactory
   if (!fileExist) {
#ifdef _WIN32
      cout << "HistFactory file cannot be generated on Windows - exit" << endl;
      return;
#endif
      // Normally this would be run on the command line
      cout << "will run standard hist2workspace example" << endl;
      gROOT->ProcessLine(".! prepareHistFactory .");
      gROOT->ProcessLine(".! hist2workspace config/example.xml");
      cout << "\n\n---------------------" << endl;
      cout << "Done creating example input" << endl;
      cout << "---------------------\n\n" << endl;
   }

} else
   filename = infile;

Try to open the file

In [5]:
TFile *file = TFile::Open(filename);
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

If input file was specified byt not found, quit

In [6]:
if (!file) {
   cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
   return;
}

Tutorial starts here

Get the workspace out of the file

In [7]:
RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
if (!w) {
   cout << "workspace not found" << endl;
   return;
}

Get the modelconfig out of the file

In [8]:
ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);

Get the modelconfig out of the file

In [9]:
RooAbsData *data = w->data(dataName);

Make sure ingredients are found

In [10]:
if (!data || !mc) {
   w->Print();
   cout << "data or ModelConfig was not found" << endl;
   return;
}

now use the profile inspector

In [11]:
ProfileInspector p;
TList *list = p.GetListOfProfilePlots(*data, mc);
[#1] INFO:Minization -- p.d.f. provides expected number of events, including extended term in likelihood.
[#1] INFO:Minization -- createNLL: caching constraint set under name CONSTR_OF_PDF_simPdf_FOR_OBS_channelCat:obs_x_channel1 with 6 entries
[#1] INFO:Minization --  Including the following constraint terms in minimization: (lumiConstraint,alpha_syst1Constraint,alpha_syst2Constraint,alpha_syst3Constraint,gamma_stat_channel1_bin_0_constraint,gamma_stat_channel1_bin_1_constraint)
[#1] INFO:Minization -- RooProfileLL::evaluate(nll_simPdf_obsData_with_constr_Profile[SigXsecOverSM]) Creating instance of MINUIT
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_simPdf_obsData_with_constr) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minization -- RooProfileLL::evaluate(nll_simPdf_obsData_with_constr_Profile[SigXsecOverSM]) determining minimum likelihood for current configurations w.r.t all observable
RooAbsTestStatistic::initSimMode: creating slave calculator #0 for state channel1 (2 dataset entries)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel1_model_Int[obs_x_channel1]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel1)
[#1] INFO:Fitting -- RooAbsTestStatistic::initSimMode: created 1 slave calculators.
[#1] INFO:NumericIntegration -- RooRealIntegral::init(channel1_model_Int[obs_x_channel1]) using numeric integrator RooBinIntegrator to calculate Int(obs_x_channel1)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gamma_stat_channel1_bin_0_constraint_Int[gamma_stat_channel1_bin_0]) using numeric integrator RooIntegrator1D to calculate Int(gamma_stat_channel1_bin_0)
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gamma_stat_channel1_bin_1_constraint_Int[gamma_stat_channel1_bin_1]) using numeric integrator RooIntegrator1D to calculate Int(gamma_stat_channel1_bin_1)
[#1] INFO:Minization -- RooProfileLL::evaluate(nll_simPdf_obsData_with_constr_Profile[SigXsecOverSM]) minimum found at (SigXsecOverSM=1.11601)
....................................................................................................

Now make plots

In [12]:
TCanvas *c1 = new TCanvas("c1", "ProfileInspectorDemo", 800, 200);
if (list->GetSize() > 4) {
   double n = list->GetSize();
   int nx = (int)sqrt(n);
   int ny = TMath::CeilNint(n / nx);
   nx = TMath::CeilNint(sqrt(n));
   c1->Divide(ny, nx);
} else
   c1->Divide(list->GetSize());
for (int i = 0; i < list->GetSize(); ++i) {
   c1->cd(i + 1);
   list->At(i)->Draw("al");
}

cout << endl;
input_line_199:3:5: error: reference to 'list' is ambiguous
if (list->GetSize() > 4) {
    ^
input_line_179:3:8: note: candidate found by name lookup is '__cling_N527::list'
TList *list = p.GetListOfProfilePlots(*data, mc);
       ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: candidate found by name lookup is 'std::__cxx11::list'
    class list : protected _List_base<_Tp, _Alloc>
          ^
input_line_199:3:5: error: use of class template 'list' requires template arguments
if (list->GetSize() > 4) {
    ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: template is declared here
    class list : protected _List_base<_Tp, _Alloc>
          ^
input_line_199:3:9: error: cannot use arrow operator on a type
if (list->GetSize() > 4) {
        ^
input_line_199:4:15: error: reference to 'list' is ambiguous
   double n = list->GetSize();
              ^
input_line_179:3:8: note: candidate found by name lookup is '__cling_N527::list'
TList *list = p.GetListOfProfilePlots(*data, mc);
       ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: candidate found by name lookup is 'std::__cxx11::list'
    class list : protected _List_base<_Tp, _Alloc>
          ^
input_line_199:10:15: error: reference to 'list' is ambiguous
   c1->Divide(list->GetSize());
              ^
input_line_179:3:8: note: candidate found by name lookup is '__cling_N527::list'
TList *list = p.GetListOfProfilePlots(*data, mc);
       ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: candidate found by name lookup is 'std::__cxx11::list'
    class list : protected _List_base<_Tp, _Alloc>
          ^
input_line_199:11:21: error: reference to 'list' is ambiguous
for (int i = 0; i < list->GetSize(); ++i) {
                    ^
input_line_179:3:8: note: candidate found by name lookup is '__cling_N527::list'
TList *list = p.GetListOfProfilePlots(*data, mc);
       ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: candidate found by name lookup is 'std::__cxx11::list'
    class list : protected _List_base<_Tp, _Alloc>
          ^
input_line_199:11:21: error: reference to 'list' is ambiguous
for (int i = 0; i < list->GetSize(); ++i) {
                    ^
input_line_179:3:8: note: candidate found by name lookup is '__cling_N527::list'
TList *list = p.GetListOfProfilePlots(*data, mc);
       ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: candidate found by name lookup is 'std::__cxx11::list'
    class list : protected _List_base<_Tp, _Alloc>
          ^
input_line_199:13:4: error: reference to 'list' is ambiguous
   list->At(i)->Draw("al");
   ^
input_line_179:3:8: note: candidate found by name lookup is '__cling_N527::list'
TList *list = p.GetListOfProfilePlots(*data, mc);
       ^
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/stl_list.h:564:11: note: candidate found by name lookup is 'std::__cxx11::list'
    class list : protected _List_base<_Tp, _Alloc>
          ^

Draw all canvases

In [13]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()