Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rs601_HLFactoryexample.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roostats
3/// \notebook -js
4/// 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
24using namespace RooFit;
25using namespace RooStats;
26using namespace std;
27
28void 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}
@ kDashed
Definition TAttLine.h:48
#define gROOT
Definition TROOT.h:406
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
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())
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition RooAbsPdf.h:58
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:691
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:39
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition HLFactory.h:31
Basic string class.
Definition TString.h:136
RooCmdArg Components(const RooArgSet &compSet)
RooCmdArg LineStyle(Style_t style)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Namespace for the RooStats classes.
Definition Asimov.h:19
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345