RooMCStudy with different generate&fit PDF and simultaneous fit

Hi,

I’m running RooFit for doing toyMC study with RooMCStudy and RooSimultaneous.

My strategy is,

  1. Get information of signal and background PDF coefficients from file
    (my signal PDF is histogram PDF with RooHistPDF, and background PDF is combination of 1 gaussian + 1 linear function.)
  2. Generate MC with background PDF
  3. Fit them with signal + background PDF
  4. Get value and error of signal PDF constant
  5. Draw figure of 1000 entries of ‘value’ and ‘error’

I expected that the result of 5(especially, value of constant) may be distributed gaussian-like distribution with near 0 mean (like figure below).

But my result is,

I can’t understand why double peaked distribution occurs. Doesn’t RooMCStudy work with RooSimultaneous, or not?

Does anyone help me?
Or if it is not clear then please let me know.

Thank you.

Best regards,
Kyungho Kim

ps. I attached my code and my PDF coefficient variables :
fit_semi_2_1.root (10.6 KB) fit_semi_2_2.root (10.6 KB) rooMC.C (6.9 KB)

Main point of my code is in below :

// signal MC constant setting for simultaneous fit
RooRealVar c_sig("c_sig", "c_sig", 0, -100, 100);
RooRealVar c_e1("c_e1", "c_e1", mode_coef[0]);
RooRealVar c_m1("c_m1", "c_m1", mode_coef[1]);
RooFormulaVar cesig("cesig", "cesig", "c_sig*c_e1/(c_e1+c_m1)", RooArgList(c_sig, c_e1, c_m1));
RooFormulaVar cmsig("cmsig", "cmsig", "c_sig*c_e1/(c_e1+c_m1)", RooArgList(c_sig, c_e1, c_m1));

//// mode 1
// signal PDF
RooHistPdf sig_ehpdf("sig_ehpdf", "sig_ehpdf", RooArgList(pl), *sig_edh, 2);
// background PDF part
RooGaussian gauss_e("gauss_e", "gauss_e", pl, gmean_e, gsigma_e);
RooPolynomial poly("poly", "poly", pl, polycep);
RooAddPdf allpdf("allpdf", "allpdf", pdfs, coefs);
RooRealVar cebkg("cebkg", "cebkg", neb, neb-nee, neb+nee ); // bkg coefficient
// signal + bkg PDF
RooArgList mode_e(sig_ehpdf, allpdf, "mode_e");
RooArgList coef_e(cesig, cebkg, "coef_e");
RooAddPdf e_pdf("e_pdf", "e_pdf", mode_e, coef_e);

//// mode 2
// signal PDF
RooHistPdf sig_mhpdf("sig_mhpdf", "sig_mhpdf", RooArgList(pl), *sig_mdh, 2);
// background PDF
RooGaussian gauss_m("gauss_m", "gauss_m", pl, gmean_m, gsigma_m);
RooPolynomial poly2("poly2", "poly2", pl, polycep2);
RooAddPdf alzpdf("alzpdf", "alzpdf", pdfz, coefz);
RooRealVar cmbkg("cmbkg", "cmbkg", nmb, nmb-nme, nmb+nme);
// signal+bkg PDF
RooArgList mode_m(sig_mhpdf, alzpdf, "mode_m");
RooArgList coef_m(cmsig, cmbkg, "coef_m");
RooAddPdf m_pdf("m_pdf", "m_pdf", mode_m, coef_m);

// simultaneous fit setting
// for fitting
RooCategory sample("sample", "sample");
sample.defineType("emode");
sample.defineType("mmode");
RooSimultaneous *simPdf = new RooSimultaneous("simPdf", "simultaneous pdf", sample);
simPdf->addPdf(e_pdf, "emode");
simPdf->addPdf(m_pdf, "mmode");
// for generation
RooCategory sp2("sp2", "sp2");
sp2.defineType("em");
sp2.defineType("mm");
RooSimultaneous *modPdf = new RooSimultaneous("modPdf", "simultaneous bkg pdf", sp2);
modPdf->addPdf(allpdf, "em");
modPdf->addPdf(alzpdf, "mm");

