Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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_code
10/// \macro_output
11///
12/// \date July 2008
13/// \author Wouter Verkerke
14
15#include "RooRealVar.h"
16#include "RooDataSet.h"
17#include "RooGaussian.h"
18#include "RooChebychev.h"
19#include "RooAddPdf.h"
20#include "RooWorkspace.h"
21#include "RooPlot.h"
22#include "TCanvas.h"
23#include "TAxis.h"
24#include "TFile.h"
25#include "TH1.h"
26using namespace RooFit;
27
29{
30 // R e a d w o r k s p a c e f r o m f i l e
31 // -----------------------------------------------
32
33 // Open input file with workspace (generated by rf503_wspacewrite)
34 TFile *f = new TFile("rf502_workspace.root");
35
36 // Retrieve workspace from file
37 RooWorkspace *w = (RooWorkspace *)f->Get("w");
38
39 // 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
40 // -----------------------------------------------------------------
41
42 // Retrieve x,model and data from workspace
43 RooRealVar *x = w->var("x");
44 RooAbsPdf *model = w->pdf("model");
45 RooAbsData *data = w->data("modelData");
46
47 // Print structure of composite pdf
48 model->Print("t");
49
50 // F i t m o d e l t o d a t a , p l o t m o d e l
51 // ---------------------------------------------------------
52
53 // Fit model to data
54 model->fitTo(*data, PrintLevel(-1));
55
56 // Plot data and PDF overlaid
57 RooPlot *xframe = x->frame(Title("Model and data read from workspace"));
58 data->plotOn(xframe);
59 model->plotOn(xframe);
60
61 // Overlay the background component of model with a dashed line
62 model->plotOn(xframe, Components("bkg"), LineStyle(kDashed));
63
64 // Overlay the background+sig2 components of model with a dotted line
65 model->plotOn(xframe, Components("bkg,sig2"), LineStyle(kDotted));
66
67 // Draw the frame on the canvas
68 new TCanvas("rf503_wspaceread", "rf503_wspaceread", 600, 600);
69 gPad->SetLeftMargin(0.15);
70 xframe->GetYaxis()->SetTitleOffset(1.4);
71 xframe->Draw();
72}
#define f(i)
Definition RSha256.hxx:104
@ kDashed
Definition TAttLine.h:48
@ kDotted
Definition TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:263
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={}, const RooCmdArg &arg10={}) const override
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition RooAbsPdf.h:124
RooFit::OwningPtr< RooFitResult > fitTo(RooAbsData &data, CmdArgs_t const &... cmdArgs)
Fit PDF to given dataset.
Definition RooAbsPdf.h:157
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:185
TAxis * GetYaxis() const
Definition RooPlot.cxx:1224
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:597
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Persistable container for RooFit projects.
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
RooCmdArg PrintLevel(Int_t code)
RooCmdArg Components(Args_t &&... argsOrArgSet)
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...
Definition CodegenImpl.h:64
const char * Title
Definition TXMLSetup.cxx:68