ROOT logo
/////////////////////////////////////////////////////////////////////////
//
// 'VALIDATION AND MC STUDIES' RooFit tutorial macro #803
// 
// RooMCStudy: Using the randomizer and profile likelihood add-on models
//
// 
// 07/2008 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooMCStudy.h"
#include "RooRandomizeParamMCSModule.h"
#include "RooDLLSignificanceMCSModule.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
#include "TDirectory.h"

using namespace RooFit ;


void rf803_mcstudy_addons2()
{
  // C r e a t e   m o d e l 
  // -----------------------

  // Simulation of signal and background of top quark decaying into
  // 3 jets with background

  // Observable
  RooRealVar mjjj("mjjj","m(3jet) (GeV)",100,85.,350.) ;

  // Signal component (Gaussian)
  RooRealVar mtop("mtop","m(top)",162) ;
  RooRealVar wtop("wtop","m(top) resolution",15.2) ;
  RooGaussian sig("sig","top signal",mjjj,mtop,wtop) ;

  // Background component (Chebychev)
  RooRealVar c0("c0","Chebychev coefficient 0",-0.846,-1.,1.) ;
  RooRealVar c1("c1","Chebychev coefficient 1", 0.112,-1.,1.) ;
  RooRealVar c2("c2","Chebychev coefficient 2", 0.076,-1.,1.) ;
  RooChebychev bkg("bkg","combinatorial background",mjjj,RooArgList(c0,c1,c2)) ;

  // Composite model
  RooRealVar nsig("nsig","number of signal events",53,0,1e3) ;
  RooRealVar nbkg("nbkg","number of background events",103,0,5e3) ;
  RooAddPdf model("model","model",RooArgList(sig,bkg),RooArgList(nsig,nbkg)) ;



  // C r e a t e   m a n a g e r
  // ---------------------------

  // Configure manager to perform binned extended likelihood fits (Binned(),Extended()) on data generated
  // with a Poisson fluctuation on Nobs (Extended())
  RooMCStudy* mcs = new RooMCStudy(model,mjjj,Binned(),Silence(),Extended(kTRUE),
				   FitOptions(Extended(kTRUE),PrintEvalErrors(-1))) ;



  // C u s t o m i z e   m a n a g e r
  // ---------------------------------

  // Add module that randomizes the summed value of nsig+nbkg 
  // sampling from a uniform distribution between 0 and 1000
  //
  // In general one can randomize a single parameter, or a 
  // sum of N parameters, using either a uniform or a Gaussian
  // distribution. Multiple randomization can be executed
  // by a single randomizer module
  
  RooRandomizeParamMCSModule randModule ;
  randModule.sampleSumUniform(RooArgSet(nsig,nbkg),50,500) ;
  mcs->addModule(randModule) ;  


  // Add profile likelihood calculation of significance. Redo each
  // fit while keeping parameter nsig fixed to zero. For each toy,
  // the difference in -log(L) of both fits is stored, as well
  // a simple significance interpretation of the delta(-logL)
  // using Dnll = 0.5 sigma^2

  RooDLLSignificanceMCSModule sigModule(nsig,0) ;
  mcs->addModule(sigModule) ;



  // R u n   m a n a g e r ,   m a k e   p l o t s
  // ---------------------------------------------

  // Run 1000 experiments. This configuration will generate a fair number
  // of (harmless) MINUIT warnings due to the instability of the Chebychev polynomial fit
  // at low statistics.
  mcs->generateAndFit(500) ;

  // Make some plots
  TH1* dll_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,dll_nullhypo_nsig",-40,-40) ;
  TH1* z_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,significance_nullhypo_nsig",-40,-40) ;
  TH1* errnsig_vs_ngen = mcs->fitParDataSet().createHistogram("ngen,nsigerr",-40,-40) ;
  TH1* errnsig_vs_nsig = mcs->fitParDataSet().createHistogram("nsig,nsigerr",-40,-40) ;


  // Draw plots on canvas
  TCanvas* c = new TCanvas("rf803_mcstudy_addons2","rf802_mcstudy_addons2",800,800) ;
  c->Divide(2,2) ;
  c->cd(1) ; gPad->SetLeftMargin(0.15) ; dll_vs_ngen->GetYaxis()->SetTitleOffset(1.6) ; dll_vs_ngen->Draw("box") ;
  c->cd(2) ; gPad->SetLeftMargin(0.15) ; z_vs_ngen->GetYaxis()->SetTitleOffset(1.6) ; z_vs_ngen->Draw("box") ;
  c->cd(3) ; gPad->SetLeftMargin(0.15) ; errnsig_vs_ngen->GetYaxis()->SetTitleOffset(1.6) ; errnsig_vs_ngen->Draw("box") ;
  c->cd(4) ; gPad->SetLeftMargin(0.15) ; errnsig_vs_nsig->GetYaxis()->SetTitleOffset(1.6) ; errnsig_vs_nsig->Draw("box") ;

 
  // Make RooMCStudy object available on command line after
  // macro finishes
  gDirectory->Add(mcs) ;

}




 rf803_mcstudy_addons2.C:1
 rf803_mcstudy_addons2.C:2
 rf803_mcstudy_addons2.C:3
 rf803_mcstudy_addons2.C:4
 rf803_mcstudy_addons2.C:5
 rf803_mcstudy_addons2.C:6
 rf803_mcstudy_addons2.C:7
 rf803_mcstudy_addons2.C:8
 rf803_mcstudy_addons2.C:9
 rf803_mcstudy_addons2.C:10
 rf803_mcstudy_addons2.C:11
 rf803_mcstudy_addons2.C:12
 rf803_mcstudy_addons2.C:13
 rf803_mcstudy_addons2.C:14
 rf803_mcstudy_addons2.C:15
 rf803_mcstudy_addons2.C:16
 rf803_mcstudy_addons2.C:17
 rf803_mcstudy_addons2.C:18
 rf803_mcstudy_addons2.C:19
 rf803_mcstudy_addons2.C:20
 rf803_mcstudy_addons2.C:21
 rf803_mcstudy_addons2.C:22
 rf803_mcstudy_addons2.C:23
 rf803_mcstudy_addons2.C:24
 rf803_mcstudy_addons2.C:25
 rf803_mcstudy_addons2.C:26
 rf803_mcstudy_addons2.C:27
 rf803_mcstudy_addons2.C:28
 rf803_mcstudy_addons2.C:29
 rf803_mcstudy_addons2.C:30
 rf803_mcstudy_addons2.C:31
 rf803_mcstudy_addons2.C:32
 rf803_mcstudy_addons2.C:33
 rf803_mcstudy_addons2.C:34
 rf803_mcstudy_addons2.C:35
 rf803_mcstudy_addons2.C:36
 rf803_mcstudy_addons2.C:37
 rf803_mcstudy_addons2.C:38
 rf803_mcstudy_addons2.C:39
 rf803_mcstudy_addons2.C:40
 rf803_mcstudy_addons2.C:41
 rf803_mcstudy_addons2.C:42
 rf803_mcstudy_addons2.C:43
 rf803_mcstudy_addons2.C:44
 rf803_mcstudy_addons2.C:45
 rf803_mcstudy_addons2.C:46
 rf803_mcstudy_addons2.C:47
 rf803_mcstudy_addons2.C:48
 rf803_mcstudy_addons2.C:49
 rf803_mcstudy_addons2.C:50
 rf803_mcstudy_addons2.C:51
 rf803_mcstudy_addons2.C:52
 rf803_mcstudy_addons2.C:53
 rf803_mcstudy_addons2.C:54
 rf803_mcstudy_addons2.C:55
 rf803_mcstudy_addons2.C:56
 rf803_mcstudy_addons2.C:57
 rf803_mcstudy_addons2.C:58
 rf803_mcstudy_addons2.C:59
 rf803_mcstudy_addons2.C:60
 rf803_mcstudy_addons2.C:61
 rf803_mcstudy_addons2.C:62
 rf803_mcstudy_addons2.C:63
 rf803_mcstudy_addons2.C:64
 rf803_mcstudy_addons2.C:65
 rf803_mcstudy_addons2.C:66
 rf803_mcstudy_addons2.C:67
 rf803_mcstudy_addons2.C:68
 rf803_mcstudy_addons2.C:69
 rf803_mcstudy_addons2.C:70
 rf803_mcstudy_addons2.C:71
 rf803_mcstudy_addons2.C:72
 rf803_mcstudy_addons2.C:73
 rf803_mcstudy_addons2.C:74
 rf803_mcstudy_addons2.C:75
 rf803_mcstudy_addons2.C:76
 rf803_mcstudy_addons2.C:77
 rf803_mcstudy_addons2.C:78
 rf803_mcstudy_addons2.C:79
 rf803_mcstudy_addons2.C:80
 rf803_mcstudy_addons2.C:81
 rf803_mcstudy_addons2.C:82
 rf803_mcstudy_addons2.C:83
 rf803_mcstudy_addons2.C:84
 rf803_mcstudy_addons2.C:85
 rf803_mcstudy_addons2.C:86
 rf803_mcstudy_addons2.C:87
 rf803_mcstudy_addons2.C:88
 rf803_mcstudy_addons2.C:89
 rf803_mcstudy_addons2.C:90
 rf803_mcstudy_addons2.C:91
 rf803_mcstudy_addons2.C:92
 rf803_mcstudy_addons2.C:93
 rf803_mcstudy_addons2.C:94
 rf803_mcstudy_addons2.C:95
 rf803_mcstudy_addons2.C:96
 rf803_mcstudy_addons2.C:97
 rf803_mcstudy_addons2.C:98
 rf803_mcstudy_addons2.C:99
 rf803_mcstudy_addons2.C:100
 rf803_mcstudy_addons2.C:101
 rf803_mcstudy_addons2.C:102
 rf803_mcstudy_addons2.C:103
 rf803_mcstudy_addons2.C:104
 rf803_mcstudy_addons2.C:105
 rf803_mcstudy_addons2.C:106
 rf803_mcstudy_addons2.C:107
 rf803_mcstudy_addons2.C:108
 rf803_mcstudy_addons2.C:109
 rf803_mcstudy_addons2.C:110
 rf803_mcstudy_addons2.C:111
 rf803_mcstudy_addons2.C:112
 rf803_mcstudy_addons2.C:113
 rf803_mcstudy_addons2.C:114
 rf803_mcstudy_addons2.C:115
 rf803_mcstudy_addons2.C:116
 rf803_mcstudy_addons2.C:117
 rf803_mcstudy_addons2.C:118
 rf803_mcstudy_addons2.C:119
 rf803_mcstudy_addons2.C:120
 rf803_mcstudy_addons2.C:121
 rf803_mcstudy_addons2.C:122
 rf803_mcstudy_addons2.C:123
 rf803_mcstudy_addons2.C:124
 rf803_mcstudy_addons2.C:125
 rf803_mcstudy_addons2.C:126
 rf803_mcstudy_addons2.C:127
 rf803_mcstudy_addons2.C:128
 rf803_mcstudy_addons2.C:129
 rf803_mcstudy_addons2.C:130
 rf803_mcstudy_addons2.C:131
 rf803_mcstudy_addons2.C:132