ROOT logo
/////////////////////////////////////////////////////////////////////////
//
// 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #504
// 
// Using RooSimWSTool to construct a simultaneous p.d.f that is built
// of variations of an input p.d.f
//
//
// 07/2008 - Wouter Verkerke 
//
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooCategory.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooPolynomial.h"
#include "RooSimultaneous.h"
#include "RooAddPdf.h"
#include "RooWorkspace.h"
#include "RooSimWSTool.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TFile.h"
#include "TH1.h"
using namespace RooFit ;


void rf504_simwstool()
{
  // C r e a t e   m a s t e r   p d f 
  // ---------------------------------
  
  // Construct gauss(x,m,s)
  RooRealVar x("x","x",-10,10) ;
  RooRealVar m("m","m",0,-10,10) ;
  RooRealVar s("s","s",1,-10,10) ;
  RooGaussian gauss("g","g",x,m,s) ;

  // Construct poly(x,p0)
  RooRealVar p0("p0","p0",0.01,0.,1.) ;
  RooPolynomial poly("p","p",x,p0) ;		 

  // Construct model = f*gauss(x) + (1-f)*poly(x)
  RooRealVar f("f","f",0.5,0.,1.) ;
  RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;



  // C r e a t e   c a t e g o r y   o b s e r v a b l e s   f o r   s p l i t t i n g
  // ----------------------------------------------------------------------------------

  // Define two categories that can be used for splitting
  RooCategory c("c","c") ;
  c.defineType("run1") ;
  c.defineType("run2") ;

  RooCategory d("d","d") ;
  d.defineType("foo") ;
  d.defineType("bar") ;



  // S e t u p   S i m W S T o o l 
  // -----------------------------

  // Import ingredients in a workspace
  RooWorkspace w("w","w") ;
  w.import(RooArgSet(model,c,d)) ;

  // Make Sim builder tool
  RooSimWSTool sct(w) ;


  // B u i l d   a   s i m u l t a n e o u s   m o d e l   w i t h   o n e   s p l i t
  // ---------------------------------------------------------------------------------

  // Construct a simultaneous p.d.f with the following form
  //
  // model_run1(x) = f*gauss_run1(x,m_run1,s) + (1-f)*poly
  // model_run2(x) = f*gauss_run2(x,m_run2,s) + (1-f)*poly
  // simpdf(x,c) = model_run1(x) if c=="run1"
  //             = model_run2(x) if c=="run2"
  //
  // Returned p.d.f is owned by the workspace
  RooSimultaneous* model_sim = sct.build("model_sim","model",SplitParam("m","c")) ;

  // Print tree structure of model
  model_sim->Print("t") ;

  // Adjust model_sim parameters in workspace
  w.var("m_run1")->setVal(-3) ;
  w.var("m_run2")->setVal(+3) ;

  // Print contents of workspace
  w.Print("v") ;



  // B u i l d   a   s i m u l t a n e o u s   m o d e l   w i t h   p r o d u c t   s p l i t
  // -----------------------------------------------------------------------------------------

  // Build another simultaneous p.d.f using a composite split in states c X d
  RooSimultaneous* model_sim2 = sct.build("model_sim2","model",SplitParam("p0","c,d")) ;

  // Print tree structure of this model
  model_sim2->Print("t") ;

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