Hello,
I was trying to set up a simple ‘counting experiment’ model, making use of RooExtendedTerm to give me a simple event count model, with an uncertainty on the expected count given by a gaussian constraint on a term in the mean expression. Here’s what I tried to do, to represent a counting experiment for a predicted count of 10 +/- 0.2 events:
RooWorkspace* w= new RooWorkspace;
w->factory("Gaussian::L_constraint(L_nom[10],L[10,0,20],0.2)");
w->factory("PROD::full_model( RooExtendedTerm::model( L ) , L_constraint )");
However, when I create a dummy dataset with an event weight of 5 in it, and use that to make the nll object, I don’t see the expected result:
w->factory("weightVar[10,0,100]");
w->factory("dummy_obs[1,0,1]");
w->defineSet("obs","dummy_obs,weightVar");
RooDataSet data("data","data",*w->set("obs"),WeightVar("weightVar"));
data.add(*w->set("obs"),5);
RooAbsReal* nll1 = w->pdf("full_model")->createNLL(data);
std::cout << " expected = " << -log(ROOT::Math::gaussian_pdf(10,0.2,10)) + (10. - 5*log(10.)) << std::endl;
std::cout << " nll1 = " << nll1->getVal() << std::endl; //this is missing the L_constraint contribution
The output from the above code is:
[#1] INFO:Minization -- p.d.f. provides expected number of events, including extended term in likelihood.
[#1] INFO:Minization -- RooProdPdf::getConstraints(full_model) omitting term model as constraint term as it does not share any parameters with the other pdfs in product. To force inclusion in likelihood, add an explicit Constrain() argument for the target parameter
[#1] INFO:Minization -- RooProdPdf::getConstraints(full_model) omitting term L_constraint as constraint term as it does not share any parameters with the other pdfs in product. To force inclusion in likelihood, add an explicit Constrain() argument for the target parameter
expected = -2.20342
nll1 = -1.51293
However, if I construct an alternative model, using the RooRealSumPdf entity, with a dummy constant and dummy observable:
w->factory("PROD::alt_full_model( ASUM::alt_model( dummyConst[1,0,100]*expr::mean_a('L',dummy_obs,L)) , L_constraint)");
RooAbsReal* nll3 = w->pdf("alt_full_model")->createNLL(data);
std::cout << " nll3 = " << nll3->getVal() << std::endl;
The result is the expected:
[#1] INFO:Minization -- p.d.f. provides expected number of events, including extended term in likelihood.
[#1] INFO:NumericIntegration -- RooRealIntegral::init(mean_a_Int[dummy_obs]) using numeric integrator RooIntegrator1D to calculate Int(dummy_obs)
[#1] INFO:Minization -- Including the following contraint terms in minimization: (L_constraint)
nll3 = -2.20342
Specifying that I want to constrain the “L” variable when I make the NLL object doesn’t work either:
RooAbsReal* nll2 = w->pdf("full_model")->createNLL(data,Constrain(*w->var("L")));
std::cout << " nll2 = " << nll2->getVal() << std::endl; //so is this!
This gives the same result as nll1
Is there a problem with how RooProdPdf deals with a RooExtendedTerm, which is independent of all observables? Having a look at the code, I think it might be possible to ‘fix’ this behaviour by accounting for the presence of an extended pdf in the prodPdf in the ‘getConstraints’ method of RooProdPdf. Specifically, if you modified the line here: root.cern.ch/root/html/src/RooP … .html#2226 to include a requirement that the term is not extended, i.e:
if (!pdf->dependsOnValue(observables) && !pdf->canBeExtended() && pdf->dependsOnValue(constrainedParams)) {
I think that would make the constraint be included?
Hope that all makes sense. Please let me know how I should proceed! I really would rather not have to use the RooRealSumPdf approach for my simple counting experiment model, if possible!
Thanks
Will