rs602_HLFactoryCombinationexample.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'High Level Factory Example' RooStats tutorial macro #602
00004 // author: Danilo Piparo
00005 // date August. 2009
00006 //
00007 // This tutorial shows an example of creating a combined
00008 // model using the High Level model Factory.
00009 //
00010 //
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #include <fstream>
00014 #include "TString.h"
00015 #include "TROOT.h"
00016 #include "RooGlobalFunc.h"
00017 #include "RooWorkspace.h"
00018 #include "RooRealVar.h"
00019 #include "RooAbsPdf.h"
00020 #include "RooDataSet.h"
00021 #include "RooPlot.h"
00022 #include "RooStats/HLFactory.h"
00023 
00024 
00025 
00026 // use this order for safety on library loading
00027 using namespace RooFit ;
00028 using namespace RooStats ;
00029 using namespace std;
00030 
00031 void rs602_HLFactoryCombinationexample() {
00032 
00033 using namespace RooStats;
00034 using namespace RooFit;
00035 
00036 // create a card
00037 TString card_name("HLFavtoryCombinationexample.rs");
00038 ofstream ofile(card_name);
00039 ofile << "// The simplest card for combination\n\n"
00040       << "gauss1 = Gaussian(x[0,100],mean1[50,0,100],4);\n"
00041       << "flat1 = Polynomial(x,0);\n"
00042       << "sb_model1 = SUM(nsig1[120,0,300]*gauss1 , nbkg1[100,0,1000]*flat1);\n"
00043       << "gauss2 = Gaussian(x,mean2[80,0,100],5);\n"
00044       << "flat2 = Polynomial(x,0);\n"
00045       << "sb_model2 = SUM(nsig2[90,0,400]*gauss2 , nbkg2[80,0,1000]*flat2);\n";
00046 
00047 ofile.close();
00048 
00049 HLFactory hlf("HLFavtoryCombinationexample",
00050               card_name,
00051               false);
00052 
00053 hlf.AddChannel("model1","sb_model1","flat1");
00054 hlf.AddChannel("model2","sb_model2","flat2");
00055 RooAbsPdf* pdf=hlf.GetTotSigBkgPdf();
00056 RooCategory* thecat = hlf.GetTotCategory();
00057 RooRealVar* x= static_cast<RooRealVar*>(hlf.GetWs()->arg("x"));
00058 
00059 RooDataSet* data = pdf->generate(RooArgSet(*x,*thecat),Extended());
00060 
00061 // --- Perform extended ML fit of composite PDF to toy data ---
00062 pdf->fitTo(*data) ;
00063 
00064 // --- Plot toy data and composite PDF overlaid ---
00065 RooPlot* xframe = x->frame() ;
00066 
00067 data->plotOn(xframe);
00068 thecat->setIndex(0);
00069 pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;
00070 
00071 thecat->setIndex(1);
00072 pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;
00073 
00074 gROOT->SetStyle("Plain");
00075 xframe->Draw();
00076 }

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