Roofit in batch mdoe -- core dump when using RooPlot

So, I just introduced Roofit into my analysis code and the fitting is going well. I have a class which has a fitting method that is called from another class method. The code works perfectly fine if I don’t try to plot the the RooPlots. If I do use RooPlot, the plots are created and stored in the root file, but at the very end I get a core dump. I could go on my merry way and keep deleting core dumps, but that’s kindof silly.

Not only does one need to delete the frame, but a write command is also required.
So, by example

RooPlot *frame;
delete frame;

I’ve tried deleting the frame after the plot is done, but then I get nothing in my root file afterwards (no core dump though). Are there issues with RooPLot running in batch mode (compiled code). Here’s the core dump message:
Error in TUnixSystem::DynamicPathName: does not exist in
Error in TUnixSystem::DynamicPathName: does not exist in
Error in TCint::AutoLoad: failure loading library for class RooPrintable
Segmentation fault (core dumped)

Here’s the fitting method:
void PidTable::FitHisto(TH1D* hist, Double_t &sig, Double_t &err)
double m1a, mi, mf, w1a, wi, wf, w2a;
m1a = 1.8694; mi = 1.855; mf = 1.875;
w1a = 0.004; wi = 0.002; wf = 0.025; w2a = 0.01;

//Build RooFit model
RooRealVar CandidateMass(“CandidateMass”,"ParentMass ", ParentMass, Hist_lower, Hist_upper, “GeV/c^2”);
RooRealVar mean1(“mean1”, “mean1”, m1a, mi, mf);
RooRealVar width1(“width1”, “width1”, w1a, wi, wf);
RooRealVar width2(“width2”,“width2”, w2a, wi, wf);
// RooRealVar m(“m”, “slope”, 0.0, -100.0, 100.0);
// RooRealVar o(“o”, “offset”, 2.0, -100.0, 10000.0);
RooRealVar m(“m”, “Exponential Parameter”, -60.0, 40.0 );
RooRealVar frac(“frac”, “fraction of gaussian”, 0.1, 0.0, 1.0);
RooRealVar N0(“N0”, “# signal events”, 100.0, 0.0, 80000.0);
RooRealVar nBkg(“nBkg”, “# Background events”, 10.0, 0.0, 20000.0);

//RooPolynomial bg(“bg”, “Background shape”, CandidateMass);
RooExponential bg(“bg”, “Background shape”, CandidateMass, m);
RooGaussian gauss1(“gauss1”, “Signal 1”, CandidateMass, mean1, width1);
RooGaussian gauss2(“gauss2”, “Signal 2”, CandidateMass , mean1, width2);
RooAddPdf signal(“signal”,“Signal”, RooArgList(gauss1,gauss2), RooArgList(frac));
RooAddPdf both(“both”,“Signal+Background”, RooArgList(signal, bg), RooArgList(N0, nBkg));

RooDataHist H(“H”, “H”, RooArgList(CandidateMass), hist);
both.fitTo(H, “me”);

double N = N0.getVal(),
f = frac.getVal(),
m1 = mean1.getVal(),
w1 = width1.getVal(),
m2 = mean1.getVal(),
w2 = width2.getVal(),
n = nBkg.getVal(),
p = m.getVal(),
Nerr = N0.getError(),
ferr = frac.getError(),
m1err = mean1.getError(),
w1err = width1.getError(),
m2err = mean1.getError(),
w2err = width2.getError(),
nerr = nBkg.getError(),
Mean = fm1 + (1-f)m2,
errMean = sqrt((m1-m2)ferr(m1-m2)ferr + fm1err
m1err +
Sigma = sqrt(f
(w1)(w1) + (1-f)(w2)(w2) + f(1-f)(m1-m2)(m1-m2)),
errSigma = (1/2Sigma) * sqrt((w1w1-w2w2+(1-2f)(m1-m2)(m1-m2))(ferr)(ferr) +
4*(fw1w1err)(fw1w1err) + 4(fw2w2err)(fw2w2err) +

RooPlot *bframe = CandidateMass.frame(Hist_lower, Hist_upper, N_HistBins);
both.plotOn(bframe,Components(RooArgList(signal, bg)), LineColor(kRed), LineStyle(kDashed));
bframe->SetTitle( hist->GetTitle());

TPaveText *box = new TPaveText(0.12,0.65,.40,.90,“TRNDC”);
box->SetTextFont(12); box->Draw();
char title[100];
sprintf(title, “#chi^{2}/#nu = %.2f”, bframe->chiSquare());
sprintf(title, “Mean=%.4f”, Mean);
sprintf(title, “RMS=%.4f”, Sigma);
sprintf(title, "Signal = %.0f #pm %.0f ", N, Nerr );
sprintf(title, "Background = %.0f #pm %.0f ", n, nerr );

sig = N;
err = Nerr;
//chi2 = bframe->chiSquare();
//delete bframe;

Did you specify “-lMinuit” in your link sequence?


I should mention that I just want this fit to be avaliable in a root file, so I don’t even need the frame->Draw() command.

So, the core dump is due to the RooPLot command.

Yes, all of the libraries are linked, I’ve included every header file I could think of. The fits work fine, it is just when I call the RooPlot command.


I’d like to first understand your problem(s) better. It might be two unrelated issues,
so I have some questions for you.

First, about creating the RooPlots. A RooPlot inherits from a TH1 and does behave in this way, i.e. if you create one it attaches itself to the current directory so that it shows up on a gDirectory->ls() and so that they are easy to persist if the current directory is a file.

It is my understanding that you should not try to delete by hand objects that you have written into a file as you do in your macro. The object should be removed from memory automatically once you close the file. This is more of core ROOT topic, so experts please correct me if I am wrong!

Does you fitting code work OK if you remove the delete command?

Second, there appears to be an issue with autoload when you open a ROOT file with RooFit objects in it. It seems as if it is correctly determined that libRooFit is needed,
but somehow it does it fails to load libMinuit, which is required for libRooFit to work.

Can you check if it worka OK if you explicitly load both in your macro, i.e. if you start with
gSystem->Load(“libMinuit”) ;
gSystem->Load(“libRooFit”) ;
before you open your file. That would help to localize the problem.