Logo ROOT   6.14/05
Reference Guide
rs602_HLFactoryCombinationexample.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roostats
3 /// \notebook
4 /// 'High Level Factory Example' RooStats tutorial macro #602
5 ///
6 /// This tutorial shows an example of creating a combined
7 /// model using the High Level model Factory.
8 ///
9 /// \macro_image
10 /// \macro_output
11 /// \macro_code
12 ///
13 /// \author Danilo Piparo
14 
15 #include <fstream>
16 #include "TString.h"
17 #include "TROOT.h"
18 #include "RooGlobalFunc.h"
19 #include "RooWorkspace.h"
20 #include "RooRealVar.h"
21 #include "RooAbsPdf.h"
22 #include "RooDataSet.h"
23 #include "RooPlot.h"
24 #include "RooStats/HLFactory.h"
25 
26 
27 // use this order for safety on library loading
28 using namespace RooFit;
29 using namespace RooStats;
30 using namespace std;
31 
32 void rs602_HLFactoryCombinationexample() {
33 
34  using namespace RooStats;
35  using namespace RooFit;
36 
37  // create a card
38  TString card_name("HLFavtoryCombinationexample.rs");
39  ofstream ofile(card_name);
40  ofile << "// The simplest card for combination\n\n"
41  << "gauss1 = Gaussian(x[0,100],mean1[50,0,100],4);\n"
42  << "flat1 = Polynomial(x,0);\n"
43  << "sb_model1 = SUM(nsig1[120,0,300]*gauss1 , nbkg1[100,0,1000]*flat1);\n"
44  << "gauss2 = Gaussian(x,mean2[80,0,100],5);\n"
45  << "flat2 = Polynomial(x,0);\n"
46  << "sb_model2 = SUM(nsig2[90,0,400]*gauss2 , nbkg2[80,0,1000]*flat2);\n";
47 
48  ofile.close();
49 
50  HLFactory hlf("HLFavtoryCombinationexample",
51  card_name,
52  false);
53 
54  hlf.AddChannel("model1","sb_model1","flat1");
55  hlf.AddChannel("model2","sb_model2","flat2");
56  RooAbsPdf* pdf=hlf.GetTotSigBkgPdf();
57  RooCategory* thecat = hlf.GetTotCategory();
58  RooRealVar* x= static_cast<RooRealVar*>(hlf.GetWs()->arg("x"));
59 
60  RooDataSet* data = pdf->generate(RooArgSet(*x,*thecat),Extended());
61 
62  // --- Perform extended ML fit of composite PDF to toy data ---
63  pdf->fitTo(*data) ;
64 
65  // --- Plot toy data and composite PDF overlaid ---
66  RooPlot* xframe = x->frame() ;
67 
68  data->plotOn(xframe);
69  thecat->setIndex(0);
70  pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;
71 
72  thecat->setIndex(1);
73  pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;
74 
75  gROOT->SetStyle("Plain");
76  xframe->Draw();
77 }
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:568
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)
Set value by specifying the index code of the desired state.
#define gROOT
Definition: TROOT.h:410
RooCmdArg ProjWData(const RooAbsData &projData, Bool_t binData=kFALSE)
STL namespace.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none(), const RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Plot (project) PDF on specified frame.
Definition: RooAbsPdf.h:105
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:31
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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:24
RooPlot * frame(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
Namespace for the RooStats classes.
Definition: Asimov.h:20
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
Generate a new dataset containing the specified variables with events sampled from our distribution...
Definition: RooAbsPdf.cxx:1725
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1079
RooCmdArg Slice(const RooArgSet &sliceSet)
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558