I’m trying to run a simple example with signal and background with background constrained from a (Gaussian) subsidiary measurement. I want to plot the NLL vs signal strength in the end, to compare it with the NLL from a measurement without a constraint term. The fit runs fine, but when trying to plot the NLL I get errors from integration, saying my pdf is zero. Any ideas? I feel I’m missing something trivial. I get the error from the plotOn at the very end
void ex10_test()
{
// Make an empty workspace that exports its contents to CINT
RooWorkspace *w = new RooWorkspace("w",kTRUE) ;
TCanvas* c = new TCanvas("c", "c", 900, 600);
c->Divide(2);
// create variables
w->factory("S[20]") ; // signal prediction
w->factory("B[20,0,100]") ; // bkg prediction (floating, to be constrained by subsidiary measurement)
w->factory("mu[1, 0, 5]"); // nominal=1
// Declare the model observable (i.e. the quantity we measure, in this case an event count)
w->factory("Poisson::model(N[100], expr:Nexp('mu*S+B', mu, S, B))");
RooDataSet dataR("data","data",*w->var("N")) ;
RooDataSet* data = &dataR;
w->var("N")->setVal(45) ; // perform a single experiment, where we measure 45 events (? I think)
data->add(*w->var("N"));
// Now we construct a Gaussian subsidiary measurement:
w->factory("Gaussian::subsidiary(Bnom[20],B,sigmaB[5])") ;
// Gaussian::name(variable, mean, sigma)
c->cd(1);
RooPlot* frameSub = w->var("Bnom")->frame(0, 50, 50);
w->pdf("subsidiary")->plotOn(frameSub);
frameSub->Draw();
// construct a new model that is the product of the
// original model and the subsidiary measurement
w->factory("PROD::model2(model,subsidiary)");
// perform fit
w->pdf("model2")->fitTo(*data);
// latex.DrawLatexNDC(.5,.7,Form("#mu = %.3f #pm %.3f", w->var("mu")->getValV(), w->var("mu")->getError())); //#mu = {} #pm {}");
// Have a look at all the objects created in the workspace
w->Print("t") ;
// add negative log likelihood to 2nd plot
c->cd(2);
cout << "\n>>>>>> About to compute negative log-likelihood of fit including subsidiary measurement " << endl;
// Draw -logL vs. mu,
RooPlot* frameNLL = w->var("mu")->frame(0, 2); //, 2);
RooAbsReal* nll = w->pdf("model2")->createNLL(*data) ;
if (!nll) {cout << "ERROR: didn't get -logL. exiting." << endl; return; }
// Plot the nll on a frame with the signal strength parameter
//////// ERROR FROM THIS LINE
nll->plotOn(frameNLL) ;
frameNLL->Draw();
}