Logo ROOT  
Reference Guide
rf503_wspaceread.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4///
5/// Organisation and simultaneous fits: reading and using a workspace
6///
7/// The input file for this macro is generated by rf502_wspacewrite.C
8///
9/// \macro_image
10/// \macro_output
11/// \macro_code
12///
13/// \date 07/2008
14/// \author Wouter Verkerke
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
30void rf503_wspaceread()
31{
32 // R e a d w o r k s p a c e f r o m f i l e
33 // -----------------------------------------------
34
35 // Open input file with workspace (generated by rf14_wspacewrite)
36 TFile *f = new TFile("rf502_workspace.root");
37
38 // Retrieve workspace from file
39 RooWorkspace *w = (RooWorkspace *)f->Get("w");
40
41 // 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
42 // -----------------------------------------------------------------
43
44 // Retrieve x,model and data from workspace
45 RooRealVar *x = w->var("x");
46 RooAbsPdf *model = w->pdf("model");
47 RooAbsData *data = w->data("modelData");
48
49 // Print structure of composite p.d.f.
50 model->Print("t");
51
52 // F i t m o d e l t o d a t a , p l o t m o d e l
53 // ---------------------------------------------------------
54
55 // Fit model to data
56 model->fitTo(*data);
57
58 // Plot data and PDF overlaid
59 RooPlot *xframe = x->frame(Title("Model and data read from workspace"));
60 data->plotOn(xframe);
61 model->plotOn(xframe);
62
63 // Overlay the background component of model with a dashed line
64 model->plotOn(xframe, Components("bkg"), LineStyle(kDashed));
65
66 // Overlay the background+sig2 components of model with a dotted line
67 model->plotOn(xframe, Components("bkg,sig2"), LineStyle(kDotted));
68
69 // Draw the frame on the canvas
70 new TCanvas("rf503_wspaceread", "rf503_wspaceread", 600, 600);
71 gPad->SetLeftMargin(0.15);
72 xframe->GetYaxis()->SetTitleOffset(1.4);
73 xframe->Draw();
74}
#define f(i)
Definition: RSha256.hxx:104
@ kDashed
Definition: TAttLine.h:48
@ kDotted
Definition: TAttLine.h:48
#define gPad
Definition: TVirtualPad.h:287
virtual void Print(Option_t *options=0) const
Print the object to the defaultPrintStream().
Definition: RooAbsArg.h:302
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:44
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:546
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:1254
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
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition: RooAbsPdf.h:118
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1277
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:712
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
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.
Definition: TAttAxis.cxx:294
The Canvas class.
Definition: TCanvas.h:27
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
RooCmdArg Components(const RooArgSet &compSet)
RooCmdArg LineStyle(Style_t style)
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
const char * Title
Definition: TXMLSetup.cxx:67