Logo ROOT   6.12/07
Reference Guide
rf503_wspaceread.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #503
5 ///
6 /// Reading and using a workspace
7 ///
8 /// --> The input file for this macro is generated by rf502_wspaceread.C
9 ///
10 /// \macro_image
11 /// \macro_output
12 /// \macro_code
13 /// \author 07/2008 - Wouter Verkerke
14 
15 
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooConstVar.h"
20 #include "RooChebychev.h"
21 #include "RooAddPdf.h"
22 #include "RooWorkspace.h"
23 #include "RooPlot.h"
24 #include "TCanvas.h"
25 #include "TAxis.h"
26 #include "TFile.h"
27 #include "TH1.h"
28 using namespace RooFit ;
29 
30 
31 void rf503_wspaceread()
32 {
33  // R e a d w o r k s p a c e f r o m f i l e
34  // -----------------------------------------------
35 
36  // Open input file with workspace (generated by rf14_wspacewrite)
37  TFile *f = new TFile("rf502_workspace.root") ;
38 
39  // Retrieve workspace from file
40  RooWorkspace* w = (RooWorkspace*) f->Get("w") ;
41 
42 
43 
44  // R e t r i e v e p d f , d a t a f r o m w o r k s p a c e
45  // -----------------------------------------------------------------
46 
47  // Retrieve x,model and data from workspace
48  RooRealVar* x = w->var("x") ;
49  RooAbsPdf* model = w->pdf("model") ;
50  RooAbsData* data = w->data("modelData") ;
51 
52  // Print structure of composite p.d.f.
53  model->Print("t") ;
54 
55 
56  // F i t m o d e l t o d a t a , p l o t m o d e l
57  // ---------------------------------------------------------
58 
59  // Fit model to data
60  model->fitTo(*data) ;
61 
62  // Plot data and PDF overlaid
63  RooPlot* xframe = x->frame(Title("Model and data read from workspace")) ;
64  data->plotOn(xframe) ;
65  model->plotOn(xframe) ;
66 
67  // Overlay the background component of model with a dashed line
68  model->plotOn(xframe,Components("bkg"),LineStyle(kDashed)) ;
69 
70  // Overlay the background+sig2 components of model with a dotted line
71  model->plotOn(xframe,Components("bkg,sig2"),LineStyle(kDotted)) ;
72 
73 
74 
75  // Draw the frame on the canvas
76  new TCanvas("rf503_wspaceread","rf503_wspaceread",600,600) ;
77  gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;
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:294
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
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:568
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 RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Plot (project) PDF on specified frame.
Definition: RooAbsPdf.h:105
RooCmdArg Title(const char *name)
Double_t x[n]
Definition: legend1.C:17
RooCmdArg LineStyle(Style_t style)
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooAbsArg.h:227
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found...
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
RooPlot * frame(const RooCmdArg &arg1, 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
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:31
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
RooCmdArg Components(const RooArgSet &compSet)
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found...
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
#define gPad
Definition: TVirtualPad.h:285
virtual RooFitResult * fitTo(RooAbsData &data, 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())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1079
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:42
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559