Logo ROOT  
Reference Guide
rs601_HLFactoryexample.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roostats
3 /// \notebook -js
4 /// \brief High Level Factory: creation of a simple model
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \author Danilo Piparo
11 
12 #include <fstream>
13 #include "TString.h"
14 #include "TROOT.h"
15 #include "RooGlobalFunc.h"
16 #include "RooWorkspace.h"
17 #include "RooRealVar.h"
18 #include "RooAbsPdf.h"
19 #include "RooDataSet.h"
20 #include "RooPlot.h"
21 #include "RooStats/HLFactory.h"
22 
23 // use this order for safety on library loading
24 using namespace RooFit;
25 using namespace RooStats;
26 using namespace std;
27 
28 void rs601_HLFactoryexample()
29 {
30 
31  // --- Build the datacard and dump to file---
32 
33  TString card_name("HLFavtoryexample.rs");
34  ofstream ofile(card_name);
35  ofile << "// The simplest card\n\n"
36  << "gauss = Gaussian(mes[5.20,5.30],mean[5.28,5.2,5.3],width[0.0027,0.001,1]);\n"
37  << "argus = ArgusBG(mes,5.291,argpar[-20,-100,-1]);\n"
38  << "sum = SUM(nsig[200,0,10000]*gauss,nbkg[800,0,10000]*argus);\n\n";
39 
40  ofile.close();
41 
42  HLFactory hlf("HLFavtoryexample", card_name, false);
43 
44  // --- Take elements out of the internal workspace ---
45 
46  auto w = hlf.GetWs();
47 
48  auto mes = dynamic_cast<RooRealVar *>(w->arg("mes"));
49  auto sum = dynamic_cast<RooAbsPdf *>(w->pdf("sum"));
50  auto argus = dynamic_cast<RooAbsPdf *>(w->pdf("argus"));
51 
52  // --- Generate a toyMC sample from composite PDF ---
53  auto data = sum->generate(*mes, 2000);
54 
55  // --- Perform extended ML fit of composite PDF to toy data ---
56  sum->fitTo(*data);
57 
58  // --- Plot toy data and composite PDF overlaid ---
59  auto mesframe = mes->frame();
60  data->plotOn(mesframe);
61  sum->plotOn(mesframe);
62  sum->plotOn(mesframe, Components(*argus), LineStyle(kDashed));
63 
64  gROOT->SetStyle("Plain");
65  mesframe->Draw();
66 }
HLFactory.h
RooWorkspace.h
RooStats::HLFactory
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition: HLFactory.h:31
TString
Basic string class.
Definition: TString.h:136
RooDataSet.h
TString.h
TROOT.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooAbsPdf.h
RooPlot.h
RooRealVar.h
RooGlobalFunc.h
sum
static long int sum(long int i)
Definition: Factory.cxx:2272
RooStats
Namespace for the RooStats classes.
Definition: Asimov.h:19
kDashed
@ kDashed
Definition: TAttLine.h:48
RooAbsPdf
Definition: RooAbsPdf.h:40
RooFit::LineStyle
RooCmdArg LineStyle(Style_t style)
Definition: RooGlobalFunc.cxx:57
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:36
RooFit::Components
RooCmdArg Components(const RooArgSet &compSet)
Definition: RooGlobalFunc.cxx:74
gROOT
#define gROOT
Definition: TROOT.h:406