RooMinimizer + createNLL : Possibility of SumW2Error?

Hello experts,

I am using a framework called xmlAnaWSBuilder ( more info here ) which is a tool for creating RooFit workspaces using 1-d observables .

This project is really nice and does an excelent job when it comes to REAL data.

To my understanding it creates a NLL and uses RooMinimizer ( see here ) to also obtain the best parameters for some exponential functions used to model the background.

However this is not working properly as the background exponential parameter errors are higher than expected for mc data as the SumW2 error is not calculated. I don’t see any usage of the fitTo function ((see here for doc) that utilizes the SumW2Error() method.

I was wondering whether there is a way to calculate the correct sumw2 errors through createNLL and RooMinimizer.

I also found these helper functions : FitHelpers that might do the trick but I would like some expert opinions as I am a newbie in such topics.

Thank you very much!

Hi @smeriano,

Let me add @jonas in the loop who might be able to help you.

Best,
Dev

Hi @devajith ,

Thank you very much! Just an update that I replaced RooMinimizer + createNLL with RooFitResult’s fitTo. Specifically these lines here with


int fitUtil::profileToData(ModelConfig *mc, RooAbsData *data, TString rangeName)
{
  RooAbsPdf *pdf = mc->GetPdf();
  RooWorkspace *w = mc->GetWS();
  RooArgSet funcs = w->allPdfs();

  for (auto it = funcs.begin(); it != funcs.end(); ++it)
  {
    RooAbsPdf *v = dynamic_cast<RooAbsPdf *>(*it);
    if (v && v->IsA() == RooRealSumPdf::Class())
    {
      spdlog::warn("Set binned likelihood for: {}", v->GetName());
      v->setAttribute("BinnedLikelihood", true);
    }
  }

  // Prepare options for fitTo
  RooCmdArg rangeCmd = (rangeName != "") ? Range(rangeName) : RooCmdArg::none();
  RooCmdArg offsetCmd = (_nllOffset) ? Offset(true) : RooCmdArg::none();
  RooCmdArg globalObsCmd = GlobalObservables(*mc->GetGlobalObservables());

  spdlog::warn("Performing fit using fitTo");

  // Create a RooLinkedList for the fit options
  RooLinkedList fitOptions;
  fitOptions.Add((rangeName != "") ? new RooCmdArg(Range(rangeName)) : nullptr);
  fitOptions.Add((_nllOffset) ? new RooCmdArg(Offset(true)) : nullptr);
  fitOptions.Add(new RooCmdArg(GlobalObservables(*mc->GetGlobalObservables())));
  fitOptions.Add(new RooCmdArg(Save(true)));                // Save the fit result
  fitOptions.Add(new RooCmdArg(SumW2Error(true)));          // Account for weighted likelihood
  fitOptions.Add(new RooCmdArg(Minimizer("Minuit2", "migrad"))); // Minimizer settings
  fitOptions.Add(new RooCmdArg(PrintLevel(_printLevel - 1)));
  fitOptions.Add(new RooCmdArg(Strategy(_minimizerStrategy)));
  fitOptions.Add(new RooCmdArg(RooFit::Offset())); 
  fitOptions.Add(new RooCmdArg(RooFit::Extended()));              // Precise error estimates

  // Perform the fit
  RooFitResult *fitResult = pdf->fitTo(*data, fitOptions);

  if (!fitResult || fitResult->status() != 0)
  {
    spdlog::error("Fit failed with status {}", fitResult ? fitResult->status() : -1);
    return fitResult ? fitResult->status() : -1;
  }

  spdlog::info("Fit completed successfully with status {}", fitResult->status());
  
  data->Print("v");



  spdlog::info("Covariance matrix:");
  fitResult->correlationMatrix().Print("v");
  spdlog::info("Errors:");
  fitResult->floatParsFinal().Print("v");

  delete fitResult; // Clean up
  return 0; // Success
}

This seems to result to the same exponential parameters with reduced errors. I will have to search this a bit more extensively from my side as well.

Hi @smeriano, thanks for the good question!

The relevant helper function that fitTo() uses internally in unfortunately not part of the public interface, but you can take a look at the code and do the same of course:

If it turns out that you want to do the covariance matrix corrections also when using createNLL+RooMinimizer, please open a GitHub issue where you request to make the relevant methods public, probably as member functions of the RooMinimizer I guess.

Cheers,
Jonas

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