Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 // Normally this would be run on the command line
61 cout << "will run standard hist2workspace example" << endl;
62 gROOT->ProcessLine(".! prepareHistFactory .");
63 gROOT->ProcessLine(".! hist2workspace config/example.xml");
64 cout << "\n\n---------------------" << endl;
65 cout << "Done creating example input" << endl;
66 cout << "---------------------\n\n" << endl;
67 }
68
69 } else
70 filename = infile;
71
72 TFile *file = TFile::Open(filename);
73
74 // -------------------------------------------------------
75 // Tutorial starts here
76 // -------------------------------------------------------
77
78 // get the workspace out of the file
79 RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
80
81 // get the modelConfig out of the file
82 ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
83
84 // get the modelConfig out of the file
85 RooAbsData *data = w->data(dataName);
86
87 // -----------------------------
88 // now use the profile inspector
90 TList *list = p.GetListOfProfilePlots(*data, mc);
91
92 // now make plots
93 TCanvas *c1 = new TCanvas("c1", "ProfileInspectorDemo", 800, 200);
94 if (list->GetSize() > 4) {
95 double n = list->GetSize();
96 int nx = (int)sqrt(n);
97 int ny = TMath::CeilNint(n / nx);
98 nx = TMath::CeilNint(sqrt(n));
99 c1->Divide(ny, nx);
100 } else
101 c1->Divide(list->GetSize());
102 for (int i = 0; i < list->GetSize(); ++i) {
103 c1->cd(i + 1);
104 list->At(i)->Draw("al");
105 }
106
107 cout << endl;
108}
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition ModelConfig.h:35
Utility class to plot conditional MLE of nuisance parameters vs.
Persistable container for RooFit projects.
The Canvas class.
Definition TCanvas.h:23
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
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:4082
A doubly linked list.
Definition TList.h:38
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
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:1296
return c1
Definition legend1.C:41
const Int_t n
Definition legend1.C:16
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
Namespace for the RooStats classes.
Definition Asimov.h:19
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).
Definition TMath.h:674