How to extract the parameter from the fitted Gaussian function to pullplot in RooMCStudy?

Dear Experts,

I am doing some toy mc study using RooMCStudy module. I can do the pull plot for signal and background and fit it with gaussian using the plotPull() function and display the fitted parameter (mean and sigma) on the plot. But I want to retrieve the mean and sigma inside the root macro and save it in the txt file. Is there any easy way how I could do that? Because I am doing so many pulls for different signal and background hypotheses (and also different mass hypotheses) it would be easier for me if I can retrieve them and save it in txt file. Any help into this matter will be highly appreciated.

Root version: 6.21
Os : MacOs

Best Regards
Rajesh

Dear all,

Any help into this topic will be highly appreciated.

Thanks
Rajesh

Perhaps @jonas can help

Hi @RAJESH_KUMAR_MAITI, sorry for the very late reply!

There is no way to get the numerical values of the pull distribution fit parameters when you use RooMCStudy::plotPull. But you can copy-paste the relevant code from said function where the Gaussian fit is done, and write your own function that returns the pull distribution fit results. It could look like this:

std::pair<double,double> fitMCStudyPulls(
        RooMCStudy& mcStudy, RooAbsReal const& param) {

  using namespace RooFit;

  auto& fitParData = const_cast<RooDataSet&>(mcStudy.fitParDataSet());
  auto pullName = std::string(param.GetName()) + "pull";
  auto pullTitle = std::string(param.GetTitle()) + " Pull";
  RooRealVar pvar(pullName.c_str(), pullTitle.c_str(), -100, 100) ;
  pvar.setBins(100) ;
  RooRealVar pullMean("pullMean","Mean of pull",0,-10,10) ;
  RooRealVar pullSigma("pullSigma","Width of pull",1,0.1,5) ;
  RooGenericPdf pullGauss("pullGauss","Gaussian of pull",
                          "exp(-0.5*(@0-@1)*(@0-@1)/(@2*@2))",
                          RooArgSet(pvar,pullMean,pullSigma)) ;
  pullGauss.fitTo(fitParData, Minos(0), PrintLevel(-1)) ;
  return {pullMean.getVal(), pullSigma.getVal()};
  // Or have some sort of output structure where you can
  // also return the uncertainty if you want. You can get them like
  // pullMean.getError(), pullSigma.getError()
};

You would use it like this:

   auto pullFitParams = fitMCStudyPulls(*mcstudy, mean);
   std::cout << "Pull mean: " << pullFitParams.first << std::endl;
   std::cout << "Pull sigma: " << pullFitParams.second << std::endl;

Instead of printing the results, you can dump them into a text file or whatever you like.

I hope this helps! Please let me know if something is unclear or if you have any further questions.

Cheers,
Jonas

Hi @jonas

Thanks for your reply.

Yes I understood this. Actually I Did something more simpler, I came to know from RooMCStudy module (line 922 - 924) that, this all pull related variables are saved in fitParDataSet(). I mean if one would like to calculate pull for some variable sig, then corresponding pull variable is “sig_pull”. So one could just do, TH1 *frame1 = mcstudy->fitParDataSet().createHistogram(“sig_pull”); frame1->Fit(“gaus”); frame1->GetFunction(“gaus”)->GetParameter(1); frame1->GetFunction(“gaus”)->GetParameter(2);

Is that okay?

Thank you,
Regards
Rajesh

Hi @RAJESH_KUMAR_MAITI,

sure, you can do that too. But keep in mind that since you created a histogram, you will now make a binned fit of the pull means instead of an unbinned fit with the RooDataSet directly like I proposed. So your results might be different from what is shown on the plot.

I would argue that the unbinned fit is better here, since it uses more information. If you stay with the binned fit, I would still manually verify that the binning that is used for the histogram makes sense.

Cheers,
Jonas

Hi @jonas

Ah, this is good point, I missed that. Yes I will convert to unbinned one (as my all of fittings are unbinned).

Thank you.

Cheers
Rajesh

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