ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StandardProfileInspectorDemo.C
Go to the documentation of this file.
1 // Standard demo of the ProfileInspector class
2 /*
3 StandardProfileInspectorDemo
4 
5 Author: Kyle Cranmer
6 date: Dec. 2010
7 
8 This is a standard demo that can be used with any ROOT file
9 prepared in the standard way. You specify:
10  - name for input ROOT file
11  - name of workspace inside ROOT file that holds model and data
12  - name of ModelConfig that specifies details for calculator tools
13  - name of dataset
14 
15 With default parameters the macro will attempt to run the
16 standard hist2workspace example and read the ROOT file
17 that it produces.
18 
19 The actual heart of the demo is only about 10 lines long.
20 
21 The ProfileInspector plots the conditional maximum likelihood estimate
22 of each nuisance parameter in the model vs. the parameter of interest.
23 (aka. profiled value of nuisance parameter vs. parameter of interest)
24 (aka. best fit nuisance parameter with p.o.i fixed vs. parameter of interest)
25 
26 */
27 
28 #include "TFile.h"
29 #include "TROOT.h"
30 #include "TCanvas.h"
31 #include "TList.h"
32 #include "TMath.h"
33 #include "TSystem.h"
34 #include "RooWorkspace.h"
35 #include "RooAbsData.h"
36 
37 #include "RooStats/ModelConfig.h"
39 
40 using namespace RooFit;
41 using namespace RooStats;
42 
43 void StandardProfileInspectorDemo(const char* infile = "",
44  const char* workspaceName = "combined",
45  const char* modelConfigName = "ModelConfig",
46  const char* dataName = "obsData") {
47 
48  /////////////////////////////////////////////////////////////
49  // First part is just to access a user-defined file
50  // or create the standard example file if it doesn't exist
51  ////////////////////////////////////////////////////////////
52 
53  const char* filename = "";
54  if (!strcmp(infile,"")) {
55  filename = "results/example_combined_GaussExample_model.root";
56  bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
57  // if file does not exists generate with histfactory
58  if (!fileExist) {
59 #ifdef _WIN32
60  cout << "HistFactory file cannot be generated on Windows - exit" << endl;
61  return;
62 #endif
63  // Normally this would be run on the command line
64  cout <<"will run standard hist2workspace example"<<endl;
65  gROOT->ProcessLine(".! prepareHistFactory .");
66  gROOT->ProcessLine(".! hist2workspace config/example.xml");
67  cout <<"\n\n---------------------"<<endl;
68  cout <<"Done creating example input"<<endl;
69  cout <<"---------------------\n\n"<<endl;
70  }
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  /////////////////////////////////////////////////////////////
87  // Tutorial starts here
88  ////////////////////////////////////////////////////////////
89 
90  // get the workspace out of the file
91  RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName);
92  if(!w){
93  cout <<"workspace not found" << endl;
94  return;
95  }
96 
97  // get the modelConfig out of the file
98  ModelConfig* mc = (ModelConfig*) w->obj(modelConfigName);
99 
100  // get the modelConfig out of the file
101  RooAbsData* data = w->data(dataName);
102 
103  // make sure ingredients are found
104  if(!data || !mc){
105  w->Print();
106  cout << "data or ModelConfig was not found" <<endl;
107  return;
108  }
109 
110  //////////////////////////////////////////////
111  // now use the profile inspector
113  TList* list = p.GetListOfProfilePlots(*data,mc);
114 
115  // now make plots
116  TCanvas* c1 = new TCanvas("c1","ProfileInspectorDemo",800,200);
117  if(list->GetSize()>4){
118  double n = list->GetSize();
119  int nx = (int)sqrt(n) ;
120  int ny = TMath::CeilNint(n/nx);
121  nx = TMath::CeilNint( sqrt(n) );
122  c1->Divide(ny,nx);
123  } else
124  c1->Divide(list->GetSize());
125  for(int i=0; i<list->GetSize(); ++i){
126  c1->cd(i+1);
127  list->At(i)->Draw("al");
128  }
129 
130  cout << endl;
131 }
const int nx
Definition: kalman.C:16
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:1213
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
void StandardProfileInspectorDemo(const char *infile="", const char *workspaceName="combined", const char *modelConfigName="ModelConfig", const char *dataName="obsData")
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found...
TCanvas * c1
Definition: legend1.C:2
static const char * filename()
#define gROOT
Definition: TROOT.h:344
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:311
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3851
double sqrt(double)
const int ny
Definition: kalman.C:17
A doubly linked list.
Definition: TList.h:47
tuple infile
Definition: mrt.py:15
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
tuple w
Definition: qtexample.py:51
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
virtual Int_t GetSize() const
Definition: TCollection.h:95
tuple file
Definition: fildir.py:20
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name) ...
void Print(Option_t *opts=0) const
Print contents of the workspace.
TList * GetListOfProfilePlots(RooAbsData &data, RooStats::ModelConfig *config)
const Int_t n
Definition: legend1.C:16
Int_t CeilNint(Double_t x)
Definition: TMath.h:470
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42