Dear all,
I am trying to run some code to be able to store in a RooWorkspace a RooProfileLL.
In attachment a script I modified from the tutorials which i adapted to save things to workspace.
The issue i have is that i can store it, but when I open back the file i get a segfault.
Any suggestion on what is happening/ it’s possible or not/ what I am doing wrong is more than welcome.
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooConstVar.h"
#include "RooAddPdf.h"
#include "RooMinimizer.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit ;
void rf605_profilell_modified()
{
// C r e a t e m o d e l a n d d a t a s e t
// -----------------------------------------------
// Observable
RooRealVar x("x","x",-20,20) ;
// Model (intentional strong correlations)
RooRealVar mean("mean","mean of g1 and g2",0,-10,10) ;
RooRealVar sigma_g1("sigma_g1","width of g1",3) ;
RooGaussian g1("g1","g1",x,mean,sigma_g1) ;
RooRealVar sigma_g2("sigma_g2","width of g2",4,3.0,6.0) ;
RooGaussian g2("g2","g2",x,mean,sigma_g2) ;
RooRealVar frac("frac","frac",0.5,0.0,1.0) ;
RooAddPdf model("model","model",RooArgList(g1,g2),frac) ;
// Generate 1000 events
RooDataSet* data = model.generate(x,1000) ;
// C o n s t r u c t p l a i n l i k e l i h o o d
// ---------------------------------------------------
// Construct unbinned likelihood
RooAbsReal* nll = model.createNLL(*data) ;
// Minimize likelihood w.r.t all parameters before making plots
RooMinimizer mini(*nll);
mini.migrad();
RooFitResult * fitres = mini.save() ;
// C o n s t r u c t p r o f i l e l i k e l i h o o d i n f r a c
// -----------------------------------------------------------------------
// The profile likelihood estimator on nll for frac will minimize nll w.r.t
// all floating parameters except frac for each evaluation
RooAbsReal* pll_frac = nll->createProfile(frac) ;
// Plot the profile likelihood in frac
// pll_frac->plotOn(frame1,LineColor(kRed)) ;
// Adjust frame maximum for visual clarity
// frame1->SetMinimum(0) ;
// frame1->SetMaximum(3) ;
// C o n s t r u c t p r o f i l e l i k e l i h o o d i n s i g m a _ g 2
// -------------------------------------------------------------------------------
// The profile likelihood estimator on nll for sigma_g2 will minimize nll
// w.r.t all floating parameters except sigma_g2 for each evaluation
RooAbsReal* pll_sigmag2 = nll->createProfile(sigma_g2) ;
pll_sigmag2->Print();
RooWorkspace* w = new RooWorkspace("w") ;
w->import( *data);
w->import( model);
w->import( *fitres);
w->import( *nll, RenameConflictNodes("nll"));
w->import( *pll_sigmag2, RenameConflictNodes("pll"));
w->writeToFile ("profiling.root", kTRUE);
}
You can reproduce the issue doing
root[0] .L test.C;
root[1] rf605_profilell_modified();
root[2] TFile *f = new TFile("profiling.root");
root[3] w->Print();
Renato