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:
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, May 29, 2023 at 09:33 AM.
%%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"
using namespace RooFit;
using namespace RooStats;
Arguments are defined.
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
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) {
// 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
TFile *file = TFile::Open(filename);
if input file was specified byt not found, quit
if (!file) {
cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
return;
}
get the workspace out of the file
RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
if (!w) {
cout << "workspace not found" << endl;
return;
}
get the modelConfig out of the file
ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
get the modelConfig out of the file
RooAbsData *data = w->data(dataName);
input_line_87:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration RooAbsData *data = w->data(dataName); ^
make sure ingredients are found
if (!data || !mc) {
w->Print();
cout << "data or ModelConfig was not found" << endl;
return;
}
input_line_88:2:7: error: reference to 'data' is ambiguous if (!data || !mc) { ^ input_line_87:2:14: note: candidate found by name lookup is 'data' RooAbsData *data = w->data(dataName); ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^
now use the profile inspector
ProfileInspector p;
TList *list = p.GetListOfProfilePlots(*data, mc);
input_line_89:3:40: error: reference to 'data' is ambiguous TList *list = p.GetListOfProfilePlots(*data, mc); ^ input_line_87:2:14: note: candidate found by name lookup is 'data' RooAbsData *data = w->data(dataName); ^ /usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data' data(initializer_list<_Tp> __il) noexcept ^ /usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data' data(_Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data' data(const _Container& __cont) noexcept(noexcept(__cont.data())) ^ /usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data' data(_Tp (&__array)[_Nm]) noexcept ^ input_line_89:3:1: warning: 'list' shadows a declaration with the same name in the 'std' namespace; use '::list' to reference this declaration TList *list = p.GetListOfProfilePlots(*data, mc); ^
now make plots
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_90:3:9: error: cannot use arrow operator on a type if (list->GetSize() > 4) { ^ input_line_90:4:15: error: use of class template 'list' requires template arguments double n = list->GetSize(); ^ /usr/include/c++/9/bits/stl_list.h:552:11: note: template is declared here class list : protected _List_base<_Tp, _Alloc> ^ input_line_90:10:15: error: use of class template 'list' requires template arguments c1->Divide(list->GetSize()); ^ /usr/include/c++/9/bits/stl_list.h:552:11: note: template is declared here class list : protected _List_base<_Tp, _Alloc> ^ input_line_90:11:25: error: expected '(' for function-style cast or type construction for (int i = 0; i < list->GetSize(); ++i) { ~~~~^ input_line_90:13:8: error: cannot use arrow operator on a type list->At(i)->Draw("al"); ^
Draw all canvases
%jsroot on
gROOT->GetListOfCanvases()->Draw()