Debug: Successful. Next step: Uncertain.

I am seeing Very Strange Things.

The heart of my thesis is a log-likelihood fit, which I won’t explain here, because the problem is in computer science rather than mathematics. For this fit I rely on a library called RooFit, which has a class of objects called RooRealVar. I declare a large number of these RooRealVars, and use them as the parameters of my fit. (This background is by no means needed to understand the problem, however.) Now, my fit is doing Weird Stuff, getting wrong results on test datasets where I know the correct answer. I have spent two weeks tracing down the problem, and it occurs in this piece of code:

void makeLocalResolution (char* pre, RooRealVar& timeVariable, RooRealVar& localBias) {
static int pdfs = 0;
pdfs++;
static char* pdfnames = new char[200];

sprintf(pdfnames, "%s_ssf1_%i", pre, pdfs);
RooRealVar* ssf1 = new RooRealVar(pdfnames, "", 0.9, 0.2, 5);
sprintf(pdfnames, "%s_ssf2_%i", pre, pdfs);
RooRealVar* ssf2 = new RooRealVar(pdfnames, "", 2.8, 0.2, 7);

sprintf(pdfnames, "%s_gauss1_%i", pre, pdfs);
RooGaussModel* gauss1 = new RooGaussModel(pdfnames, "", timeVariable, localBias, *ssf1);
sprintf(pdfnames, "%s_gauss2_%i", pre, pdfs);
RooGaussModel* gauss2 = new RooGaussModel(pdfnames, "", timeVariable, localBias, *ssf2);
sprintf(pdfnames, "%s_frac_%i", pre, pdfs);
RooRealVar* frac1 = new RooRealVar(pdfnames, "", 0.175, 0.02, 1);
(...)
}

Now, this is just creating a bunch of RooRealVars, with some bells and whistles to give them unique names for when I call the method more than once. This is needed in some cases, but is currently turned off for my debugging effort, so this code runs only once. But when I use gdb to set some breakpoints, step through the code line by line, and look at the variable addresses (I won’t bore you with the tale of how I got to the point of thinking such a procedure necessary; I’ve been debugging this thing for two weeks), everything looks fine until I come to the last ‘new’ statement. At that point I get this:

(gdb) p ssf1
$8 = (class RooRealVar *) 0xa5fea38
(gdb) p frac1
$9 = (class RooRealVar *) 0xa5fea38

In other words, the ‘frac1’ object is being created right on top of my ‘ssf1’ object! Naturally this creates all sorts of problems later in the fit. Honestly I’m surprised it runs at all, but it does.

My question: Does anyone have any ideas on how this kind of situation can occur? I have no idea how to debug this. Even if I can perhaps avoid this particular problem by moving my code around a bit, I would like to be confident that nothing similar is happening elsewhere in the program. I would really, really welcome suggestions. I will not be graduating unless I can have confidence in the results of this code.

Advertisements

Leave a comment

Filed under Academics, Personal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s