Logo ROOT   6.10/09
Reference Guide
rs601_HLFactoryexample.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roostats
3 /// \notebook -js
4 /// 'High Level Factory Example' RooStats tutorial macro #601
5 ///
6 /// This tutorial shows an example of creating a simple
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 rs601_HLFactoryexample() {
33 
34  // --- Build the datacard and dump to file---
35 
36  TString card_name("HLFavtoryexample.rs");
37  ofstream ofile(card_name);
38  ofile << "// The simplest card\n\n"
39  << "gauss = Gaussian(mes[5.20,5.30],mean[5.28,5.2,5.3],width[0.0027,0.001,1]);\n"
40  << "argus = ArgusBG(mes,5.291,argpar[-20,-100,-1]);\n"
41  << "sum = SUM(nsig[200,0,10000]*gauss,nbkg[800,0,10000]*argus);\n\n";
42 
43  ofile.close();
44 
45  HLFactory hlf("HLFavtoryexample",
46  card_name,
47  false);
48 
49  // --- Take elements out of the internal workspace ---
50 
51  RooWorkspace* w = hlf.GetWs();
52 
53  RooRealVar* mes = dynamic_cast<RooRealVar*>(w->arg("mes"));
54  RooAbsPdf* sum = dynamic_cast<RooAbsPdf*>(w->pdf("sum"));
55  RooAbsPdf* argus = dynamic_cast<RooAbsPdf*>(w->pdf("argus"));
56 // RooRealVar* mean = dynamic_cast<RooRealVar*>(w->arg("mean"));
57 // RooRealVar* argpar = dynamic_cast<RooRealVar*>(w->arg("argpar"));
58 
59  // --- Generate a toyMC sample from composite PDF ---
60  RooDataSet *data = sum->generate(*mes,2000) ;
61 
62  // --- Perform extended ML fit of composite PDF to toy data ---
63  sum->fitTo(*data) ;
64 
65  // --- Plot toy data and composite PDF overlaid ---
66  RooPlot* mesframe = mes->frame() ;
67  data->plotOn(mesframe) ;
68  sum->plotOn(mesframe) ;
69  sum->plotOn(mesframe,Components(*argus),LineStyle(kDashed)) ;
70 
71  gROOT->SetStyle("Plain");
72  mesframe->Draw() ;
73 }
static long int sum(long int i)
Definition: Factory.cxx:2162
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:552
#define gROOT
Definition: TROOT.h:375
RooAbsArg * arg(const char *name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
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
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition: HLFactory.h:31
RooCmdArg LineStyle(Style_t style)
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
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 * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCmdArg Components(const RooArgSet &compSet)
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: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