void central_interval_Profile_Likelihood(Model* model,double confidence){ cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl; cout<<"Calculating central confidence interval with the Profile Likelihood method"<<endl; cout<<"///////////////////////////////////////////////////////////////////////////////////////////"<<endl; // //define paramsOfInterest RooArgSet *paramsOfInterest=new RooArgSet("paramsOfInterest"); paramsOfInterest->addClone(*model->get_POI()); //clone because we need s for complete likelihood //get the calculator ProfileLikelihoodCalculator plc(*model->get_data(),*model->get_complete_likelihood(), *paramsOfInterest); // //get the confidence interval LikelihoodInterval* lrint = (LikelihoodInterval*) plc.GetInterval(); lrint->SetConfidenceLevel(confidence); double ll=lrint->LowerLimit(*model->get_POI()); double ul=lrint->UpperLimit(*model->get_POI()); cout<<confidence<<"% inter val is "<<ll<<" , "<<ul<<endl; }
void StandardProfileLikelihoodDemo(const char* infile = "", const char* workspaceName = "combined", const char* modelConfigName = "ModelConfig", const char* dataName = "obsData"){ double confLevel = optPL.confLevel; double nScanPoints = optPL.nScanPoints; bool plotAsTF1 = optPL.plotAsTF1; double poiXMin = optPL.poiMinPlot; double poiXMax = optPL.poiMaxPlot; bool doHypoTest = optPL.doHypoTest; double nullParamValue = optPL.nullValue; // ------------------------------------------------------- // 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"; bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code // if file does not exists generate with histfactory if (!fileExist) { #ifdef _WIN32 cout << "HistFactory file cannot be generated on Windows - exit" << endl; return; #endif // Normally this would be run on the command line cout <<"will run standard hist2workspace example"<<endl; gROOT->ProcessLine(".! prepareHistFactory ."); gROOT->ProcessLine(".! hist2workspace config/example.xml"); cout <<"\n\n---------------------"<<endl; cout <<"Done creating example input"<<endl; cout <<"---------------------\n\n"<<endl; } } else filename = infile; // Try to open the file TFile *file = TFile::Open(filename); // if input file was specified byt not found, quit if(!file ){ cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl; return; } // ------------------------------------------------------- // Tutorial starts here // ------------------------------------------------------- // get the workspace out of the file RooWorkspace* w = (RooWorkspace*) file->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" <<endl; return; } // --------------------------------------------- // create and use the ProfileLikelihoodCalculator // to find and plot the 95% confidence interval // on the parameter of interest as specified // in the model config ProfileLikelihoodCalculator pl(*data,*mc); pl.SetConfidenceLevel(confLevel); // 95% interval LikelihoodInterval* interval = pl.GetInterval(); // print out the interval on the first Parameter of Interest RooRealVar* firstPOI = (RooRealVar*) mc->GetParametersOfInterest()->first(); cout << "\n>>>> RESULT : " << confLevel*100 << "% interval on " <<firstPOI->GetName()<<" is : ["<< interval->LowerLimit(*firstPOI) << ", "<< interval->UpperLimit(*firstPOI) <<"]\n "<<endl; // make a plot cout << "making a plot of the profile likelihood function ....(if it is taking a lot of time use less points or the TF1 drawing option)\n"; LikelihoodIntervalPlot plot(interval); plot.SetNPoints(nScanPoints); // do not use too many points, it could become very slow for some models if (poiXMin < poiXMax) plot.SetRange(poiXMin, poiXMax); TString opt; if (plotAsTF1) opt += TString("tf1"); plot.Draw(opt); // use option TF1 if too slow (plot.Draw("tf1") // if requested perform also an hypothesis test for the significance if (doHypoTest) { RooArgSet nullparams("nullparams"); nullparams.addClone(*firstPOI); nullparams.setRealValue(firstPOI->GetName(), nullParamValue); pl.SetNullParameters(nullparams); std::cout << "Perform Test of Hypothesis : null Hypothesis is " << firstPOI->GetName() << nullParamValue << std::endl; auto result = pl.GetHypoTest(); std::cout << "\n>>>> Hypotheis Test Result \n"; result->Print(); } }
// // calculation of the limit: assumes that wspace is set up and observations // contained in data // MyLimit computeLimit (RooWorkspace* wspace, RooDataSet* data, StatMethod method, bool draw) { // let's time this challenging example TStopwatch t; // // get nominal signal // RooRealVar exp_sig(*wspace->var("s")); double exp_sig_val = exp_sig.getVal(); std::cout << "exp_sig = " << exp_sig_val << std::endl; ///////////////////////////////////////////////////// // Now the statistical tests // model config std::cout << wspace->pdf("model") << " " << wspace->pdf("prior") << " " << wspace->set("poi") << " " << wspace->set("nuis") << std::endl; ModelConfig modelConfig("RA4abcd"); modelConfig.SetWorkspace(*wspace); modelConfig.SetPdf(*wspace->pdf("model")); modelConfig.SetPriorPdf(*wspace->pdf("prior")); modelConfig.SetParametersOfInterest(*wspace->set("poi")); modelConfig.SetNuisanceParameters(*wspace->set("nuis")); ////////////////////////////////////////////////// // If you want to see the covariance matrix uncomment // wspace->pdf("model")->fitTo(*data); // use ProfileLikelihood if ( method == ProfileLikelihoodMethod ) { ProfileLikelihoodCalculator plc(*data, modelConfig); plc.SetConfidenceLevel(0.95); RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow(); RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL); LikelihoodInterval* plInt = plc.GetInterval(); RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL); plInt->LowerLimit( *wspace->var("s") ); // get ugly print out of the way. Fix. // RooMsgService::instance().setGlobalKillBelow(RooFit::DEBUG); if ( draw ) { TCanvas* c = new TCanvas("ProfileLikelihood"); LikelihoodIntervalPlot* lrplot = new LikelihoodIntervalPlot(plInt); lrplot->Draw(); } // RooMsgService::instance().setGlobalKillBelow(msglevel); double lowLim = plInt->LowerLimit(*wspace->var("s")); double uppLim = plInt->UpperLimit(*wspace->var("s")); // double exp_sig_val = wspace->var("s")->getVal(); // double exp_sig_val = exp_sig.getVal(); cout << "Profile Likelihood interval on s = [" << lowLim << ", " << uppLim << "]" << " " << exp_sig_val << endl; // MyLimit result(plInt->IsInInterval(exp_sig), MyLimit result(exp_sig_val>lowLim&&exp_sig_val<uppLim,lowLim,uppLim); // std::cout << "isIn " << result << std::endl; delete plInt; // delete modelConfig; return result; } // use FeldmaCousins (takes ~20 min) if ( method == FeldmanCousinsMethod ) { FeldmanCousins fc(*data, modelConfig); fc.SetConfidenceLevel(0.95); //number counting: dataset always has 1 entry with N events observed fc.FluctuateNumDataEntries(false); fc.UseAdaptiveSampling(true); fc.SetNBins(100); PointSetInterval* fcInt = NULL; fcInt = (PointSetInterval*) fc.GetInterval(); // fix cast double lowLim = fcInt->LowerLimit(*wspace->var("s")); double uppLim = fcInt->UpperLimit(*wspace->var("s")); // double exp_sig_val = wspace->var("s")->getVal(); cout << "Feldman Cousins interval on s = [" << lowLim << " " << uppLim << endl; // std::cout << "isIn " << result << std::endl; MyLimit result(exp_sig_val>lowLim&&exp_sig_val<uppLim, fcInt->LowerLimit(*wspace->var("s")),fcInt->UpperLimit(*wspace->var("s"))); delete fcInt; return result; } // use BayesianCalculator (only 1-d parameter of interest, slow for this problem) if ( method == BayesianMethod ) { BayesianCalculator bc(*data, modelConfig); bc.SetConfidenceLevel(0.95); bc.SetLeftSideTailFraction(0.5); SimpleInterval* bInt = NULL; if( wspace->set("poi")->getSize() == 1) { bInt = bc.GetInterval(); if ( draw ) { TCanvas* c = new TCanvas("Bayesian"); // the plot takes a long time and print lots of error // using a scan it is better bc.SetScanOfPosterior(50); RooPlot* bplot = bc.GetPosteriorPlot(); bplot->Draw(); } cout << "Bayesian interval on s = [" << bInt->LowerLimit( ) << ", " << bInt->UpperLimit( ) << "]" << endl; // std::cout << "isIn " << result << std::endl; MyLimit result(bInt->IsInInterval(exp_sig), bInt->LowerLimit(),bInt->UpperLimit()); delete bInt; return result; } else { cout << "Bayesian Calc. only supports on parameter of interest" << endl; return MyLimit(); } } // use MCMCCalculator (takes about 1 min) // Want an efficient proposal function, so derive it from covariance // matrix of fit if ( method == MCMCMethod ) { RooFitResult* fit = wspace->pdf("model")->fitTo(*data,Save()); ProposalHelper ph; ph.SetVariables((RooArgSet&)fit->floatParsFinal()); ph.SetCovMatrix(fit->covarianceMatrix()); ph.SetUpdateProposalParameters(kTRUE); // auto-create mean vars and add mappings ph.SetCacheSize(100); ProposalFunction* pf = ph.GetProposalFunction(); MCMCCalculator mc(*data, modelConfig); mc.SetConfidenceLevel(0.95); mc.SetProposalFunction(*pf); mc.SetNumBurnInSteps(100); // first N steps to be ignored as burn-in mc.SetNumIters(100000); mc.SetLeftSideTailFraction(0.5); // make a central interval MCMCInterval* mcInt = NULL; mcInt = mc.GetInterval(); MCMCIntervalPlot mcPlot(*mcInt); mcPlot.Draw(); cout << "MCMC interval on s = [" << mcInt->LowerLimit(*wspace->var("s") ) << ", " << mcInt->UpperLimit(*wspace->var("s") ) << "]" << endl; // std::cout << "isIn " << result << std::endl; MyLimit result(mcInt->IsInInterval(exp_sig), mcInt->LowerLimit(*wspace->var("s")),mcInt->UpperLimit(*wspace->var("s"))); delete mcInt; return result; } t.Print(); // delete modelConfig; return MyLimit(); }
void IntervalExamples() { // Time this macro TStopwatch t; t.Start(); // set RooFit random seed for reproducible results RooRandom::randomGenerator()->SetSeed(3001); // make a simple model via the workspace factory RooWorkspace* wspace = new RooWorkspace(); wspace->factory("Gaussian::normal(x[-10,10],mu[-1,1],sigma[1])"); wspace->defineSet("poi","mu"); wspace->defineSet("obs","x"); // specify components of model for statistical tools ModelConfig* modelConfig = new ModelConfig("Example G(x|mu,1)"); modelConfig->SetWorkspace(*wspace); modelConfig->SetPdf( *wspace->pdf("normal") ); modelConfig->SetParametersOfInterest( *wspace->set("poi") ); modelConfig->SetObservables( *wspace->set("obs") ); // create a toy dataset RooDataSet* data = wspace->pdf("normal")->generate(*wspace->set("obs"),100); data->Print(); // for convenience later on RooRealVar* x = wspace->var("x"); RooRealVar* mu = wspace->var("mu"); // set confidence level double confidenceLevel = 0.95; // example use profile likelihood calculator ProfileLikelihoodCalculator plc(*data, *modelConfig); plc.SetConfidenceLevel( confidenceLevel); LikelihoodInterval* plInt = plc.GetInterval(); // example use of Feldman-Cousins FeldmanCousins fc(*data, *modelConfig); fc.SetConfidenceLevel( confidenceLevel); fc.SetNBins(100); // number of points to test per parameter fc.UseAdaptiveSampling(true); // make it go faster // Here, we consider only ensembles with 100 events // The PDF could be extended and this could be removed fc.FluctuateNumDataEntries(false); // Proof // ProofConfig pc(*wspace, 4, "workers=4", kFALSE); // proof-lite //ProofConfig pc(w, 8, "localhost"); // proof cluster at "localhost" // ToyMCSampler* toymcsampler = (ToyMCSampler*) fc.GetTestStatSampler(); // toymcsampler->SetProofConfig(&pc); // enable proof PointSetInterval* interval = (PointSetInterval*) fc.GetInterval(); // example use of BayesianCalculator // now we also need to specify a prior in the ModelConfig wspace->factory("Uniform::prior(mu)"); modelConfig->SetPriorPdf(*wspace->pdf("prior")); // example usage of BayesianCalculator BayesianCalculator bc(*data, *modelConfig); bc.SetConfidenceLevel( confidenceLevel); SimpleInterval* bcInt = bc.GetInterval(); // example use of MCMCInterval MCMCCalculator mc(*data, *modelConfig); mc.SetConfidenceLevel( confidenceLevel); // special options mc.SetNumBins(200); // bins used internally for representing posterior mc.SetNumBurnInSteps(500); // first N steps to be ignored as burn-in mc.SetNumIters(100000); // how long to run chain mc.SetLeftSideTailFraction(0.5); // for central interval MCMCInterval* mcInt = mc.GetInterval(); // for this example we know the expected intervals double expectedLL = data->mean(*x) + ROOT::Math::normal_quantile( (1-confidenceLevel)/2,1) / sqrt(data->numEntries()); double expectedUL = data->mean(*x) + ROOT::Math::normal_quantile_c((1-confidenceLevel)/2,1) / sqrt(data->numEntries()) ; // Use the intervals std::cout << "expected interval is [" << expectedLL << ", " << expectedUL << "]" << endl; cout << "plc interval is [" << plInt->LowerLimit(*mu) << ", " << plInt->UpperLimit(*mu) << "]" << endl; std::cout << "fc interval is ["<< interval->LowerLimit(*mu) << " , " << interval->UpperLimit(*mu) << "]" << endl; cout << "bc interval is [" << bcInt->LowerLimit() << ", " << bcInt->UpperLimit() << "]" << endl; cout << "mc interval is [" << mcInt->LowerLimit(*mu) << ", " << mcInt->UpperLimit(*mu) << "]" << endl; mu->setVal(0); cout << "is mu=0 in the interval? " << plInt->IsInInterval(RooArgSet(*mu)) << endl; // make a reasonable style gStyle->SetCanvasColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetPadColor(0); gStyle->SetCanvasColor(0); gStyle->SetTitleFillColor(0); gStyle->SetFillColor(0); gStyle->SetFrameFillColor(0); gStyle->SetStatColor(0); // some plots TCanvas* canvas = new TCanvas("canvas"); canvas->Divide(2,2); // plot the data canvas->cd(1); RooPlot* frame = x->frame(); data->plotOn(frame); data->statOn(frame); frame->Draw(); // plot the profile likelihood canvas->cd(2); LikelihoodIntervalPlot plot(plInt); plot.Draw(); // plot the MCMC interval canvas->cd(3); MCMCIntervalPlot* mcPlot = new MCMCIntervalPlot(*mcInt); mcPlot->SetLineColor(kGreen); mcPlot->SetLineWidth(2); mcPlot->Draw(); canvas->cd(4); RooPlot * bcPlot = bc.GetPosteriorPlot(); bcPlot->Draw(); canvas->Update(); t.Stop(); t.Print(); }
void exercise_3() { //Open the rootfile and get the workspace from the exercise_0 TFile fIn("exercise_0.root"); fIn.cd(); RooWorkspace *w = (RooWorkspace*)fIn.Get("w"); //You can set constant parameters that are known //If you leave them floating, the fit procedure will determine their uncertainty w->var("mean")->setConstant(kFALSE); //don't fix the mean, it's what we want to know the interval for! w->var("sigma")->setConstant(kTRUE); w->var("tau")->setConstant(kTRUE); w->var("Nsig")->setConstant(kTRUE); w->var("Nbkg")->setConstant(kTRUE); //Set the RooModelConfig and let it know what the content of the workspace is about ModelConfig model; model.SetWorkspace(*w); model.SetPdf("PDFtot"); //Let the model know what is the parameter of interest RooRealVar* mean = w->var("mean"); mean->setRange(120., 130.); //this is mostly for plotting reasons RooArgSet poi(*mean); // set confidence level double confidenceLevel = 0.68; //Build the profile likelihood calculator ProfileLikelihoodCalculator plc; plc.SetData(*(w->data("PDFtotData"))); plc.SetModel(model); plc.SetParameters(poi); plc.SetConfidenceLevel(confidenceLevel); //Get the interval LikelihoodInterval* plInt = plc.GetInterval(); //Now let's do the same for the Bayesian Calculator //Now we also need to specify a prior in the ModelConfig //To be quicker, we'll use the PDF factory facility of RooWorkspace //NB!! For simplicity, we are using a flat prior, but this doesn't mean it's the best choice! w->factory("Uniform::prior(mean)"); model.SetPriorPdf(*w->pdf("prior")); //Construct the bayesian calculator BayesianCalculator bc(*(w->data("PDFtotData")), model); bc.SetConfidenceLevel(confidenceLevel); bc.SetParameters(poi); SimpleInterval* bcInt = bc.GetInterval(); // Let's make a plot TCanvas dataCanvas("dataCanvas"); dataCanvas.Divide(2,1); dataCanvas.cd(1); LikelihoodIntervalPlot plotInt((LikelihoodInterval*)plInt); plotInt.SetTitle("Profile Likelihood Ratio and Posterior for mH"); plotInt.SetMaximum(3.); plotInt.Draw(); dataCanvas.cd(2); RooPlot *bcPlot = bc.GetPosteriorPlot(); bcPlot->Draw(); dataCanvas.SaveAs("exercise_3.gif"); //Now print the interval for mH for the two methods cout << "PLC interval is [" << plInt->LowerLimit(*mean) << ", " << plInt->UpperLimit(*mean) << "]" << endl; cout << "Bayesian interval is [" << bcInt->LowerLimit() << ", " << bcInt->UpperLimit() << "]" << endl; }
void CountingModelCross_2( int nobs_4m = 27, // number of observed events double b_4m = 0.09, // number of background events double sigmab_4m = 0.16, // relative uncertainty in b 1 int nobs_2e2m = 30, // number of observed events double b_2e2m = 0.47, // number of background events double sigmab_2e2m = 0.26, // relative uncertainty in b 2 int nobs_4e = 8, // number of observed events double b_4e = 0.44, // number of background events double sigmab_4e = 0.35 // relative uncertainty in b 2 ) { RooWorkspace w("w"); // make Poisson model * Gaussian constraint w.factory("prod:s_4m(cross[34.7,0.,10000000],BR_4m[0.5,0,1],Acc_4m[0.5,0.,1.],Lumi[2.229,0.,10000])"); w.factory("prod:s_2e2m(cross[34.7,0.,10000000],BR_2e2m[0.5,0,1],Acc_2e2m[0.5,0.,1.],Lumi[2.229,0.,10000])"); w.factory("prod:s_4e(cross[34.7,0.,10000000],BR_4e[0.5,0,1],Acc_4e[0.5,0.,1.],Lumi[2.229,0.,10000])"); w.factory("sum:nexp_4m(s_4m,b_4m[1,0,10])"); w.factory("sum:nexp_2e2m(s_2e2m,b_2e2m[1,0,10])"); w.factory("sum:nexp_4e(s_4e,b_4e[1,0,10])"); w.var("b_4m")->setVal(b_4m); w.var("b_2e2m")->setVal(b_2e2m); w.var("b_4e")->setVal(b_4e); // Poisson of (n | s+b) w.factory("Poisson:pdf_4m(nobs_4m[0,50],nexp_4m)"); w.factory("Poisson:pdf_2e2m(nobs_2e2m[0,50],nexp_2e2m)"); w.factory("Poisson:pdf_4e(nobs_4e[0,50],nexp_4e)"); w.factory("Gaussian:constraint_4m(b0_4m[0,10],b_4m,sigmab_4m[1])"); w.factory("Gaussian:constraint_2e2m(b0_2e2m[0,10],b_2e2m,sigmab_2e2m[1])"); w.factory("Gaussian:constraint_4e(b0_4e[0,10],b_4e,sigmab_4e[1])"); w.factory("Gaussian:constraintAcc_4m(Acc0_4m[0,1],Acc_4m,sigmaAcc_4m[1])"); w.factory("Gaussian:constraintAcc_2e2m(Acc0_2e2m[0,1],Acc_2e2m,sigmaAcc_2e2m[1])"); w.factory("Gaussian:constraintAcc_4e(Acc0_4e[0,1],Acc_4e,sigmaAcc_4e[1])"); w.factory("PROD:model_4m(pdf_4m,constraint_4m,constraintAcc_4m)"); w.factory("PROD:model_2e2m(pdf_2e2m,constraint_2e2m,constraintAcc_2e2m)"); w.factory("PROD:model_4e(pdf_4e,constraint_4e,constraintAcc_4e)"); w.factory("PROD:model(model_4m,model_2e2m,model_4e)"); w.var("b0_4m")->setVal(b_4m); w.var("b0_2e2m")->setVal(b_2e2m); w.var("b0_4e")->setVal(b_4e); w.var("b0_4m")->setConstant(true); // needed for being treated as global observables w.var("b0_2e2m")->setConstant(true); // needed for being treated as global observables w.var("b0_4e")->setConstant(true); // needed for being treated as global observables // w.var("Acc_4m")->setVal(0.844); // w.var("Acc_2e2m")->setVal(0.694); // w.var("Acc_4e")->setVal(0.60); Float_t Acc_4m = 0.844*0.5388; Float_t Acc_2e2m = 0.694*0.5388; Float_t Acc_4e = 0.60*0.5388; // Float_t Acc_4m = 0.844; // Float_t Acc_2e2m = 0.694; // Float_t Acc_4e = 0.60; Float_t sigmaAcc_4m = 0.0097 ; Float_t sigmaAcc_2e2m = 0.0097 ; Float_t sigmaAcc_4e = 0.0097 ; Float_t BRele = 0.03363; Float_t BRmu = 0.03366; Float_t BR_4m = BRmu*BRmu; Float_t BR_2e2m = 2*BRmu*BRele; Float_t BR_4e = BRele*BRele; Float_t BR = BR_4m+BR_2e2m+BR_4e; cout<<"BR sum"<<BR<<" BRmean "<<(BR_4m + BR_4e + BR_2e2m)/3.<<" BR_4m "<<BR_4m<<" BR_2e2m "<<BR_2e2m<<" BR_4e "<<BR_4e<<endl; w.var("BR_4m")->setVal(BR_4m); w.var("BR_2e2m")->setVal(BR_2e2m); w.var("BR_4e")->setVal(BR_4e); w.var("BR_4m")->setConstant(true); // needed for being treated as global observables w.var("BR_2e2m")->setConstant(true); // needed for being treated as global observables w.var("BR_4e")->setConstant(true); // needed for being treated as global observables w.var("Lumi")->setVal(2.560); w.var("Lumi")->setConstant(true); w.var("sigmab_4m")->setVal(sigmab_4m*b_4m); w.var("sigmab_2e2m")->setVal(sigmab_2e2m*b_2e2m); w.var("sigmab_4e")->setVal(sigmab_4e*b_4e); w.var("sigmaAcc_4m")->setVal(sigmaAcc_4m*Acc_4m); w.var("sigmaAcc_2e2m")->setVal(sigmaAcc_2e2m*Acc_2e2m); w.var("sigmaAcc_4e")->setVal(sigmaAcc_4e*Acc_4e); ModelConfig mc("ModelConfig",&w); mc.SetPdf(*w.pdf("model")); mc.SetParametersOfInterest(*w.var("cross")); mc.SetObservables(RooArgSet(*w.var("nobs_4m"),*w.var("nobs_2e2m"),*w.var("nobs_4e"))); // mc.SetNuisanceParameters(RooArgSet(*w.var("b_4m"),*w.var("b_2e2m"),*w.var("b_4e"))); //mc.SetObservables(RooArgSet(*w.var("nobs_4m"),*w.var("nobs_2e2m"))); // mc.SetNuisanceParameters(RooArgSet(*w.var("b_4m"),*w.var("b_2e2m"),*w.var("Acc_4m"),*w.var("Acc_2e2m"))); mc.SetNuisanceParameters(RooArgSet(*w.var("b_4m"),*w.var("b_2e2m"),*w.var("b_4e"),*w.var("Acc_4m"),*w.var("Acc_2e2m"),*w.var("Acc_4e"))); mc.SetParametersOfInterest(*w.var("cross")); // these are needed for the hypothesis tests mc.SetSnapshot(*w.var("cross")); // mc.SetGlobalObservables(RooArgSet(*w.var("b0_4m"),*w.var("b0_2e2m"),*w.var("b0_4e"))); mc.Print(); // import model in the workspace w.import(mc); // make data set with the namber of observed events RooDataSet data("data","", RooArgSet(*w.var("nobs_4m"),*w.var("nobs_2e2m"),*w.var("nobs_4e"))); //RooDataSet data("data","", RooArgSet(*w.var("nobs_4m"),*w.var("nobs_2e2m"))); w.var("nobs_4m")->setVal(nobs_4m); data.add(*w.var("nobs_4m") ); w.var("nobs_2e2m")->setVal(nobs_2e2m); data.add(*w.var("nobs_2e2m") ); w.var("nobs_4e")->setVal(nobs_4e); data.add(*w.var("nobs_4e") ); // import data set in workspace and save it in a file ProfileLikelihoodCalculator pl(data, mc); pl.SetConfidenceLevel(0.68); // 95% interval LikelihoodInterval* interval = pl.GetInterval(); // print out the iterval on the first Parameter of Interest RooRealVar* firstPOI = (RooRealVar*) mc.GetParametersOfInterest()->first(); cout << "\n65% interval on " <<firstPOI->GetName()<<" is : ["<< interval->LowerLimit(*firstPOI) << ", "<< interval->UpperLimit(*firstPOI) <<"] "<<endl; std::cout<<"Cross "<<mc.GetParametersOfInterest()->getRealValue("cross")*BR<<std::endl; w.import(data); w.Print(); TString fileName = "CountingModel.root"; // write workspace in the file (recreate file if already existing) w.writeToFile(fileName, true); }