Skip to content

[RF] RooParamHistFunc: analytical integral inconsistent with value for paramRelative = false #24003

Closed as not planned

Description

@cburgard

Check duplicate issues.

  • Checked for duplicates

Description

With paramRelative = false, the value of a RooParamHistFunc in bin i is the parameter p_i, but its analytical integral is Σ p_i · w_i · vol_i, where w_i is the content of the histogram the function was built from. The integral should be Σ p_i · vol_i, consistent with the value.

evaluate() multiplies by the nominal content only if _relParam is set:

double ret = (static_cast<RooAbsReal*>(_p.at(idx)))->getVal() ;
return _relParam ? ret * getNominal(idx) : ret;

while analyticalIntegralWN() always sums the histogram weights, scaled by the parameters, regardless of _relParam:

auto getBinScale = [&](int iBin){ return static_cast<const RooAbsReal&>(_p[iBin]).getVal(); };
return const_cast<RooDataHist&>(_dh).sum(_x, sliceSet, true, false, ranges, getBinScale);

For paramRelative = true (the default), both agree.

Reproducer

void paramhist_relparam()
{
   RooRealVar x{"x", "x", 0.0, 2.0};
   x.setBins(2);
   RooDataHist dh{"dh", "dh", x};
   x.setBin(0);
   dh.set(x, 2.0);
   x.setBin(1);
   dh.set(x, 3.0);

   for (bool relParam : {true, false}) {
      RooParamHistFunc f{"f", "f", dh, x, nullptr, relParam};
      double sumOfValues = 0.0;
      for (int i = 0; i < 2; ++i) {
         x.setBin(i);
         sumOfValues += f.getVal() * 1.0; // bin width 1
      }
      std::unique_ptr<RooAbsReal> integral{f.createIntegral(x)};
      std::cout << "relParam=" << relParam << ": sum of value*width = " << sumOfValues
                << ", createIntegral(x) = " << integral->getVal() << std::endl;
   }
}

Output:

relParam=1: sum of value*width = 5, createIntegral(x) = 5
relParam=0: sum of value*width = 5, createIntegral(x) = 13

With paramRelative = false, the parameters are initialized to the bin contents (2 and 3), so the integral comes out as 2·2 + 3·3 = 13 instead of 2 + 3 = 5.

ROOT version

master (6.41.01), at 507d28258e0.

Installation method

Built from source.

Operating system

Ubuntu 26.04, GCC 15.2.

Additional context

The range handling of this integral was fixed in #7182; the RooDataHist::sum with a bin-scale lambda is probably from that change.

This came up while mapping RooParamHistFunc to HS3 (the RooFit JSON format). #24002 writes a RooParamHistFunc with relative parameters like a HistFactory sample: a product of a RooHistFunc and the HistFactory ParamHistFunc (whose HS3 I/O is reworked in #24001). For absolute parameters, the natural mapping would be a ParamHistFunc alone. Its integral is consistent with its value, so it would differ from the current integral of RooParamHistFunc. #24002 therefore rejects absolute parameters with an error for now.

Question to the RooFit developers: will this be fixed, or is RooParamHistFunc going to be deprecated (in favour of ParamHistFunc), so that bugs in it won't be fixed any more? That decides whether #24002 should map absolute parameters to ParamHistFunc (changing the integral to the consistent one) or keep rejecting them.

Activity

  1. guitargeek commented on Nov 6, 2026

    @guitargeek
    Contributor

    Actually, I planned to deprecate RooParamHistFunc and the associated RooHistConstraint years ago, but there was never a strong enough justification to really to it.

    I think that someone once again spent time now on understanding the differences between RooParamHistFunc and ParamHistFunc and hit the quirks that I so far accepted as "won't fix" is a pretty strong indication that the deprecation should go ahead. I have updated this three-years-old PR that does it:

  2. guitargeek commented on Nov 6, 2026

    @guitargeek
    Contributor

    "not planned" because RooParamHistFunc was deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions