ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rs601_HLFactoryexample.C
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'High Level Factory Example' RooStats tutorial macro #601
4 // author: Danilo Piparo
5 // date August. 2009
6 //
7 // This tutorial shows an example of creating a simple
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 // use this order for safety on library loading
26 using namespace RooFit ;
27 using namespace RooStats ;
28 using namespace std;
29 
31 
32  // --- Build the datacard and dump to file---
33 
34  TString card_name("HLFavtoryexample.rs");
35  ofstream ofile(card_name);
36  ofile << "// The simplest card\n\n"
37  << "gauss = Gaussian(mes[5.20,5.30],mean[5.28,5.2,5.3],width[0.0027,0.001,1]);\n"
38  << "argus = ArgusBG(mes,5.291,argpar[-20,-100,-1]);\n"
39  << "sum = SUM(nsig[200,0,10000]*gauss,nbkg[800,0,10000]*argus);\n\n";
40 
41  ofile.close();
42 
43  HLFactory hlf("HLFavtoryexample",
44  card_name,
45  false);
46 
47  // --- Take elements out of the internal workspace ---
48 
49  RooWorkspace* w = hlf.GetWs();
50 
51  RooRealVar* mes = dynamic_cast<RooRealVar*>(w->arg("mes"));
52  RooAbsPdf* sum = dynamic_cast<RooAbsPdf*>(w->pdf("sum"));
53  RooAbsPdf* argus = dynamic_cast<RooAbsPdf*>(w->pdf("argus"));
54 // RooRealVar* mean = dynamic_cast<RooRealVar*>(w->arg("mean"));
55 // RooRealVar* argpar = dynamic_cast<RooRealVar*>(w->arg("argpar"));
56 
57  // --- Generate a toyMC sample from composite PDF ---
58  RooDataSet *data = sum->generate(*mes,2000) ;
59 
60  // --- Perform extended ML fit of composite PDF to toy data ---
61  sum->fitTo(*data) ;
62 
63  // --- Plot toy data and composite PDF overlaid ---
64  RooPlot* mesframe = mes->frame() ;
65  data->plotOn(mesframe) ;
66  sum->plotOn(mesframe) ;
67  sum->plotOn(mesframe,Components(*argus),LineStyle(kDashed)) ;
68 
69  gROOT->SetStyle("Plain");
70  mesframe->Draw() ;
71 }
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
void rs601_HLFactoryexample()
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition: HLFactory.h:41
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCmdArg LineStyle(Style_t style)
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:626
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
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
tuple w
Definition: qtexample.py:51
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
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooCmdArg Components(const RooArgSet &compSet)
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.
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:1702
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:1056
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559