ROOT logo

From $ROOTSYS/tutorials/roostats/rs602_HLFactoryCombinationexample.C

/////////////////////////////////////////////////////////////////////////
//
// 'High Level Factory Example' RooStats tutorial macro #602
// author: Danilo Piparo
// date August. 2009
//
// This tutorial shows an example of creating a combined
// model using the High Level model Factory.
//
//
/////////////////////////////////////////////////////////////////////////

#include <fstream>
#include "TString.h"
#include "TROOT.h"
#include "RooGlobalFunc.h"
#include "RooWorkspace.h"
#include "RooRealVar.h"
#include "RooAbsPdf.h"
#include "RooDataSet.h"
#include "RooPlot.h"
#include "RooStats/HLFactory.h"



// use this order for safety on library loading
using namespace RooFit ;
using namespace RooStats ;
using namespace std;

void rs602_HLFactoryCombinationexample() {

using namespace RooStats;
using namespace RooFit;

// create a card
TString card_name("HLFavtoryCombinationexample.rs");
ofstream ofile(card_name);
ofile << "// The simplest card for combination\n\n"
      << "gauss1 = Gaussian(x[0,100],mean1[50,0,100],4);\n"
      << "flat1 = Polynomial(x,0);\n"
      << "sb_model1 = SUM(nsig1[120,0,300]*gauss1 , nbkg1[100,0,1000]*flat1);\n"
      << "gauss2 = Gaussian(x,mean2[80,0,100],5);\n"
      << "flat2 = Polynomial(x,0);\n"
      << "sb_model2 = SUM(nsig2[90,0,400]*gauss2 , nbkg2[80,0,1000]*flat2);\n";

ofile.close();

HLFactory hlf("HLFavtoryCombinationexample",
              card_name,
              false);

hlf.AddChannel("model1","sb_model1","flat1");
hlf.AddChannel("model2","sb_model2","flat2");
RooAbsPdf* pdf=hlf.GetTotSigBkgPdf();
RooCategory* thecat = hlf.GetTotCategory();
RooRealVar* x= static_cast<RooRealVar*>(hlf.GetWs()->arg("x"));

RooDataSet* data = pdf->generate(RooArgSet(*x,*thecat),Extended());

// --- Perform extended ML fit of composite PDF to toy data ---
pdf->fitTo(*data) ;

// --- Plot toy data and composite PDF overlaid ---
RooPlot* xframe = x->frame() ;

data->plotOn(xframe);
thecat->setIndex(0);
pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;

thecat->setIndex(1);
pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ;

gROOT->SetStyle("Plain");
xframe->Draw();
}
 rs602_HLFactoryCombinationexample.C:1
 rs602_HLFactoryCombinationexample.C:2
 rs602_HLFactoryCombinationexample.C:3
 rs602_HLFactoryCombinationexample.C:4
 rs602_HLFactoryCombinationexample.C:5
 rs602_HLFactoryCombinationexample.C:6
 rs602_HLFactoryCombinationexample.C:7
 rs602_HLFactoryCombinationexample.C:8
 rs602_HLFactoryCombinationexample.C:9
 rs602_HLFactoryCombinationexample.C:10
 rs602_HLFactoryCombinationexample.C:11
 rs602_HLFactoryCombinationexample.C:12
 rs602_HLFactoryCombinationexample.C:13
 rs602_HLFactoryCombinationexample.C:14
 rs602_HLFactoryCombinationexample.C:15
 rs602_HLFactoryCombinationexample.C:16
 rs602_HLFactoryCombinationexample.C:17
 rs602_HLFactoryCombinationexample.C:18
 rs602_HLFactoryCombinationexample.C:19
 rs602_HLFactoryCombinationexample.C:20
 rs602_HLFactoryCombinationexample.C:21
 rs602_HLFactoryCombinationexample.C:22
 rs602_HLFactoryCombinationexample.C:23
 rs602_HLFactoryCombinationexample.C:24
 rs602_HLFactoryCombinationexample.C:25
 rs602_HLFactoryCombinationexample.C:26
 rs602_HLFactoryCombinationexample.C:27
 rs602_HLFactoryCombinationexample.C:28
 rs602_HLFactoryCombinationexample.C:29
 rs602_HLFactoryCombinationexample.C:30
 rs602_HLFactoryCombinationexample.C:31
 rs602_HLFactoryCombinationexample.C:32
 rs602_HLFactoryCombinationexample.C:33
 rs602_HLFactoryCombinationexample.C:34
 rs602_HLFactoryCombinationexample.C:35
 rs602_HLFactoryCombinationexample.C:36
 rs602_HLFactoryCombinationexample.C:37
 rs602_HLFactoryCombinationexample.C:38
 rs602_HLFactoryCombinationexample.C:39
 rs602_HLFactoryCombinationexample.C:40
 rs602_HLFactoryCombinationexample.C:41
 rs602_HLFactoryCombinationexample.C:42
 rs602_HLFactoryCombinationexample.C:43
 rs602_HLFactoryCombinationexample.C:44
 rs602_HLFactoryCombinationexample.C:45
 rs602_HLFactoryCombinationexample.C:46
 rs602_HLFactoryCombinationexample.C:47
 rs602_HLFactoryCombinationexample.C:48
 rs602_HLFactoryCombinationexample.C:49
 rs602_HLFactoryCombinationexample.C:50
 rs602_HLFactoryCombinationexample.C:51
 rs602_HLFactoryCombinationexample.C:52
 rs602_HLFactoryCombinationexample.C:53
 rs602_HLFactoryCombinationexample.C:54
 rs602_HLFactoryCombinationexample.C:55
 rs602_HLFactoryCombinationexample.C:56
 rs602_HLFactoryCombinationexample.C:57
 rs602_HLFactoryCombinationexample.C:58
 rs602_HLFactoryCombinationexample.C:59
 rs602_HLFactoryCombinationexample.C:60
 rs602_HLFactoryCombinationexample.C:61
 rs602_HLFactoryCombinationexample.C:62
 rs602_HLFactoryCombinationexample.C:63
 rs602_HLFactoryCombinationexample.C:64
 rs602_HLFactoryCombinationexample.C:65
 rs602_HLFactoryCombinationexample.C:66
 rs602_HLFactoryCombinationexample.C:67
 rs602_HLFactoryCombinationexample.C:68
 rs602_HLFactoryCombinationexample.C:69
 rs602_HLFactoryCombinationexample.C:70
 rs602_HLFactoryCombinationexample.C:71
 rs602_HLFactoryCombinationexample.C:72
 rs602_HLFactoryCombinationexample.C:73
 rs602_HLFactoryCombinationexample.C:74
 rs602_HLFactoryCombinationexample.C:75
 rs602_HLFactoryCombinationexample.C:76
 rs602_HLFactoryCombinationexample.C:77