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:
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.
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 RooAddPdfand 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!
The benefit of using RooAddPdf and related classes is that RooFit can figure out how to analytically normalize the pdfs in case the analytic integrals of the components in known. However, by dividing by other pdfs/functions, you completely lose the benefit because the analytical integral would not be simple anymore.
In your case, you would be much better off just defining your own functions and wrapping them in the RooGenericPdf, which is made for cases like this.
thanks for the reply. In the python script attached to the previous reply I was already considering using the RooGenericPdf class, but I think that doesn’t cover my case. Maybe I can recap the situation so that you can understand better:
I want to perform a simultaneous fit on two binned histograms
One of the functions can be implemented easily as a RooAddPdf and is called total_pdf_mass in the python script
The other function is tricky as it is not a pdf (I am not fitting counts on the second histogram). In the attached python script, I used RooGenericPdf to implement its components, but then I need to obtain a linear combination of them with the coefficients left as free parameters to be fitted. Thus, looking at the RooFit documentation, I think that the class that suits the most for implementing such function is RooRealSumFunc (please don’t consider the vn_model function I implemented at the end of the code snippet I attached, it’s wrong).
However, when I look at the RooSimultaneous class, I see that the simultaneous fit is implemented only for pdfs. Did I get it correctly? If so, is there any workaround that I can implement? I thought about defining a custom chi2, but I coudn’t find anything related to it in RooFit.