# RooLinearVar and plot projections

Hello

In my model I have a multidimensional pdf, for which all relevant analytical integrals are implemented. The pdf has, as observables, nDim `RooLinearVar`.
Since `RooLinearVar` is a `RooAbsRealLValue`, it should transparently propagate the integral and indeed, if I just create the integral with `createIntegral` or even during fitting, it correctly integrates the pdf analytically.
However, if I try to plot the pdf in one of its dimensions, the plot projection integral does not use the internal integral at all, and is instead numeric (very slow in my case, as nDim > 2 and the pdf is complex)

This is an example using a gaussian, which is almost accurate (`RooGaussian` does not have 2D integrals, but can integrate 1D both in x or mu)

``````import ROOT
from ROOT.RooFit import RooConst

x = ROOT.RooRealVar('x', '', 0, 1)
y = ROOT.RooRealVar('y', '', 0, 1)

x2 = ROOT.RooLinearVar('x2', '', x, RooConst(1), RooConst(0))
y2 = ROOT.RooLinearVar('y2', '', y, RooConst(1), RooConst(0))

D2 = ROOT.RooGaussian('g', '', x2, y2, RooConst(0.2))

# needed only to set the correct normalization in the frame
dt = D2.generate({x,y}, NumEvents = 10)

#ROOT.RooMsgService.instance().addStream(ROOT.RooFit.DEBUG, Topic = ROOT.RooFit.Integration)

# works fine, numerical integral only for the 2D normalization integral
# but not in the y projection
# if the pdf supported 2D integrals, there would be no numerical integrals at all
integral = D2.createIntegral({y}, NormSet = {x,y})
print('Projection is', integral, flush = True)

# numerical integral in the 2D normalization (expected, like above)
# numerical integral in the y projection (unwanted)
frame = x.frame()
dt.plotOn(frame)
D2.plotOn(frame)
``````

The last integral, in y, should not be needed, because `RooGaussian` knows how to integrate over the mean. However, if we enable Integration debug log, we can see that in the first case y2 is considered for analytical integration, while in the second case it is not.

How can I actually convince RooFit that the analytical integral is ok?

Thank you in advance.

Apologies for the slow response… Maybe @jonas can help here?

To add a few info that I gathered while debugging:

• The variables that are used in the plot projection do not have clients, so they are not considered in the search for lvalue dependents
• Even if I pass the actual function variables using `Project`, the lvalues are compared by pointer, which does not match the cloned function servers

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.