ROOT logo

From $ROOTSYS/tutorials/roofit/rf312_multirangefit.C

//////////////////////////////////////////////////////////////////////////
//
// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #312
// 
// Performing fits in multiple (disjoint) ranges in one or more dimensions
//
//
//
// 07/2008 - Wouter Verkerke 
// 
/////////////////////////////////////////////////////////////////////////

#ifndef __CINT__
#include "RooGlobalFunc.h"
#endif
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooProdPdf.h"
#include "RooAddPdf.h"
#include "RooPolynomial.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "RooFitResult.h"
using namespace RooFit ;


void rf312_multirangefit()
{

  // C r e a t e   2 D   p d f   a n d   d a t a 
  // -------------------------------------------

  // Define observables x,y
  RooRealVar x("x","x",-10,10) ;
  RooRealVar y("y","y",-10,10) ;

  // Construct the signal pdf gauss(x)*gauss(y)
  RooRealVar mx("mx","mx",1,-10,10) ;
  RooRealVar my("my","my",1,-10,10) ;

  RooGaussian gx("gx","gx",x,mx,RooConst(1)) ;
  RooGaussian gy("gy","gy",y,my,RooConst(1)) ;

  RooProdPdf sig("sig","sig",gx,gy) ;

  // Construct the background pdf (flat in x,y)
  RooPolynomial px("px","px",x) ;
  RooPolynomial py("py","py",y) ;
  RooProdPdf bkg("bkg","bkg",px,py) ;

  // Construct the composite model sig+bkg
  RooRealVar f("f","f",0.,1.) ;
  RooAddPdf model("model","model",RooArgList(sig,bkg),f) ;

  // Sample 10000 events in (x,y) from the model
  RooDataSet* modelData = model.generate(RooArgSet(x,y),10000) ;



  // D e f i n e   s i g n a l   a n d   s i d e b a n d   r e g i o n s
  // -------------------------------------------------------------------

  // Construct the SideBand1,SideBand2,Signal regions
  //
  //                    |
  //      +-------------+-----------+                 
  //      |             |           |             
  //      |    Side     |   Sig     |        
  //      |    Band1    |   nal     |             
  //      |             |           |            
  //    --+-------------+-----------+--   
  //      |                         |       
  //      |           Side          |        
  //      |           Band2         |            
  //      |                         |          
  //      +-------------+-----------+            
  //                    |                       

  x.setRange("SB1",-10,+10) ;
  y.setRange("SB1",-10,0) ;

  x.setRange("SB2",-10,0) ;
  y.setRange("SB2",0,+10) ;

  x.setRange("SIG",0,+10) ;
  y.setRange("SIG",0,+10) ;

  x.setRange("FULL",-10,+10) ;
  y.setRange("FULL",-10,+10) ;


  // P e r f o r m   f i t s   i n   i n d i v i d u a l   s i d e b a n d   r e g i o n s
  // -------------------------------------------------------------------------------------

  // Perform fit in SideBand1 region (RooAddPdf coefficients will be interpreted in full range)
  RooFitResult* r_sb1 = model.fitTo(*modelData,Range("SB1"),Save()) ;

  // Perform fit in SideBand2 region (RooAddPdf coefficients will be interpreted in full range)
  RooFitResult* r_sb2 = model.fitTo(*modelData,Range("SB2"),Save()) ;



  // P e r f o r m   f i t s   i n   j o i n t    s i d e b a n d   r e g i o n s
  // -----------------------------------------------------------------------------

  // Now perform fit to joint 'L-shaped' sideband region 'SB1|SB2' 
  // (RooAddPdf coefficients will be interpreted in full range)
  RooFitResult* r_sb12 = model.fitTo(*modelData,Range("SB1,SB2"),Save()) ;


  // Print results for comparison
  r_sb1->Print() ;
  r_sb2->Print() ;
  r_sb12->Print() ;
  

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