Logo ROOT  
Reference Guide
HybridOriginalDemo.C File Reference

Detailed Description

Example on how to use the HybridCalculatorOriginal class.

View in nbviewer Open in SWAN With this example, you should get: CL_sb = 0.130 and CL_b = 0.946 (if data had -2lnQ = -3.0742).

RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
Test statistics has been evaluated for data
HybridCalculatorOriginal: run 1000 toy-MC experiments
with test statistics index: 1
marginalize nuisance parameters
....... toy number 0 / 1000
....... toy number 500 / 1000
Completed HybridCalculatorOriginal example:
- -2lnQ = -5.97789
- CL_sb = 0.194
- CL_b = 0.04
- CL_s = 4.85
- significance of data = 1.75069
- mean significance of toys = 2.65207
#include "RooRandom.h"
#include "RooRealVar.h"
#include "RooGaussian.h"
#include "RooPolynomial.h"
#include "RooArgSet.h"
#include "RooAddPdf.h"
#include "RooDataSet.h"
#include "RooExtendPdf.h"
#include "RooConstVar.h"
void HybridOriginalDemo(int ntoys = 1000)
{
using namespace RooFit;
using namespace RooStats;
// set RooFit random seed
/// build the models for background and signal+background
RooRealVar x("x", "", -3, 3);
RooArgList observables(x); // variables to be generated
// gaussian signal
RooGaussian sig_pdf("sig_pdf", "", x, RooConst(0.0), RooConst(0.8));
RooRealVar sig_yield("sig_yield", "", 20, 0, 300);
// flat background (extended PDF)
RooPolynomial bkg_pdf("bkg_pdf", "", x, RooConst(0));
RooRealVar bkg_yield("bkg_yield", "", 40, 0, 300);
RooExtendPdf bkg_ext_pdf("bkg_ext_pdf", "", bkg_pdf, bkg_yield);
// bkg_yield.setConstant(kTRUE);
sig_yield.setConstant(kTRUE);
// total sig+bkg (extended PDF)
RooAddPdf tot_pdf("tot_pdf", "", RooArgList(sig_pdf, bkg_pdf), RooArgList(sig_yield, bkg_yield));
// build the prior PDF on the parameters to be integrated
// gaussian contraint on the background yield ( N_B = 40 +/- 10 ie. 25% )
RooGaussian bkg_yield_prior("bkg_yield_prior", "", bkg_yield, RooConst(bkg_yield.getVal()), RooConst(10.));
RooArgSet nuisance_parameters(bkg_yield); // variables to be integrated
/// generate a data sample
RooDataSet *data = tot_pdf.generate(observables, RooFit::Extended());
// run HybridCalculator on those inputs
// use interface from HypoTest calculator by default
HybridCalculatorOriginal myHybridCalc(*data, tot_pdf, bkg_ext_pdf, &nuisance_parameters, &bkg_yield_prior);
// here I use the default test statistics: 2*lnQ (optional)
myHybridCalc.SetTestStatistic(1);
// myHybridCalc.SetTestStatistic(3); // profile likelihood ratio
myHybridCalc.SetNumberOfToys(ntoys);
myHybridCalc.UseNuisance(true);
// for speed up generation (do binned data)
myHybridCalc.SetGenerateBinned(false);
// calculate by running ntoys for the S+B and B hypothesis and retrieve the result
HybridResult *myHybridResult = myHybridCalc.GetHypoTest();
if (!myHybridResult) {
std::cerr << "\nError returned from Hypothesis test" << std::endl;
return;
}
/// nice plot of the results
HybridPlot *myHybridPlot =
myHybridResult->GetPlot("myHybridPlot", "Plot of results with HybridCalculatorOriginal", 100);
myHybridPlot->Draw();
/// recover and display the results
double clsb_data = myHybridResult->CLsplusb();
double clb_data = myHybridResult->CLb();
double cls_data = myHybridResult->CLs();
double data_significance = myHybridResult->Significance();
double min2lnQ_data = myHybridResult->GetTestStat_data();
/// compute the mean expected significance from toys
double mean_sb_toys_test_stat = myHybridPlot->GetSBmean();
myHybridResult->SetDataTestStatistics(mean_sb_toys_test_stat);
double toys_significance = myHybridResult->Significance();
std::cout << "Completed HybridCalculatorOriginal example:\n";
std::cout << " - -2lnQ = " << min2lnQ_data << endl;
std::cout << " - CL_sb = " << clsb_data << std::endl;
std::cout << " - CL_b = " << clb_data << std::endl;
std::cout << " - CL_s = " << cls_data << std::endl;
std::cout << " - significance of data = " << data_significance << std::endl;
std::cout << " - mean significance of toys = " << toys_significance << std::endl;
}
Author
Gregory Schott

Definition in file HybridOriginalDemo.C.

RooStats::HypoTestResult::Significance
virtual Double_t Significance() const
familiar name for the Null p-value in terms of 1-sided Gaussian significance
Definition: HypoTestResult.h:80
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
HybridCalculatorOriginal.h
RooAddPdf
Definition: RooAddPdf.h:32
RooExtendPdf.h
RooArgSet.h
RooStats::HybridResult::GetTestStat_data
double GetTestStat_data()
Get test statistics value for data.
Definition: HybridResult.h:70
RooArgList
Definition: RooArgList.h:21
RooGaussian.h
RooExtendPdf
Definition: RooExtendPdf.h:22
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
RooAddPdf.h
RooDataSet.h
RooStats::HybridPlot
Definition: HybridPlot.h:36
RooPolynomial.h
RooFit
Definition: RooCFunction1Binding.h:29
RooPolynomial
Definition: RooPolynomial.h:28
RooRandom.h
TRandom::SetSeed
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:597
RooStats::HybridResult::GetPlot
HybridPlot * GetPlot(const char *name, const char *title, int n_bins)
prepare a plot showing a result and return a pointer to a HybridPlot object the needed arguments are:...
Definition: HybridResult.cxx:253
RooRealVar.h
HybridPlot.h
RooConstVar.h
RooStats
Definition: Asimov.h:19
RooStats::HypoTestResult::CLs
virtual Double_t CLs() const
is simply (not a method, but a quantity)
Definition: HypoTestResult.h:69
HybridResult.h
RooStats::HybridResult
Definition: HybridResult.h:38
RooDataSet
Definition: RooDataSet.h:33
RooStats::HybridPlot::Draw
void Draw(const char *options="")
Draw on current pad.
Definition: HybridPlot.cxx:138
RooRandom::randomGenerator
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
RooStats::HybridResult::SetDataTestStatistics
void SetDataTestStatistics(double testStat_data_val)
set the value of the test statistics on data
Definition: HybridResult.cxx:108
RooRealVar
Definition: RooRealVar.h:36
RooStats::HypoTestResult::CLsplusb
virtual Double_t CLsplusb() const
Convert AlternatePValue into a "confidence level".
Definition: HypoTestResult.h:66
RooStats::HybridPlot::GetSBmean
double GetSBmean()
Get SB histo mean.
Definition: HybridPlot.h:77
RooStats::HybridCalculatorOriginal
Definition: HybridCalculatorOriginal.h:34
RooArgSet
Definition: RooArgSet.h:28
RooStats::HypoTestResult::CLb
virtual Double_t CLb() const
Convert NullPValue into a "confidence level".
Definition: HypoTestResult.h:63
RooFit::Extended
RooCmdArg Extended(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:155
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:341