// 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 "RooWorkspace.h" #include "RooAbsData.h" #include "RooStats/ModelConfig.h" // #include "RooStats/ProfileInspector.h" #include "TString.h" #include "TMath.h" #include "TROOT.h" #include "Math/MinimizerOptions.h" #include "TList.h" #include "RooRealVar.h" #include "RooAbsReal.h" #include "RooArgSet.h" #include "RooAbsPdf.h" #include "RooArgSet.h" #include "RooCurve.h" #include "TAxis.h" #include "RooAbsData.h" using namespace RooFit; using namespace RooStats; void runTest(TString mA="", TString tb="", TString suff="", double TOL=1, int strategy=0); TList* 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(); //cout << "PDF got " << endl; 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; } //cout << "Before createNLL data " << endl; RooAbsReal* nll = pdf->createNLL(data); //cout << "Before createProfile " << endl; RooAbsReal* profile = nll->createProfile(*poi); //cout << "Before TList definition " << endl; 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(poi)->getMax(); // Double_t min = dynamic_cast(poi)->getMin(); Double_t max = 5.1; Double_t min = 0.1; Double_t step = (max-min)/(curve_N-1); curve_x=new Double_t[curve_N]; for(int i=0; i > name_val; for(int i=0; isetVal(curve_x[i]); //cout << "poi value set, getting profile value" << endl; profile->getVal(); //cout << "Profile set" << endl; TIterator* nuis_params_itr=nuis_params->createIterator(); TObject* nuis_params_obj; while((nuis_params_obj=nuis_params_itr->Next())){ RooRealVar* nuis_param = dynamic_cast(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(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); } } } } nuis_params->Print("v"); } delete [] curve_x; delete nll; delete profile; return list; } void StandardProfileInspectorDemo(const char* infile = "", const char* pname = "", 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"; else filename = infile; // Check if example input file exists TFile *file = TFile::Open(filename); // if input file was specified byt not found, quit if(!file && strcmp(infile,"")){ cout <<"file not found" << endl; return; } // if default file not found, try to create it if(!file ){ // Normally this would be run on the command line cout <<"will run standard hist2workspace example"<ProcessLine(".! prepareHistFactory ."); gROOT->ProcessLine(".! hist2workspace config/example.xml"); cout <<"\n\n---------------------"<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" < make the plots ------------------------ for(int i=0; iGetSize(); ++i){ TCanvas* ci = new TCanvas("c1","ProfileInspectorDemo",1000,600); TGraph *g = (TGraph*) list->At(i); int g_npoints = g->GetN(); double g_min = TMath::MinElement(g_npoints, g->GetY()); double g_max = TMath::MaxElement(g_npoints, g->GetY()); double g_span = g_max-g_min; double g_mean = g_min + g_span/2; double g_range_min = std::min(g_min, g_mean - g_max*0.3) - 0.2*g_span; double g_range_max = std::max(g_max, g_mean + g_max*0.3) + 0.2*g_span; g->GetYaxis()->SetRangeUser(g_range_min, g_range_max); // list->At(i)->Draw("al"); g->Draw("al"); TString cname("c1_"); cname += i; cname += "_"; ci->Print(cname+TString(pname)+".png"); //ci->Delete(); } return; // ------------------------------------------- // now make plots TCanvas* c1 = new TCanvas("c1","ProfileInspectorDemo",800,200); c1->Divide(list->GetSize()); for(int i=0; iGetSize(); ++i){ c1->cd(i+1); list->At(i)->Draw("al"); } c1->Print("c1_"+TString(pname)+".png"); // now make plots TCanvas* c2 = 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) ); c2->Divide(ny,nx); } else c2->Divide(list->GetSize()); for(int i=0; iGetSize(); ++i){ c2->cd(i+1); list->At(i)->Draw("al"); } c2->Print("c2_"+TString(pname)+".png"); } void runTest(TString mA, TString tb, TString suff, double TOL, int strategy) { if (mA == "" or tb == "") { mA = "130"; tb = "10"; } TString pname= "mA"+mA+"tb"+tb; TString fold="/home/rompotis/Analysis/higgsTauTau/December2012Analysis/Limits/MSSMLimits/TestSensitivities/results/resultsV5_teff_v1/"; // TString file = fold+"mssm_mA"+mA+"tb"+tb+"_comb_combined_AllSyst_model.root"; TString file = fold+"bTagDefCom_"+pname+"_comb_combined_AllSyst_model.root"; ROOT::Math::MinimizerOptions::SetDefaultTolerance(TOL); ROOT::Math::MinimizerOptions::SetDefaultMinimizer("Minuit2"); // ROOT::Math::MinimizerOptions::SetDefaultPrintingLevel(-1); ROOT::Math::MinimizerOptions::SetDefaultStrategy(strategy); ROOT::Math::MinimizerOptions::SetDefaultMaxFunctionCalls(100000); StandardProfileInspectorDemo(file.Data(), pname.Data()); }