Zbi_Zgamma.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // Demonstraite Z_Bi = Z_Gamma
00004 // author: Kyle Cranmer & Wouter Verkerke
00005 // date May 2010
00006 //
00007 //
00008 /////////////////////////////////////////////////////////////////////////
00009 
00010 #ifndef __CINT__
00011 #include "RooGlobalFunc.h"
00012 #endif
00013 #include "RooRealVar.h"
00014 #include "RooProdPdf.h"
00015 #include "RooWorkspace.h"
00016 #include "RooDataSet.h"
00017 #include "TCanvas.h"
00018 #include "TH1.h"
00019 
00020 using namespace RooFit;
00021 using namespace RooStats;
00022 
00023 void Zbi_Zgamma() {
00024 
00025   // Make model for prototype on/off problem
00026   // Pois(x | s+b) * Pois(y | tau b )
00027   // for Z_Gamma, use uniform prior on b.
00028   RooWorkspace* w = new RooWorkspace("w",true);
00029   w->factory("Poisson::px(x[150,0,500],sum::splusb(s[0,0,100],b[100,0,300]))");
00030   w->factory("Poisson::py(y[100,0,500],prod::taub(tau[1.],b))");             
00031   w->factory("Uniform::prior_b(b)");
00032 
00033   // construct the Bayesian-averaged model (eg. a projection pdf)
00034   // p'(x|s) = \int db p(x|s+b) * [ p(y|b) * prior(b) ]
00035   w->factory("PROJ::averagedModel(PROD::foo(px|b,py,prior_b),b)") ;
00036 
00037   // plot it, blue is averaged model, red is b known exactly
00038   RooPlot* frame = w->var("x")->frame() ;
00039   w->pdf("averagedModel")->plotOn(frame) ;
00040   w->pdf("px")->plotOn(frame,LineColor(kRed)) ;
00041   frame->Draw() ;
00042 
00043   // compare analytic calculation of Z_Bi
00044   // with the numerical RooFit implementation of Z_Gamma
00045   // for an example with x = 150, y = 100
00046    
00047   // numeric RooFit Z_Gamma
00048   w->var("y")->setVal(100);
00049   w->var("x")->setVal(150);
00050   RooAbsReal* cdf = w->pdf("averagedModel")->createCdf(*w->var("x"));
00051   cdf->getVal(); // get ugly print messages out of the way
00052 
00053   cout << "Hybrid p-value = " << cdf->getVal() << endl;
00054   cout << "Z_Gamma Significance  = " << 
00055     PValueToSignificance(1-cdf->getVal()) << endl;
00056 
00057   // analytic Z_Bi
00058   double Z_Bi = NumberCountingUtils::BinomialWithTauObsZ(150, 100, 1);
00059   std::cout << "Z_Bi significance estimation: " << Z_Bi << std::endl;
00060 
00061   // OUTPUT
00062   // Hybrid p-value = 0.999058
00063   // Z_Gamma Significance  = 3.10804
00064   // Z_Bi significance estimation: 3.10804
00065 
00066 
00067 }

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