Logo ROOT   6.07/09
Reference Guide
rf301_composition.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #301
4 //
5 // Multi-dimensional p.d.f.s through composition, e.g. substituting a
6 // p.d.f parameter with a function that depends on other observables
7 //
8 // pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
9 //
10 //
11 // 07/2008 - Wouter Verkerke
12 //
13 /////////////////////////////////////////////////////////////////////////
14 
15 #ifndef __CINT__
16 #include "RooGlobalFunc.h"
17 #endif
18 #include "RooRealVar.h"
19 #include "RooDataSet.h"
20 #include "RooGaussian.h"
21 #include "RooPolyVar.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TH1.h"
25 using namespace RooFit ;
26 
27 
28 
29 class TestBasic301 : public RooFitTestUnit
30 {
31 public:
32  TestBasic301(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Composition extension of basic p.d.f",refFile,writeRef,verbose) {} ;
33  Bool_t testCode() {
34 
35  // S e t u p c o m p o s e d m o d e l g a u s s ( x , m ( y ) , s )
36  // -----------------------------------------------------------------------
37 
38  // Create observables
39  RooRealVar x("x","x",-5,5) ;
40  RooRealVar y("y","y",-5,5) ;
41 
42  // Create function f(y) = a0 + a1*y
43  RooRealVar a0("a0","a0",-0.5,-5,5) ;
44  RooRealVar a1("a1","a1",-0.5,-1,1) ;
45  RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
46 
47  // Creat gauss(x,f(y),s)
48  RooRealVar sigma("sigma","width of gaussian",0.5) ;
49  RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
50 
51 
52  // S a m p l e d a t a , p l o t d a t a a n d p d f o n x a n d y
53  // ---------------------------------------------------------------------------------
54 
55  // Generate 10000 events in x and y from model
56  RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
57 
58  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
59  RooPlot* xframe = x.frame() ;
60  data->plotOn(xframe) ;
61  model.plotOn(xframe) ;
62 
63  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
64  RooPlot* yframe = y.frame() ;
65  data->plotOn(yframe) ;
66  model.plotOn(yframe) ;
67 
68  // Make two-dimensional plot in x vs y
69  TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
70  hh_model->SetLineColor(kBlue) ;
71 
72 
73  regPlot(xframe,"rf301_plot1") ;
74  regPlot(yframe,"rf302_plot2") ;
75  regTH(hh_model,"rf302_model2d") ;
76 
77  delete data ;
78  return kTRUE ;
79  }
80 } ;
81 
82 
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
const Double_t sigma
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:80
Definition: Rtypes.h:61
const Bool_t kTRUE
Definition: Rtypes.h:91
RooCmdArg Binning(const RooAbsBinning &binning)