Hello,
I need to make a morphing interpolation using real functions (RooAbsReal objects) instead of PDFs (RooAbsPdf objects).
The class RooMomentMorph is perfect for what I need, but it just doesn’t accept non-PDF inputs.
Is there any alternative implementation of the algorithm that makes the trick?

Hi @jonas, thanks a lot for your reply.
Yes, indeed RooMomentMorphFunc seems to be what I was looking for.
However, I have found it can not handle negative values. Is it a general limit of the morphing itself? My goal was exactly to morph functions which take negative values (i.e. non-PDFs).
I have attached a working example showing what I mean. morphing.py (3.6 KB)

[#0] ERROR:Eval -- RooAbsReal::logEvalError(int_yy_1_MOMENT_2C_m_yy) evaluation error,
origin : RooSecondMoment::int_yy_1_MOMENT_2C_m_yy[ nset=() function=int_yy_1 x=m_yy ]
message : function value is NAN
server values: nset=(), function=int_yy_1=0, x=m_yy=125, !mean=int_yy_1_MOMENT_1_m_yy=-138.935, !xf=int_yy_1_MOMENT_2C_m_yy_product=0, !ixf=int_yy_1_MOMENT_2C_m_yy_product_Int[m_yy]=-601014, !if=int_yy_1_Int[m_yy]=8.63787

Hi @lucaf! Yes, it is a limitation of the morphing itself as it is defined mathematically. It uses the standard deviation of the function, which is undefined if the second moment of the function is negative as in your case.

You can circumvent this limitation by transforming your functions such that the second moment when integrating over the variable range is positive, for example by adding a constant. You could use RooFormulaVar for that I attached here an example of how you could do it:

Hi @jonas. OK, I understand your explanation, thanks!

So you think that adding a constant will not introduce a bias in the morphing?
I would just add the same constant to all the input functions before the morphing, such that they’re positive in the target range.
Then I would subtract that constant to the final morphed function in order to get back to the initial situation.
What do you think?

yes that’s what I suggest. There is no bias in the morphing from adding a constant. I have also tried out hacking RooSecondMoment to deal with negative second moments, and I get the same morphing result as when adding a constant.

If you want to make that study yourself, you can change this line in ROOT such that it returns the sqrt of the absolute value times the sign. But we can’t do this in the release, because it would give wrong morphing results if you have some templates with positive and some template with negative second moments.

By the way, I also saw that the Moment morphing doesn’t work that well for your function. The morphed function is very different from the true function. But that is a different problem

Cheers and let me know if you have further questions!
Jonas