Logo ROOT   6.16/01
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
28using namespace RooFit;
29using namespace RooStats;
30using namespace std;
31
32void 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}
@ kDashed
Definition: TAttLine.h:48
#define gROOT
Definition: TROOT.h:410
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
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
Create a new RooPlot on the heap with a drawing frame initialized for this object,...
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition: HLFactory.h:31
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooAbsArg * arg(const char *name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
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)
RooCmdArg LineStyle(Style_t style)
@(#)root/roostats:$Id$ Author: George Lewis, Kyle Cranmer
Definition: Asimov.h:20
STL namespace.
static long int sum(long int i)
Definition: Factory.cxx:2258