00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00034 ClassImp(RooStats::ProfileInspector);
00035
00036 using namespace RooStats;
00037
00038
00039 ProfileInspector::ProfileInspector()
00040 {
00041 }
00042
00043
00044 ProfileInspector::~ProfileInspector()
00045 {
00046
00047 }
00048
00049
00050 TList* ProfileInspector::GetListOfProfilePlots( RooAbsData& data, RooStats::ModelConfig * config)
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
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
00099
00100
00101
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 }