From $ROOTSYS/tutorials/roostats/StandardProfileInspectorDemo.C

// Standard demo of the ProfileInspector class
/*
StandardProfileInspectorDemo

Author: Kyle Cranmer
date: Dec. 2010

This is a standard demo that can be used with any ROOT file
prepared in the standard way.  You specify:
 - name for input ROOT file
 - name of workspace inside ROOT file that holds model and data
 - name of ModelConfig that specifies details for calculator tools
 - name of dataset

With default parameters the macro will attempt to run the
standard hist2workspace example and read the ROOT file
that it produces.

The actual heart of the demo is only about 10 lines long.

The ProfileInspector plots the conditional maximum likelihood estimate
of each nuisance parameter in the model vs. the parameter of interest.
(aka. profiled value of nuisance parameter vs. parameter of interest)
(aka. best fit nuisance parameter with p.o.i fixed vs. parameter of interest)

*/

#include "TFile.h"
#include "TROOT.h"
#include "TCanvas.h"
#include "TList.h"
#include "TMath.h"
#include "TSystem.h"
#include "RooWorkspace.h"
#include "RooAbsData.h"

#include "RooStats/ModelConfig.h"
#include "RooStats/ProfileInspector.h"

using namespace RooFit;
using namespace RooStats;

void StandardProfileInspectorDemo(const char* infile = "",
                                  const char* workspaceName = "combined",
                                  const char* modelConfigName = "ModelConfig",
                                  const char* dataName = "obsData") {

  /////////////////////////////////////////////////////////////
  // First part is just to access a user-defined file
  // or create the standard example file if it doesn't exist
  ////////////////////////////////////////////////////////////

   const char* filename = "";
   if (!strcmp(infile,"")) {
      filename = "results/example_combined_GaussExample_model.root";
      bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code
      // if file does not exists generate with histfactory
      if (!fileExist) {
#ifdef _WIN32
         cout << "HistFactory file cannot be generated on Windows - exit" << endl;
         return;
#endif
         // Normally this would be run on the command line
         cout <<"will run standard hist2workspace example"<<endl;
         gROOT->ProcessLine(".! prepareHistFactory .");
         gROOT->ProcessLine(".! hist2workspace config/example.xml");
         cout <<"\n\n---------------------"<<endl;
         cout <<"Done creating example input"<<endl;
         cout <<"---------------------\n\n"<<endl;
      }

   }
   else
      filename = infile;

   // Try to open the file
   TFile *file = TFile::Open(filename);

   // if input file was specified byt not found, quit
   if(!file ){
      cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl;
      return;
   }


  /////////////////////////////////////////////////////////////
  // Tutorial starts here
  ////////////////////////////////////////////////////////////

  // get the workspace out of the file
  RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName);
  if(!w){
    cout <<"workspace not found" << endl;
    return;
  }

  // get the modelConfig out of the file
  ModelConfig* mc = (ModelConfig*) w->obj(modelConfigName);

  // get the modelConfig out of the file
  RooAbsData* data = w->data(dataName);

  // make sure ingredients are found
  if(!data || !mc){
    w->Print();
    cout << "data or ModelConfig was not found" <<endl;
    return;
  }

  //////////////////////////////////////////////
  // now use the profile inspector
  ProfileInspector p;
  TList* list = p.GetListOfProfilePlots(*data,mc);

  // now make plots
  TCanvas* c1 = new TCanvas("c1","ProfileInspectorDemo",800,200);
  if(list->GetSize()>4){
    double n = list->GetSize();
    int nx = (int)sqrt(n) ;
    int ny = TMath::CeilNint(n/nx);
    nx = TMath::CeilNint( sqrt(n) );
    c1->Divide(ny,nx);
  } else
    c1->Divide(list->GetSize());
  for(int i=0; i<list->GetSize(); ++i){
    c1->cd(i+1);
    list->At(i)->Draw("al");
  }

  cout << endl;
}
 StandardProfileInspectorDemo.C:1
 StandardProfileInspectorDemo.C:2
 StandardProfileInspectorDemo.C:3
 StandardProfileInspectorDemo.C:4
 StandardProfileInspectorDemo.C:5
 StandardProfileInspectorDemo.C:6
 StandardProfileInspectorDemo.C:7
 StandardProfileInspectorDemo.C:8
 StandardProfileInspectorDemo.C:9
 StandardProfileInspectorDemo.C:10
 StandardProfileInspectorDemo.C:11
 StandardProfileInspectorDemo.C:12
 StandardProfileInspectorDemo.C:13
 StandardProfileInspectorDemo.C:14
 StandardProfileInspectorDemo.C:15
 StandardProfileInspectorDemo.C:16
 StandardProfileInspectorDemo.C:17
 StandardProfileInspectorDemo.C:18
 StandardProfileInspectorDemo.C:19
 StandardProfileInspectorDemo.C:20
 StandardProfileInspectorDemo.C:21
 StandardProfileInspectorDemo.C:22
 StandardProfileInspectorDemo.C:23
 StandardProfileInspectorDemo.C:24
 StandardProfileInspectorDemo.C:25
 StandardProfileInspectorDemo.C:26
 StandardProfileInspectorDemo.C:27
 StandardProfileInspectorDemo.C:28
 StandardProfileInspectorDemo.C:29
 StandardProfileInspectorDemo.C:30
 StandardProfileInspectorDemo.C:31
 StandardProfileInspectorDemo.C:32
 StandardProfileInspectorDemo.C:33
 StandardProfileInspectorDemo.C:34
 StandardProfileInspectorDemo.C:35
 StandardProfileInspectorDemo.C:36
 StandardProfileInspectorDemo.C:37
 StandardProfileInspectorDemo.C:38
 StandardProfileInspectorDemo.C:39
 StandardProfileInspectorDemo.C:40
 StandardProfileInspectorDemo.C:41
 StandardProfileInspectorDemo.C:42
 StandardProfileInspectorDemo.C:43
 StandardProfileInspectorDemo.C:44
 StandardProfileInspectorDemo.C:45
 StandardProfileInspectorDemo.C:46
 StandardProfileInspectorDemo.C:47
 StandardProfileInspectorDemo.C:48
 StandardProfileInspectorDemo.C:49
 StandardProfileInspectorDemo.C:50
 StandardProfileInspectorDemo.C:51
 StandardProfileInspectorDemo.C:52
 StandardProfileInspectorDemo.C:53
 StandardProfileInspectorDemo.C:54
 StandardProfileInspectorDemo.C:55
 StandardProfileInspectorDemo.C:56
 StandardProfileInspectorDemo.C:57
 StandardProfileInspectorDemo.C:58
 StandardProfileInspectorDemo.C:59
 StandardProfileInspectorDemo.C:60
 StandardProfileInspectorDemo.C:61
 StandardProfileInspectorDemo.C:62
 StandardProfileInspectorDemo.C:63
 StandardProfileInspectorDemo.C:64
 StandardProfileInspectorDemo.C:65
 StandardProfileInspectorDemo.C:66
 StandardProfileInspectorDemo.C:67
 StandardProfileInspectorDemo.C:68
 StandardProfileInspectorDemo.C:69
 StandardProfileInspectorDemo.C:70
 StandardProfileInspectorDemo.C:71
 StandardProfileInspectorDemo.C:72
 StandardProfileInspectorDemo.C:73
 StandardProfileInspectorDemo.C:74
 StandardProfileInspectorDemo.C:75
 StandardProfileInspectorDemo.C:76
 StandardProfileInspectorDemo.C:77
 StandardProfileInspectorDemo.C:78
 StandardProfileInspectorDemo.C:79
 StandardProfileInspectorDemo.C:80
 StandardProfileInspectorDemo.C:81
 StandardProfileInspectorDemo.C:82
 StandardProfileInspectorDemo.C:83
 StandardProfileInspectorDemo.C:84
 StandardProfileInspectorDemo.C:85
 StandardProfileInspectorDemo.C:86
 StandardProfileInspectorDemo.C:87
 StandardProfileInspectorDemo.C:88
 StandardProfileInspectorDemo.C:89
 StandardProfileInspectorDemo.C:90
 StandardProfileInspectorDemo.C:91
 StandardProfileInspectorDemo.C:92
 StandardProfileInspectorDemo.C:93
 StandardProfileInspectorDemo.C:94
 StandardProfileInspectorDemo.C:95
 StandardProfileInspectorDemo.C:96
 StandardProfileInspectorDemo.C:97
 StandardProfileInspectorDemo.C:98
 StandardProfileInspectorDemo.C:99
 StandardProfileInspectorDemo.C:100
 StandardProfileInspectorDemo.C:101
 StandardProfileInspectorDemo.C:102
 StandardProfileInspectorDemo.C:103
 StandardProfileInspectorDemo.C:104
 StandardProfileInspectorDemo.C:105
 StandardProfileInspectorDemo.C:106
 StandardProfileInspectorDemo.C:107
 StandardProfileInspectorDemo.C:108
 StandardProfileInspectorDemo.C:109
 StandardProfileInspectorDemo.C:110
 StandardProfileInspectorDemo.C:111
 StandardProfileInspectorDemo.C:112
 StandardProfileInspectorDemo.C:113
 StandardProfileInspectorDemo.C:114
 StandardProfileInspectorDemo.C:115
 StandardProfileInspectorDemo.C:116
 StandardProfileInspectorDemo.C:117
 StandardProfileInspectorDemo.C:118
 StandardProfileInspectorDemo.C:119
 StandardProfileInspectorDemo.C:120
 StandardProfileInspectorDemo.C:121
 StandardProfileInspectorDemo.C:122
 StandardProfileInspectorDemo.C:123
 StandardProfileInspectorDemo.C:124
 StandardProfileInspectorDemo.C:125
 StandardProfileInspectorDemo.C:126
 StandardProfileInspectorDemo.C:127
 StandardProfileInspectorDemo.C:128
 StandardProfileInspectorDemo.C:129
 StandardProfileInspectorDemo.C:130
 StandardProfileInspectorDemo.C:131
 StandardProfileInspectorDemo.C:132