 ROOT   Reference Guide rf502_wspacewrite.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 /// Organisation and simultaneous fits: creating and writing a workspace
5 ///
6 /// \macro_output
7 /// \macro_code
8 ///
9 /// \date July 2008
10 /// \author Wouter Verkerke
11
12 #include "RooRealVar.h"
13 #include "RooDataSet.h"
14 #include "RooGaussian.h"
15 #include "RooConstVar.h"
16 #include "RooChebychev.h"
18 #include "RooWorkspace.h"
19 #include "RooPlot.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "TFile.h"
23 #include "TH1.h"
24 using namespace RooFit;
25
26 void rf502_wspacewrite()
27 {
28  // C r e a t e m o d e l a n d d a t a s e t
29  // -----------------------------------------------
30
31  // Declare observable x
32  RooRealVar x("x", "x", 0, 10);
33
34  // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters
35  RooRealVar mean("mean", "mean of gaussians", 5, 0, 10);
36  RooRealVar sigma1("sigma1", "width of gaussians", 0.5);
37  RooRealVar sigma2("sigma2", "width of gaussians", 1);
38
39  RooGaussian sig1("sig1", "Signal component 1", x, mean, sigma1);
40  RooGaussian sig2("sig2", "Signal component 2", x, mean, sigma2);
41
42  // Build Chebychev polynomial pdf
43  RooRealVar a0("a0", "a0", 0.5, 0., 1.);
44  RooRealVar a1("a1", "a1", 0.2, 0, 1.);
45  RooChebychev bkg("bkg", "Background", x, RooArgSet(a0, a1));
46
47  // Sum the signal components into a composite signal pdf
48  RooRealVar sig1frac("sig1frac", "fraction of component 1 in signal", 0.8, 0., 1.);
49  RooAddPdf sig("sig", "Signal", RooArgList(sig1, sig2), sig1frac);
50
51  // Sum the composite signal and background
52  RooRealVar bkgfrac("bkgfrac", "fraction of background", 0.5, 0., 1.);
53  RooAddPdf model("model", "g1+g2+a", RooArgList(bkg, sig), bkgfrac);
54
55  // Generate a data sample of 1000 events in x from model
56  RooDataSet *data = model.generate(x, 1000);
57
58  // C r e a t e w o r k s p a c e , i m p o r t d a t a a n d m o d e l
59  // -----------------------------------------------------------------------------
60
61  // Create a new empty workspace
62  RooWorkspace *w = new RooWorkspace("w", "workspace");
63
64  // Import model and all its components into the workspace
65  w->import(model);
66
67  // Import data into the workspace
68  w->import(*data);
69
70  // Print workspace contents
71  w->Print();
72
73  // S a v e w o r k s p a c e i n f i l e
74  // -------------------------------------------
75
76  // Save the workspace into a ROOT file
77  w->writeToFile("rf502_workspace.root");
78
79  // Workspace will remain in memory after macro finishes
81 }
RooWorkspace.h
RooChebychev.h
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
RooWorkspace::writeToFile
Bool_t writeToFile(const char *fileName, Bool_t recreate=kTRUE)
Save this current workspace into given file.
Definition: RooWorkspace.cxx:2154
RooChebychev
Chebychev polynomial p.d.f.
Definition: RooChebychev.h:25
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
TCanvas.h
RooDataSet.h
TFile.h
RooWorkspace::import
Bool_t import(const RooAbsArg &arg, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Import a RooAbsArg object, e.g.
Definition: RooWorkspace.cxx:361
RooWorkspace::Print
void Print(Option_t *opts=0) const
Print contents of the workspace.
Definition: RooWorkspace.cxx:2194
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPlot.h
gDirectory
#define gDirectory
Definition: TDirectory.h:236
rf502_wspacewrite
Definition: rf502_wspacewrite.py:1
RooRealVar.h
RooConstVar.h
RooWorkspace
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
TAxis.h
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
TH1.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29