Skip to content

Commit

Permalink
Fix roofit macros to run with ROOT 6
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoneta committed May 30, 2014
1 parent 41276d8 commit deba552
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
49 changes: 37 additions & 12 deletions tutorials/roofit/rf509_wsinteractive.C
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ void rf509_wsinteractive()
// C r e a t e a n d f i l l w o r k s p a c e
// ------------------------------------------------

// Create a workspace named 'w' that exports its contents to
// Create a workspace named 'w'
// With CINT w could exports its contents to
// a same-name C++ namespace in CINT 'namespace w'.
// but this does not work anymore in CLING.
// so this tutorial is an example on how to
// change the code
RooWorkspace* w = new RooWorkspace("w",kTRUE) ;

// Fill workspace with p.d.f. and data in a separate function
Expand All @@ -48,23 +52,44 @@ void rf509_wsinteractive()
// Print workspace contents
w->Print() ;

// U s e w o r k s p a c e c o n t e n t s t h r o u g h C I N T C + + n a m e s p a c e
// -------------------------------------------------------------------------------------------------
// this does not work anymore with CLING
// use normal workspace functionality

// Use the name space prefix operator to access the workspace contents
RooDataSet* d = w::model.generate(w::x,1000) ;
RooFitResult* r = w::model.fitTo(*d) ;

// U s e w o r k s p a c e c o n t e n t s
// ----------------------------------------------

RooPlot* frame = w::x.frame() ;
d->plotOn(frame) ;

// Old syntax to use the name space prefix operator to access the workspace contents
//
//RooDataSet* d = w::model.generate(w::x,1000) ;
//RooFitResult* r = w::model.fitTo(*d) ;

// use normal workspace methods
RooAbsPdf * model = w->pdf("model");
RooRealVar * x = w->var("x");

RooDataSet* d = model->generate(*x,1000) ;
RooFitResult* r = model->fitTo(*d) ;

// old syntax to access the variable x
// RooPlot* frame = w::x.frame() ;

RooPlot* frame = x->frame() ;
d->plotOn(frame) ;

// OLD syntax to ommit x::
// NB: The 'w::' prefix can be omitted if namespace w is imported in local namespace
// in the usual C++ way
using namespace w;
model.plotOn(frame) ;
model.plotOn(frame,Components(bkg),LineStyle(kDashed)) ;

//
// using namespace w;
// model.plotOn(frame) ;
// model.plotOn(frame,Components(bkg),LineStyle(kDashed)) ;

// new correct syntax
RooAbsPdf *bkg = w->pdf("bkg");
model->plotOn(frame);
model->plotOn(frame,Components(*bkg),LineStyle(kDashed)) ;

// Draw the frame on the canvas
new TCanvas("rf509_wsinteractive","rf509_wsinteractive",600,600) ;
Expand Down
16 changes: 11 additions & 5 deletions tutorials/roofit/rf903_numintcache.C
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ void rf903_numintcache(Int_t mode=0)

// Show plot of cached integral values
RooDataHist* hhcache = (RooDataHist*) w->expensiveObjectCache().getObj(1) ;
if (hhcache) {

new TCanvas("rf903_numintcache","rf903_numintcache",600,600) ;
hhcache->createHistogram("a")->Draw() ;
new TCanvas("rf903_numintcache","rf903_numintcache",600,600) ;
hhcache->createHistogram("a")->Draw() ;

return ;
}
else {
Error("rf903_numintcache","Cached histogram is not existing in workspace");
}
return ;
}


// U s e p . d . f . f r o m w o r k s p a c e f o r g e n e r a t i o n a n d f i t t i n g
// -----------------------------------------------------------------------------------

Expand Down Expand Up @@ -109,7 +113,9 @@ RooWorkspace* getWorkspace(Int_t mode)
// two dimensions numerically. In this specific case the integral value for
// all values of parameter 'a' are stored in a histogram and available for use
// in subsequent fitting and plotting operations (interpolation is applied)
w->pdf("model")->setNormValueCaching(3) ;

// w->pdf("model")->setNormValueCaching(3) ;
w->pdf("model")->setStringAttribute("CACHEPARMINT","x:y:z");

// Evaluate p.d.f. once to trigger filling of cache
RooArgSet normSet(*w->var("x"),*w->var("y"),*w->var("z")) ;
Expand Down

0 comments on commit deba552

Please sign in to comment.