ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rs602_HLFactoryCombinationexample.C
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'High Level Factory Example' RooStats tutorial macro #602
4 // author: Danilo Piparo
5 // date August. 2009
6 //
7 // This tutorial shows an example of creating a combined
8 // model using the High Level model Factory.
9 //
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #include <fstream>
14 #include "TString.h"
15 #include "TROOT.h"
16 #include "RooGlobalFunc.h"
17 #include "RooWorkspace.h"
18 #include "RooRealVar.h"
19 #include "RooAbsPdf.h"
20 #include "RooDataSet.h"
21 #include "RooPlot.h"
22 #include "RooStats/HLFactory.h"
23 
24 
25 
26 // use this order for safety on library loading
27 using namespace RooFit ;
28 using namespace RooStats ;
29 using namespace std;
30 
32 
33 using namespace RooStats;
34 using namespace RooFit;
35 
36 // create a card
37 TString card_name("HLFavtoryCombinationexample.rs");
38 ofstream ofile(card_name);
39 ofile << "// The simplest card for combination\n\n"
40  << "gauss1 = Gaussian(x[0,100],mean1[50,0,100],4);\n"
41  << "flat1 = Polynomial(x,0);\n"
42  << "sb_model1 = SUM(nsig1[120,0,300]*gauss1 , nbkg1[100,0,1000]*flat1);\n"
43  << "gauss2 = Gaussian(x,mean2[80,0,100],5);\n"
44  << "flat2 = Polynomial(x,0);\n"
45  << "sb_model2 = SUM(nsig2[90,0,400]*gauss2 , nbkg2[80,0,1000]*flat2);\n";
46 
47 ofile.close();
48 
49 HLFactory hlf("HLFavtoryCombinationexample",
50  card_name,
51  false);
52 
53 hlf.AddChannel("model1","sb_model1","flat1");
54 hlf.AddChannel("model2","sb_model2","flat2");
55 RooAbsPdf* pdf=hlf.GetTotSigBkgPdf();
56 RooCategory* thecat = hlf.GetTotCategory();
57 RooRealVar* x= static_cast<RooRealVar*>(hlf.GetWs()->arg("x"));
58 
59 RooDataSet* data = pdf->generate(RooArgSet(*x,*thecat),Extended());
60 
61 // --- Perform extended ML fit of composite PDF to toy data ---
62 pdf->fitTo(*data) ;
63 
64 // --- Plot toy data and composite PDF overlaid ---
65 RooPlot* xframe = x->frame() ;
66 
67 data->plotOn(xframe);
68 thecat->setIndex(0);
69 pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;
70 
71 thecat->setIndex(1);
72 pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;
73 
74 gROOT->SetStyle("Plain");
75 xframe->Draw();
76 }
int AddChannel(const char *label, const char *SigBkgPdfName, const char *BkgPdfName=0, const char *datasetName=0)
Add channel for the combination.
Definition: HLFactory.cxx:131
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
RooCmdArg ProjWData(const RooAbsData &projData, Bool_t binData=kFALSE)
RooCmdArg Extended(Bool_t flag=kTRUE)
Double_t x[n]
Definition: legend1.C:17
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition: HLFactory.h:41
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:25
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
void rs602_HLFactoryCombinationexample()
RooCategory * GetTotCategory()
Get the combined dataset.
Definition: HLFactory.cxx:332
RooWorkspace * GetWs()
Get the RooWorkspace containing the models and variables.
Definition: HLFactory.h:84
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooAbsArg * arg(const char *name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
RooAbsPdf * GetTotSigBkgPdf()
Get the combined signal plus background pdf.
Definition: HLFactory.cxx:180
RooCmdArg Slice(const RooArgSet &sliceSet)