Logo ROOT   6.16/01
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"
28using namespace RooFit ;
29
30
31void 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}
#define f(i)
Definition: RSha256.hxx:104
@ kDashed
Definition: TAttLine.h:48
@ kDotted
Definition: TAttLine.h:48
#define gPad
Definition: TVirtualPad.h:286
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1123
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
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
The Canvas class.
Definition: TCanvas.h:31
Double_t x[n]
Definition: legend1.C:17
RooCmdArg Components(const RooArgSet &compSet)
RooCmdArg LineStyle(Style_t style)
const char * Title
Definition: TXMLSetup.cxx:67