// RooMCStudy
RooMCStudy* mcstudy = new RooMCStudy(*modPdf, RooArgSet(pl, sp2, sample), FitModel(*simPdf), Binned(kFALSE), Extended(), Silenc    e(), FitOptions(Save(kTRUE), PrintEvalErrors(0))) ;
mcstudy->generateAndFit(1000);

(including after this question is solved)
I should set same categories for generating PDF and fitting PDF.

Hi @K.H.Kim,

it’s hard to say. You could activate information on what is being generated using the Verbose flag from here:
https://root.cern.ch/doc/master/classRooMCStudy.html#a30126934f36ba75cf35f6aa8b06c60f9

Check if it generates reasonable values for the observables of the PDF. In particular, it should generate a value for each of the observables in the simultaneous fit.

Dear @StephanH,

I got message after including Verbose(1).

RooMCStudy: now generating 686 events
— RooSimGenContext —
Using PDF RooSimultaneous::modPdf[ indexCat=sp2 emode=allpdf mmode=alzpdf ]
List of component generators
— RooAddGenContext —
Using PDF RooAddPdf::allpdf[ coef1 * gauss_e + coef2 * poly ]
List of component generators
— RooGenContext —
Using PDF RooGaussian::gauss_e[ x=pl mean=gmean_e sigma=gsigma_e ]
Use PDF generator for (pl)
Use MC sampling generator for (sample)
— RooGenContext —
Using PDF RooPolynomial::poly[ x=pl coefList=(ycept) ]
Use PDF generator for ()
Use MC sampling generator RooFoamGenerator for (pl,sample)
— RooAddGenContext —
Using PDF RooAddPdf::alzpdf[ coef3 * gauss_m + coef4 * poly2 ]
List of component generators
— RooGenContext —
Using PDF RooGaussian::gauss_m[ x=pl mean=gmean_m sigma=gsigma_m ]
Use PDF generator for (pl)
Use MC sampling generator for (sample)
— RooGenContext —
Using PDF RooPolynomial::poly2[ x=pl coefList=(y2cept) ]
Use PDF generator for ()
Use MC sampling generator RooFoamGenerator for (pl,sample)

I can catch that my category name for generation PDF is not sample but sp2.

Then problems would come at calling RooMCStudy :

RooMCStudy* mcstudy = new RooMCStudy(*modPdf, RooArgSet(pl, sp2, sample), FitModel(*simPdf), Verbose(1), Binned(kFALSE), Extended(), Silence(), FitOptions(Save(kTRUE), PrintEvalErrors(0))) ;

(modPdf with sp2 for generating, and simPdf with sample for fitting)

especially RooArgSet(pl, sp2, sample).
(I referred RooMCStudy with simultaneous fit - #4 by dennis question.)

How can I include category type when constructing RooMCStudy?
(Or is it not a problem?)

Thank you.

Best regards,
Kyungho Kim

Hi @K.H.Kim,

could it be that passing two different category object creates the problem? How should the MCStudy know how to associate (emode, mmode) to (em, mm)?
There is no reason that these two should correspond to each other. So what it does (I assume) is to generate in terms of emode & mmode, but when fitting it cannot associate these to the fitting categories. Would it be an option to unify the categories?

1 Like

Dear @StephanH,

Thanks for your suggestion.
I tried it : unifying the categories.

RooCategory sample("sample", "sample");
sample.defineType("emode");
sample.defineType("mmode");

RooSimultaneous *simPdf = new RooSimultaneous("simPdf", "simultaneous pdf", sample);
simPdf->addPdf(e_pdf, "emode");
simPdf->addPdf(m_pdf, "mmode");

RooSimultaneous *modPdf = new RooSimultaneous("modPdf", "simultaneous bkg pdf", sample);
modPdf->addPdf(allpdf, "emode");
modPdf->addPdf(alzpdf, "mmode");

And the result is what I expected!

As you said, I don’t have to use 2 categories for each mode. 1 category is just enough.

Thank you!

Best regards,
Kyungho Kim

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