#include "RooWorkspace.h" #include "RooAbsPdf.h" #include "RooDataSet.h" #include "RooFitResult.h" #include "RooPlot.h" #include "RooRealVar.h" #include "RooRandom.h" #include "RooStats/ModelConfig.h" #include "RooStats/AsymptoticCalculator.h" #include "RooStats/ToyMCSampler.h" #include "RooStats/HypoTestResult.h" #include "RooStats/FrequentistCalculator.h" #include "RooStats/ProfileLikelihoodTestStat.h" #include "RooStats/HypoTestPlot.h" #include "TFile.h" using namespace RooFit; using namespace RooStats; using namespace RooFit; void HggGausExpModelHypoTest( const char* infile = "HggGausExpModel.root", const char* workspaceName = "w", const char* modelConfigName = "ModelConfig", const char* dataName = "data" ) { // open input file TFile *file = TFile::Open(infile); if (!file) return; // get the workspace out of the file RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName); // get the data out of the file RooAbsData* data = w->data(dataName); // get the modelConfig (S+B) out of the file // and create the B model from the S+B model ModelConfig* sbModel = (RooStats::ModelConfig*) w->obj(modelConfigName); sbModel->SetName("S+B Model"); RooRealVar* poi = (RooRealVar*) sbModel->GetParametersOfInterest()->first(); poi->setVal(50); // set POI snapshot in S+B model for expected significance sbModel->SetSnapshot(*poi); ModelConfig * bModel = (ModelConfig*) sbModel->Clone(); bModel->SetName("B Model"); poi->setVal(0); bModel->SetSnapshot(*poi); // create the AsymptoticCalculator from data,alt model, null model AsymptoticCalculator ac(*data, *sbModel, *bModel); ac.SetOneSidedDiscovery(true); // for one-side discovery test //ac.SetPrintLevel(-1); // to suppress print level // run the calculator HypoTestResult * asResult = ac.GetHypoTest(); asResult->Print(); //return; std::cout << "\n*** FrequentistCalculator ***\n" << std::endl; FrequentistCalculator fc(*data, *sbModel, *bModel); // 2000 for null (B) and 500 for alt (S+B) fc.SetToys(2000,500); // create the test statistics ProfileLikelihoodTestStat profll(*sbModel->GetPdf()); // use one-sided profile likelihood profll.SetOneSidedDiscovery(true); // configure ToyMCSampler and set the test statistics ToyMCSampler *toymcs = (ToyMCSampler*)fc.GetTestStatSampler(); toymcs->SetTestStatistic(&profll); if (!sbModel->GetPdf()->canBeExtended()) { toymcs->SetNEventsPerToy(1); } // run the test HypoTestResult *fqResult = fc.GetHypoTest(); fqResult->Print(); // plot test statistic distributions HypoTestPlot * plot = new HypoTestPlot(*fqResult); plot->SetLogYaxis(true); plot->Draw(); }