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 // Try to open the file
74
75 // if input file was specified byt not found, quit
76 if (!file) {
77 cout << "StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
78 return;
79 }
80
81 // -------------------------------------------------------
82 // Tutorial starts here
83 // -------------------------------------------------------
84
85 // get the workspace out of the file
86 RooWorkspace *w = (RooWorkspace *)file->Get(workspaceName);
87 if (!w) {
88 cout << "workspace not found" << endl;
89 return;
90 }
91
92 // get the modelConfig out of the file
93 ModelConfig *mc = (ModelConfig *)w->obj(modelConfigName);
94
95 // get the modelConfig out of the file
96 RooAbsData *data = w->data(dataName);
97
98 // make sure ingredients are found
99 if (!data || !mc) {
100 w->Print();
101 cout << "data or ModelConfig was not found" << endl;
102 return;
103 }
104
105 // -----------------------------
106 // now use the profile inspector
108 TList *list = p.GetListOfProfilePlots(*data, mc);
109
110 // now make plots
111 TCanvas *c1 = new TCanvas("c1", "ProfileInspectorDemo", 800, 200);
112 if (list->GetSize() > 4) {
113 double n = list->GetSize();
114 int nx = (int)sqrt(n);
115 int ny = TMath::CeilNint(n / nx);
116 nx = TMath::CeilNint(sqrt(n));
117 c1->Divide(ny, nx);
118 } else
119 c1->Divide(list->GetSize());
120 for (int i = 0; i < list->GetSize(); ++i) {
121 c1->cd(i + 1);
122 list->At(i)->Draw("al");
123 }
124
125 cout << endl;
126}
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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
#define gROOT
Definition TROOT.h:407
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
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.
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
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:4075
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:357
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:1283
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
Definition file.py:1