Logo ROOT   6.12/07
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 
40 #include "RooStats/ModelConfig.h"
42 
43 using namespace RooFit;
44 using namespace RooStats;
45 
46 void StandardProfileInspectorDemo(const char* infile = "",
47  const char* workspaceName = "combined",
48  const char* modelConfigName = "ModelConfig",
49  const char* dataName = "obsData") {
50 
51  // -------------------------------------------------------
52  // First part is just to access a user-defined file
53  // or create the standard example file if it doesn't exist
54 
55  const char* filename = "";
56  if (!strcmp(infile,"")) {
57  filename = "results/example_combined_GaussExample_model.root";
58  bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
59  // if file does not exists generate with histfactory
60  if (!fileExist) {
61 #ifdef _WIN32
62  cout << "HistFactory file cannot be generated on Windows - exit" << endl;
63  return;
64 #endif
65  // Normally this would be run on the command line
66  cout <<"will run standard hist2workspace example"<<endl;
67  gROOT->ProcessLine(".! prepareHistFactory .");
68  gROOT->ProcessLine(".! hist2workspace config/example.xml");
69  cout <<"\n\n---------------------"<<endl;
70  cout <<"Done creating example input"<<endl;
71  cout <<"---------------------\n\n"<<endl;
72  }
73 
74  }
75  else
76  filename = infile;
77 
78  // Try to open the file
79  TFile *file = TFile::Open(filename);
80 
81  // if input file was specified byt not found, quit
82  if(!file ){
83  cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
84  return;
85  }
86 
87 
88  // -------------------------------------------------------
89  // Tutorial starts here
90  // -------------------------------------------------------
91 
92  // get the workspace out of the file
93  RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName);
94  if(!w){
95  cout <<"workspace not found" << endl;
96  return;
97  }
98 
99  // get the modelConfig out of the file
100  ModelConfig* mc = (ModelConfig*) w->obj(modelConfigName);
101 
102  // get the modelConfig out of the file
103  RooAbsData* data = w->data(dataName);
104 
105  // make sure ingredients are found
106  if(!data || !mc){
107  w->Print();
108  cout << "data or ModelConfig was not found" <<endl;
109  return;
110  }
111 
112  // -----------------------------
113  // now use the profile inspector
115  TList* list = p.GetListOfProfilePlots(*data,mc);
116 
117  // now make plots
118  TCanvas* c1 = new TCanvas("c1","ProfileInspectorDemo",800,200);
119  if(list->GetSize()>4){
120  double n = list->GetSize();
121  int nx = (int)sqrt(n) ;
122  int ny = TMath::CeilNint(n/nx);
123  nx = TMath::CeilNint( sqrt(n) );
124  c1->Divide(ny,nx);
125  } else
126  c1->Divide(list->GetSize());
127  for(int i=0; i<list->GetSize(); ++i){
128  c1->cd(i+1);
129  list->At(i)->Draw("al");
130  }
131 
132  cout << endl;
133 }
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:1276
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:30
return c1
Definition: legend1.C:41
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
#define gROOT
Definition: TROOT.h:402
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
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:3950
double sqrt(double)
A doubly linked list.
Definition: TList.h:44
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found...
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:354
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:31
Namespace for the RooStats classes.
Definition: Asimov.h:20
Utility class to plot conditional MLE of nuisance parameters vs.
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1153
Definition: file.py:1
TList * GetListOfProfilePlots(RooAbsData &data, RooStats::ModelConfig *config)
This tool makes a plot of the conditional maximum likelihood estimate of the nuisance parameter vs th...
virtual Int_t GetSize() const
Definition: TCollection.h:180
void Print(Option_t *opts=0) const
Print contents of the workspace.
const Int_t n
Definition: legend1.C:16
Int_t CeilNint(Double_t x)
Definition: TMath.h:596
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42