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 std::ofstream;
27
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gROOT
Definition TROOT.h:406
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Variable that can be changed from the outside.
Definition RooRealVar.h:37
HLFactory is an High Level model Factory allows you to describe your models in a configuration file (...
Definition HLFactory.h:29
Basic string class.
Definition TString.h:139
RooCmdArg Components(Args_t &&... argsOrArgSet)
RooCmdArg LineStyle(Style_t style)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
Namespace for the RooStats classes.
Definition Asimov.h:19
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345