Logo ROOT  
Reference Guide
rf503_wspaceread.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Organisation and simultaneous fits: reading and using a workspace
5 ///
6 /// The input file for this macro is generated by rf502_wspacewrite.C
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 ///
12 /// \date July 2008
13 /// \author Wouter Verkerke
14 
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "RooConstVar.h"
19 #include "RooChebychev.h"
20 #include "RooAddPdf.h"
21 #include "RooWorkspace.h"
22 #include "RooPlot.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "TFile.h"
26 #include "TH1.h"
27 using namespace RooFit;
28 
29 void rf503_wspaceread()
30 {
31  // R e a d w o r k s p a c e f r o m f i l e
32  // -----------------------------------------------
33 
34  // Open input file with workspace (generated by rf14_wspacewrite)
35  TFile *f = new TFile("rf502_workspace.root");
36 
37  // Retrieve workspace from file
38  RooWorkspace *w = (RooWorkspace *)f->Get("w");
39 
40  // 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
41  // -----------------------------------------------------------------
42 
43  // Retrieve x,model and data from workspace
44  RooRealVar *x = w->var("x");
45  RooAbsPdf *model = w->pdf("model");
46  RooAbsData *data = w->data("modelData");
47 
48  // Print structure of composite pdf
49  model->Print("t");
50 
51  // F i t m o d e l t o d a t a , p l o t m o d e l
52  // ---------------------------------------------------------
53 
54  // Fit model to data
55  model->fitTo(*data);
56 
57  // Plot data and PDF overlaid
58  RooPlot *xframe = x->frame(Title("Model and data read from workspace"));
59  data->plotOn(xframe);
60  model->plotOn(xframe);
61 
62  // Overlay the background component of model with a dashed line
63  model->plotOn(xframe, Components("bkg"), LineStyle(kDashed));
64 
65  // Overlay the background+sig2 components of model with a dotted line
66  model->plotOn(xframe, Components("bkg,sig2"), LineStyle(kDotted));
67 
68  // Draw the frame on the canvas
69  new TCanvas("rf503_wspaceread", "rf503_wspaceread", 600, 600);
70  gPad->SetLeftMargin(0.15);
71  xframe->GetYaxis()->SetTitleOffset(1.4);
72  xframe->Draw();
73 }
RooWorkspace::data
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1368
RooWorkspace.h
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooChebychev.h
f
#define f(i)
Definition: RSha256.hxx:104
RooAbsData
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:47
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooAddPdf.h
TCanvas.h
RooDataSet.h
TFile.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1258
RooPlot
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
RooWorkspace::pdf
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1277
RooRealVar.h
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
RooConstVar.h
RooWorkspace
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TAxis.h
kDashed
@ kDashed
Definition: TAttLine.h:48
gPad
#define gPad
Definition: TVirtualPad.h:287
RooWorkspace::var
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
Definition: RooWorkspace.cxx:1295
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsPdf
Definition: RooAbsPdf.h:43
RooFit::LineStyle
RooCmdArg LineStyle(Style_t style)
Definition: RooGlobalFunc.cxx:58
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooFit::Components
RooCmdArg Components(const RooArgSet &compSet)
Definition: RooGlobalFunc.cxx:75
TH1.h
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:176
kDotted
@ kDotted
Definition: TAttLine.h:48