ROOT logo
// @(#)root/roostats:$Id: ProfileInspector.cxx 34109 2010-06-24 15:00:16Z moneta $

/*************************************************************************
 * Project: RooStats                                                     *
 * Package: RooFit/RooStats                                              *
 * Authors:                                                              *
 *   Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke       *
 *   Akira Shibata
 *************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//____________________________________________________________________
/*
ProfileInspector : 

Utility class to plot conditional MLE of nuisance parameters vs. Parameters of Interest
*/

#include "RooStats/ProfileInspector.h"
#include "RooRealVar.h"
#include "RooAbsReal.h"
#include "RooArgSet.h"
#include "RooAbsPdf.h"
#include "RooArgSet.h"
#include "RooCurve.h"
#include "TAxis.h"

/// ClassImp for building the THtml documentation of the class 
ClassImp(RooStats::ProfileInspector);

using namespace RooStats;

//_______________________________________________________
ProfileInspector::ProfileInspector()
{
}

//_______________________________________________________
ProfileInspector::~ProfileInspector()
{
  // ProfileInspector destructor
}

//_____________________________________________________________________________
TList* ProfileInspector::GetListOfProfilePlots( RooAbsData& data, RooStats::ModelConfig * config)
{

   //
    // < This tool makes a plot of the conditional maximum likelihood estimate of the nuisance parameter 
    //   vs the parameter of interest >
    //
    // This enables you to discover if any of the nuisance parameters are behaving strangely
    // curve is the optional parameters, when used you can specify the points previously scanned
    // in the process of plotOn or createHistogram. 
    // To do this, you can do the following after the plot has been made:

  // profile, RooRealVar * poi, RooCurve * curve ){
  //RooCurve * curve = 0;

  const RooArgSet* poi_set = config->GetParametersOfInterest();
  const RooArgSet* nuis_params=config->GetNuisanceParameters();
  RooAbsPdf* pdf =  config->GetPdf();


  if(!poi_set){
    cout << "no parameters of interest" << endl;
    return 0;
  }

  if(poi_set->getSize()!=1){
    cout << "only one parameter of interest is supported currently" << endl;
    return 0;
  }
  RooRealVar* poi = (RooRealVar*) poi_set->first();


  if(!nuis_params){
    cout << "no nuisance parameters" << endl;
    return 0;
  }

  if(!pdf){
    cout << "pdf not set" << endl;
    return 0;
  }

  RooAbsReal* nll = pdf->createNLL(data);
  RooAbsReal* profile = nll->createProfile(*poi);
  
  TList * list = new TList;
  Int_t curve_N=100;
  Double_t* curve_x=0;
//   if(curve){
//     curve_N=curve->GetN();
//     curve_x=curve->GetX();
//     } else {
  Double_t max = dynamic_cast<RooAbsRealLValue*>(poi)->getMax();
  Double_t min = dynamic_cast<RooAbsRealLValue*>(poi)->getMin();
  Double_t step = (max-min)/(curve_N-1);
  curve_x=new Double_t[curve_N];
  for(int i=0; i<curve_N; ++i){
     curve_x[i]=min+step*i;
  }
//   }
  
  map<string, std::vector<Double_t> > name_val;
  for(int i=0; i<curve_N; i++){
    poi->setVal(curve_x[i]);
    profile->getVal();
    
    TIterator* nuis_params_itr=nuis_params->createIterator();
    TObject* nuis_params_obj;
    while((nuis_params_obj=nuis_params_itr->Next())){
       RooRealVar* nuis_param = dynamic_cast<RooRealVar*>(nuis_params_obj); 
       if(nuis_param) { 
          string name = nuis_param->GetName();
          if(nuis_params->getSize()==0) continue;
          if(nuis_param && (! nuis_param->isConstant())){
             if(name_val.find(name)==name_val.end()) name_val[name]=std::vector<Double_t>(curve_N);
             name_val[name][i]=nuis_param->getVal();
             
             if(i==curve_N-1){
                TGraph* g = new TGraph(curve_N, curve_x, &(name_val[name].front()));
                g->SetName((name+"_"+string(poi->GetName())+"_profile").c_str());
                g->GetXaxis()->SetTitle(poi->GetName());
                g->GetYaxis()->SetTitle(nuis_param->GetName());
                g->SetTitle("");
                list->Add(g);
             }
          }
       }
    }
  }

  delete [] curve_x;
  

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