rs801_HypoTestInverter.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'Hypothesis Test Inversion' RooStats tutorial macro #801
00004 // author: Gregory Schott
00005 // date Sep 2009
00006 //
00007 // This tutorial shows an example of using the HypoTestInverter class 
00008 //
00009 /////////////////////////////////////////////////////////////////////////
00010 
00011 #include "RooRealVar.h"
00012 #include "RooConstVar.h"
00013 #include "RooProdPdf.h"
00014 #include "RooWorkspace.h"
00015 #include "RooDataSet.h"
00016 #include "RooPolynomial.h"
00017 #include "RooAddPdf.h"
00018 #include "RooExtendPdf.h"
00019 
00020 #include "RooStats/HypoTestInverter.h"
00021 #include "RooStats/HypoTestInverterResult.h"
00022 #include "RooStats/HypoTestInverterPlot.h"
00023 #include "RooStats/HybridCalculatorOriginal.h"
00024 
00025 #include "TGraphErrors.h"
00026 
00027 using namespace RooFit;
00028 using namespace RooStats;
00029 
00030 
00031 void rs801_HypoTestInverter()
00032 {
00033   // prepare the model
00034   RooRealVar lumi("lumi","luminosity",1);
00035   RooRealVar r("r","cross-section ratio",3.74,0,50);
00036   RooFormulaVar ns("ns","1*r*lumi",RooArgList(lumi,r));
00037   RooRealVar nb("nb","background yield",1);
00038   RooRealVar x("x","dummy observable",0,1);
00039   RooConstVar p0(RooFit::RooConst(0));
00040   RooPolynomial flatPdf("flatPdf","flat PDF",x,p0);
00041   RooAddPdf totPdf("totPdf","S+B model",RooArgList(flatPdf,flatPdf),RooArgList(ns,nb));
00042   RooExtendPdf bkgPdf("bkgPdf","B-only model",flatPdf,nb);
00043   RooDataSet* data = totPdf.generate(x,1);
00044 
00045   // prepare the calculator
00046   HybridCalculatorOriginal myhc(*data, totPdf, bkgPdf,0,0);
00047   myhc.SetTestStatistic(2);
00048   myhc.SetNumberOfToys(1000);
00049   myhc.UseNuisance(false);                            
00050 
00051   // run the hypothesis-test invertion
00052   HypoTestInverter myInverter(myhc,r);
00053   myInverter.SetTestSize(0.10);
00054   myInverter.UseCLs(true);
00055   // myInverter.RunFixedScan(5,1,6);
00056   // scan for a 95% UL
00057   myInverter.RunAutoScan(3.,5,myInverter.Size()/2,0.005);  
00058   // run an alternative autoscan algorithm 
00059   // myInverter.RunAutoScan(1,6,myInverter.Size()/2,0.005,1);  
00060   //myInverter.RunOnePoint(3.9);
00061 
00062 
00063   HypoTestInverterResult* results = myInverter.GetInterval();
00064 
00065   HypoTestInverterPlot myInverterPlot("myInverterPlot","",results);
00066   TGraphErrors* gr1 = myInverterPlot.MakePlot();
00067   gr1->Draw("ALP");
00068 
00069   double ulError = results->UpperLimitEstimatedError();
00070 
00071   double upperLimit = results->UpperLimit();
00072   std::cout << "The computed upper limit is: " << upperLimit << std::endl;
00073   std::cout << "an estimated error on this upper limit is: " << ulError << std::endl;
00074   // expected result: 4.10
00075 }
00076 int main() { 
00077    rs801_HypoTestInverter();
00078 }

Generated on Tue Jul 5 15:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1