Logo ROOT   6.07/09
Reference Guide
rf301_composition.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #301
5 ///
6 /// Multi-dimensional p.d.f.s through composition, e.g. substituting a
7 /// p.d.f parameter with a function that depends on other observables
8 ///
9 /// pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
10 ///
11 /// \macro_image
12 /// \macro_output
13 /// \macro_code
14 /// \author 07/2008 - Wouter Verkerke
15 
16 
17 #include "RooRealVar.h"
18 #include "RooDataSet.h"
19 #include "RooGaussian.h"
20 #include "RooPolyVar.h"
21 #include "RooPlot.h"
22 #include "TCanvas.h"
23 #include "TAxis.h"
24 #include "TH1.h"
25 using namespace RooFit ;
26 
27 
28 
29 void rf301_composition()
30 {
31  // 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 )
32  // -----------------------------------------------------------------------
33 
34  // Create observables
35  RooRealVar x("x","x",-5,5) ;
36  RooRealVar y("y","y",-5,5) ;
37 
38  // Create function f(y) = a0 + a1*y
39  RooRealVar a0("a0","a0",-0.5,-5,5) ;
40  RooRealVar a1("a1","a1",-0.5,-1,1) ;
41  RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
42 
43  // Create gauss(x,f(y),s)
44  RooRealVar sigma("sigma","width of gaussian",0.5) ;
45  RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;
46 
47 
48  // 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
49  // ---------------------------------------------------------------------------------
50 
51  // Generate 10000 events in x and y from model
52  RooDataSet *data = model.generate(RooArgSet(x,y),10000) ;
53 
54  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
55  RooPlot* xframe = x.frame() ;
56  data->plotOn(xframe) ;
57  model.plotOn(xframe) ;
58 
59  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
60  RooPlot* yframe = y.frame() ;
61  data->plotOn(yframe) ;
62  model.plotOn(yframe) ;
63 
64  // Make two-dimensional plot in x vs y
65  TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ;
66  hh_model->SetLineColor(kBlue) ;
67 
68 
69 
70  // Make canvas and draw RooPlots
71  TCanvas *c = new TCanvas("rf301_composition","rf301_composition",1200, 400);
72  c->Divide(3);
73  c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;
74  c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ;
75  c->cd(3) ; gPad->SetLeftMargin(0.20) ; hh_model->GetZaxis()->SetTitleOffset(2.5) ; hh_model->Draw("surf") ;
76 
77 }
78 
79 
80 
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:262
return c
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
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
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2853
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
The Canvas class.
Definition: TCanvas.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
TAxis * GetZaxis()
Definition: TH1.h:326
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1089
#define gPad
Definition: TVirtualPad.h:289
Definition: Rtypes.h:61
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559
RooCmdArg Binning(const RooAbsBinning &binning)