Logo ROOT  
Reference Guide
StandardProfileInspectorDemo.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roostats
3/// \notebook -js
4/// Standard demo of the ProfileInspector class
5/// StandardProfileInspectorDemo
6///
7/// This is a standard demo that can be used with any ROOT file
8/// prepared in the standard way. You specify:
9/// - name for input ROOT file
10/// - name of workspace inside ROOT file that holds model and data
11/// - name of ModelConfig that specifies details for calculator tools
12/// - name of dataset
13///
14/// With default parameters the macro will attempt to run the
15/// standard hist2workspace example and read the ROOT file
16/// that it produces.
17///
18/// The actual heart of the demo is only about 10 lines long.
19///
20/// The ProfileInspector plots the conditional maximum likelihood estimate
21/// of each nuisance parameter in the model vs. the parameter of interest.
22/// (aka. profiled value of nuisance parameter vs. parameter of interest)
23/// (aka. best fit nuisance parameter with p.o.i fixed vs. parameter of interest)
24///
25/// \macro_image
26/// \macro_output
27/// \macro_code
28///
29/// \author Kyle Cranmer
30
31#include "TFile.h"
32#include "TROOT.h"
33#include "TCanvas.h"
34#include "TList.h"
35#include "TMath.h"
36#include "TSystem.h"
37#include "RooWorkspace.h"
38#include "RooAbsData.h"
39
42
43using namespace RooFit;
44using namespace RooStats;
45
46void StandardProfileInspectorDemo(const char *infile = "", const char *workspaceName = "combined",
47 const char *modelConfigName = "ModelConfig", const char *dataName = "obsData")
48{
49
50 // -------------------------------------------------------
51 // First part is just to access a user-defined file
52 // or create the standard example file if it doesn't exist
53
54 const char *filename = "";
55 if (!strcmp(infile, "")) {
56 filename = "results/example_combined_GaussExample_model.root";
57 bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
58 // if file does not exists generate with histfactory
59 if (!fileExist) {
60#ifdef _WIN32
61 cout << "HistFactory file cannot be generated on Windows - exit" << endl;
62 return;
63#endif
64 // Normally this would be run on the command line
65 cout << "will run standard hist2workspace example" << endl;
66 gROOT->ProcessLine(".! prepareHistFactory .");
67 gROOT->ProcessLine(".! hist2workspace config/example.xml");
68 cout << "\n\n---------------------" << endl;
69 cout << "Done creating example input" << endl;
70 cout << "---------------------\n\n" << endl;
71 }
72
73 } else
74 filename = infile;
75
76 // Try to open the file
77 TFile *file = TFile::Open(filename);
78
79 // if input file was specified byt not found, quit
80 if (!file) {
81 cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
82 return;
83 }
84
85 // -------------------------------------------------------
86 // Tutorial starts here
87 // -------------------------------------------------------
88
89 // get the workspace out of the file
90 RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
91 if (!w) {
92 cout << "workspace not found" << endl;
93 return;
94 }
95
96 // get the modelConfig out of the file
97 ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
98
99 // get the modelConfig out of the file
100 RooAbsData *data = w->data(dataName);
101
102 // make sure ingredients are found
103 if (!data || !mc) {
104 w->Print();
105 cout << "data or ModelConfig was not found" << endl;
106 return;
107 }
108
109 // -----------------------------
110 // now use the profile inspector
112 TList *list = p.GetListOfProfilePlots(*data, mc);
113
114 // now make plots
115 TCanvas *c1 = new TCanvas("c1", "ProfileInspectorDemo", 800, 200);
116 if (list->GetSize() > 4) {
117 double n = list->GetSize();
118 int nx = (int)sqrt(n);
119 int ny = TMath::CeilNint(n / nx);
120 nx = TMath::CeilNint(sqrt(n));
121 c1->Divide(ny, nx);
122 } else
123 c1->Divide(list->GetSize());
124 for (int i = 0; i < list->GetSize(); ++i) {
125 c1->cd(i + 1);
126 list->At(i)->Draw("al");
127 }
128
129 cout << endl;
130}
double sqrt(double)
#define gROOT
Definition: TROOT.h:406
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:44
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
Utility class to plot conditional MLE of nuisance parameters vs.
TList * GetListOfProfilePlots(RooAbsData &data, RooStats::ModelConfig *config)
This tool makes a plot of the conditional maximum likelihood estimate of the nuisance parameter vs th...
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
void Print(Option_t *opts=0) const
Print contents of the workspace.
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
The Canvas class.
Definition: TCanvas.h:27
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3942
A doubly linked list.
Definition: TList.h:44
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:356
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1291
return c1
Definition: legend1.C:41
const Int_t n
Definition: legend1.C:16
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
Definition: Asimov.h:19
Int_t CeilNint(Double_t x)
Definition: TMath.h:689
Definition: file.py:1