Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rs602_HLFactoryCombinationexample.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roostats
3/// \notebook
4/// High Level Factory: creation of a combined 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
28void rs602_HLFactoryCombinationexample()
29{
30 // create a card
31 TString card_name("HLFavtoryCombinationexample.rs");
32 ofstream ofile(card_name);
33 ofile << "// The simplest card for combination\n\n"
34 << "gauss1 = Gaussian(x[0,100],mean1[50,0,100],4);\n"
35 << "flat1 = Polynomial(x,0);\n"
36 << "sb_model1 = SUM(nsig1[120,0,300]*gauss1 , nbkg1[100,0,1000]*flat1);\n"
37 << "gauss2 = Gaussian(x,mean2[80,0,100],5);\n"
38 << "flat2 = Polynomial(x,0);\n"
39 << "sb_model2 = SUM(nsig2[90,0,400]*gauss2 , nbkg2[80,0,1000]*flat2);\n";
40
41 ofile.close();
42
43 HLFactory hlf("HLFavtoryCombinationexample", card_name, false);
44
45 hlf.AddChannel("model1", "sb_model1", "flat1");
46 hlf.AddChannel("model2", "sb_model2", "flat2");
47 auto pdf = hlf.GetTotSigBkgPdf();
48 auto thecat = hlf.GetTotCategory();
49 auto x = static_cast<RooRealVar *>(hlf.GetWs()->arg("x"));
50
51 auto data = pdf->generate(RooArgSet(*x, *thecat), Extended());
52
53 // --- Perform extended ML fit of composite PDF to toy data ---
54 pdf->fitTo(*data);
55
56 // --- Plot toy data and composite PDF overlaid ---
57 auto xframe = x->frame();
58
59 data->plotOn(xframe);
60 thecat->setIndex(0);
61 pdf->plotOn(xframe, Slice(*thecat), ProjWData(*thecat, *data));
62
63 thecat->setIndex(1);
64 pdf->plotOn(xframe, Slice(*thecat), ProjWData(*thecat, *data));
65
66 gROOT->SetStyle("Plain");
67 xframe->Draw();
68}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gROOT
Definition TROOT.h:406
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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 Extended(bool flag=true)
RooCmdArg ProjWData(const RooAbsData &projData, bool binData=false)
RooCmdArg Slice(const RooArgSet &sliceSet)
Double_t x[n]
Definition legend1.C:17
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