I am using the iterative (“Bayesian”) method based on the Roounfolding package to do unfolding for my analysis, and I already filled the response matrix R by response = ROOT.RooUnfoldResponse (hMeas, hTrue),

but now I want to do the backfolding test, which means I should get the R^(-1), I was wondering is there a way to get R^(-1) directly if I already have R prepared? Otherwise should I get the R^(-1) by filling it again with response = ROOT.RooUnfoldResponse (hTrue, hMeas)?

Hi Jen!
Thanks @jonas for tagging me.
Indeed RooUnfold is a comparatively small project, and experts are usually in high demand - so sorry for dropping the ball on your question.

As for the matter at hand: the way in which the unfolding is done depends very much on the method you use. In principle, not all methods even need to have an “inverse migration matrix”, since whether the computation is done as a matrix or in a different way is very much up to the method.
Strictly speaking, R^-1 is only available for RooUnfoldInvert, which is the unregularized matrix-inversion method.
You are in luck though, because RooUnfoldBayes does provide a method called “UnfoldingMatrix”, which gives you back a matrix that is used to propagate the errors between the folded and the unfolded space - depending on what you’re trying to do, this might be just what you need.
In general, it would be interesting to understand what you’re trying to achieve, as the inverse of the folding matrix is strictly speaking only related to your unfolding method when you use RooUnfoldInvert.

Please feel free to follow up with further questions.
Regards,
Carsten

So for the UnfoldingMatrix, will it give you the inverse of a matrix? I have the response matrix and want to get it inverse matrix now. Could you show me an example code how to do it?

And what I am trying to achieve, is that I want to do backfolding test.

I already filled the response matrix R by
response = ROOT.RooUnfoldResponse (hMeas, hTrue),
and then as a closure test, I use Bayes method to do the unfolding to get the hTrue

unfold= ROOT.RooUnfoldBayes (response, hMeas, 1);

which is succeeded.

Then I want to do another test, which is use the inverse of the matrix and hGen to get hMeas, ie the backfolding test.

So I need to get the inverse of the matrix.

Or do you know any other way to do backfolding in the roounfolding?

They are roughly inverses of one another. hMresponse is the response matrix, e.g. the matrix that maps your unfolded space to your folded space. Depending on whether you put true or false as an argument, you will receive the normalized or non-normalized version. hUMatrix is then the regularized unfolding matrix, that is, it’s basically the regularized form of the inverse of the matrix you get when you do Mresponse(true).