Dear experts,
I would like to know if there is the possibility, in RooFit, to define a pdf as the ratio among two linear combinations of pdfs. In particular, in my analysis, I deal with the following scenario:
I have to perform a simultaneous fit of an invariant mass spectrum and another quantity as a function of the mass (the v2 flow harmonic). I fit the invariant mass spectrum with a model which is built as a linear combination of pdfs:
func_1 = a1 * (pdf_gaus) + a2 * (pdf_bkg)
Then, in order to fit the other spectrum, I want to build a function with the following structure:
func_2 = [b1 * (a1 * pdf_gaus) + b2 * (a1 * pdf_bkg)] / (func_1)
So func_2
is basically a weighted average of the components of func_1
. The parameters a1, a2, b1, b2
are free and specific for the two spectra, the gaussian and the background functions are shared among the two models. It is important to note that, in each fit iteration, the func_1
needs to be evaluated locally for each point of func_2
.
I tried to look into the online documentation, but it seems that only sums and products of different pdfs are implemented, so I was wondering if there is some workaround to cover my case. If so, since my case is quite complex, I can surely work to produce a minimum working example to iterate on. Unfortunately by now I am stuck as I do not see ways to perform ratios of pdfs so just an hint on how to define a ratio pdf would be much appreciated.
Thanks!
Welcome on the ROOT Forum!
I’m sure @jonas can help you
Hello,
I managed to progress a bit on my problem, but there are still some things which are unclear to me. You find the status in the attached minimal python script, with the .root
file with the corresponding inputs.
I could implement the func_1
as a RooAddPdf
called total_pdf_mass
, weighting the contributions with fractions, and it works. However, I am having issues in implementing func_2
. I could implement the single components of the function with the structure mass_comp_pdf / func_1
and, if I plot them, the shapes look healthy. However, when I try to build func_2
as a weighted sum of the components I encounter issues.
The implementation of func_2
which you find in the attached file under vn_model
is still simplified with respect to my needs though, as I am going step by step. The ultimate goal is to have separate weights multiplying vn_pdf_bkg
(polynomial weight), vn_pdf_sgn
(constant weight), vn_pdf_templ
(constant weight).
More importantly, the components normalizations should not sum to 1, as they are the physical quantities I am measuring and such behaviour is not expected. For this, I think that the RooRealSumFunc
class would fit my needs better, but I checked that a simultaneous fit of a RooAddPdf
and RooRealSumFunc
cannot be performed. Another alternative which I explored is the RooClassFactory
by putting the required RooFit pdfs as class datamembers, but I had trouble in updating them in the fit minimization.
Any help would be greatly appreciated, thanks in advance!
test.py (5.8 KB)
test.root (8.6 KB)
Let see if @jonas can help