ProfileInspector.cxx

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: ProfileInspector.cxx 34109 2010-06-24 15:00:16Z moneta $
00002 
00003 /*************************************************************************
00004  * Project: RooStats                                                     *
00005  * Package: RooFit/RooStats                                              *
00006  * Authors:                                                              *
00007  *   Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke       *
00008  *   Akira Shibata
00009  *************************************************************************
00010  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00011  * All rights reserved.                                                  *
00012  *                                                                       *
00013  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00014  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00015  *************************************************************************/
00016 
00017 //____________________________________________________________________
00018 /*
00019 ProfileInspector : 
00020 
00021 Utility class to plot conditional MLE of nuisance parameters vs. Parameters of Interest
00022 */
00023 
00024 #include "RooStats/ProfileInspector.h"
00025 #include "RooRealVar.h"
00026 #include "RooAbsReal.h"
00027 #include "RooArgSet.h"
00028 #include "RooAbsPdf.h"
00029 #include "RooArgSet.h"
00030 #include "RooCurve.h"
00031 #include "TAxis.h"
00032 
00033 /// ClassImp for building the THtml documentation of the class 
00034 ClassImp(RooStats::ProfileInspector);
00035 
00036 using namespace RooStats;
00037 
00038 //_______________________________________________________
00039 ProfileInspector::ProfileInspector()
00040 {
00041 }
00042 
00043 //_______________________________________________________
00044 ProfileInspector::~ProfileInspector()
00045 {
00046   // ProfileInspector destructor
00047 }
00048 
00049 //_____________________________________________________________________________
00050 TList* ProfileInspector::GetListOfProfilePlots( RooAbsData& data, RooStats::ModelConfig * config)
00051 {
00052 
00053    //
00054     // < This tool makes a plot of the conditional maximum likelihood estimate of the nuisance parameter 
00055     //   vs the parameter of interest >
00056     //
00057     // This enables you to discover if any of the nuisance parameters are behaving strangely
00058     // curve is the optional parameters, when used you can specify the points previously scanned
00059     // in the process of plotOn or createHistogram. 
00060     // To do this, you can do the following after the plot has been made:
00061 
00062   // profile, RooRealVar * poi, RooCurve * curve ){
00063   //RooCurve * curve = 0;
00064 
00065   const RooArgSet* poi_set = config->GetParametersOfInterest();
00066   const RooArgSet* nuis_params=config->GetNuisanceParameters();
00067   RooAbsPdf* pdf =  config->GetPdf();
00068 
00069 
00070   if(!poi_set){
00071     cout << "no parameters of interest" << endl;
00072     return 0;
00073   }
00074 
00075   if(poi_set->getSize()!=1){
00076     cout << "only one parameter of interest is supported currently" << endl;
00077     return 0;
00078   }
00079   RooRealVar* poi = (RooRealVar*) poi_set->first();
00080 
00081 
00082   if(!nuis_params){
00083     cout << "no nuisance parameters" << endl;
00084     return 0;
00085   }
00086 
00087   if(!pdf){
00088     cout << "pdf not set" << endl;
00089     return 0;
00090   }
00091 
00092   RooAbsReal* nll = pdf->createNLL(data);
00093   RooAbsReal* profile = nll->createProfile(*poi);
00094   
00095   TList * list = new TList;
00096   Int_t curve_N=100;
00097   Double_t* curve_x=0;
00098 //   if(curve){
00099 //     curve_N=curve->GetN();
00100 //     curve_x=curve->GetX();
00101 //     } else {
00102   Double_t max = dynamic_cast<RooAbsRealLValue*>(poi)->getMax();
00103   Double_t min = dynamic_cast<RooAbsRealLValue*>(poi)->getMin();
00104   Double_t step = (max-min)/(curve_N-1);
00105   curve_x=new Double_t[curve_N];
00106   for(int i=0; i<curve_N; ++i){
00107      curve_x[i]=min+step*i;
00108   }
00109 //   }
00110   
00111   map<string, std::vector<Double_t> > name_val;
00112   for(int i=0; i<curve_N; i++){
00113     poi->setVal(curve_x[i]);
00114     profile->getVal();
00115     
00116     TIterator* nuis_params_itr=nuis_params->createIterator();
00117     TObject* nuis_params_obj;
00118     while((nuis_params_obj=nuis_params_itr->Next())){
00119        RooRealVar* nuis_param = dynamic_cast<RooRealVar*>(nuis_params_obj); 
00120        if(nuis_param) { 
00121           string name = nuis_param->GetName();
00122           if(nuis_params->getSize()==0) continue;
00123           if(nuis_param && (! nuis_param->isConstant())){
00124              if(name_val.find(name)==name_val.end()) name_val[name]=std::vector<Double_t>(curve_N);
00125              name_val[name][i]=nuis_param->getVal();
00126              
00127              if(i==curve_N-1){
00128                 TGraph* g = new TGraph(curve_N, curve_x, &(name_val[name].front()));
00129                 g->SetName((name+"_"+string(poi->GetName())+"_profile").c_str());
00130                 g->GetXaxis()->SetTitle(poi->GetName());
00131                 g->GetYaxis()->SetTitle(nuis_param->GetName());
00132                 g->SetTitle("");
00133                 list->Add(g);
00134              }
00135           }
00136        }
00137     }
00138   }
00139 
00140   delete [] curve_x;
00141   
00142 
00143   delete nll;
00144   delete profile;
00145   return list;
00146 }

Generated on Tue Jul 5 15:14:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1