Problem with simultaneous fit in two subranges on multiple variables

Dear experts,

I’m trying to perform a simultaneous fit over two distinct variables (mass and transverse momentum).
Initially, I faced no problems working in two specific mass and transverse momentum regions. The problems arise when I want to extend the mass region, selecting two specific ranges, with the following error:

RooAbsTestStatistic::initSimMode: creating slave calculator #1 for state transversemomentum (73504 dataset entries)
terminate called after throwing an instance of ‘std::runtime_error’
what(): Error in RooAbsData::reduce! The ranges mregion1,mregion2 are overlapping!

In the following I attach the small version of the code that I’m using:

RooWorkspace *w = (RooWorkspace *)fIn->Get("w");
  w->Print();

  RooRealVar *m = w->var("m");
  m->setRange("mregion1", 4, 9);
  m->setRange("mregion2", 11, 30);
  RooRealVar *pt = w->var("pt");
  m->setBins(Binning_m);
  pt->setBins(Binning_pt);

  RooCategory sample("sample", "sample");
  sample.defineType("mass");
  sample.defineType("transversemomentum");
  TFile *fIn_data = new TFile("~/dimuon_HF_pp/data/LHC18p/Hist_AOD/3_11_2022/TreeResults_merged.root", "READ");

  // Taking data saved in tree
  TTree *tree_data = (TTree *)fIn_data->Get(Form("rec_data_tree%s", mass_range_data.Data()));
  RooDataSet *unbinned_M_Dimu_data = new RooDataSet("M_Dimu_data", "M_Dimu_data", RooArgSet(*m), Import(*tree_data), Cut("m<9 || (m>11 && m<30)"));
  RooDataSet *unbinned_Pt_Dimu_data = new RooDataSet("Pt_Dimu_data", "Pt_Dimu_data", RooArgSet(*pt), Import(*tree_data)); // 5
  RooDataSet *unbinned_combData_set = new RooDataSet("combData", "combined data", RooArgSet(*m, *pt), Index(sample), Import("mass", *unbinned_M_Dimu_data), Import("transversemomentum", *unbinned_Pt_Dimu_data));

RooAddPdf *m_model = new RooAddPdf("m_model", "n_charm_output*dimuMassFromC + n_beauty_output*dimuMassFromB + n_mixed_output*dimuMassFromMixed", RooArgList(*pdfDimuMassFromBeauty, *pdfDimuMassFromCharm, *pdfDimuMassFromMixed), RooArgList(*normForB, *normForC, *normForMixed));
RooAddPdf *pt_model = new RooAddPdf("pt_model", "n_charm_output*dimuPtFromC + n_beauty_output*dimuPtFromB + n_mixed_output*dimuPtFromMixed", RooArgList(*pdfDimuPtFromBeauty, *pdfDimuPtFromCharm, *pdfDimuPtFromMixed), RooArgList(*normForB, *normForC, *normForMixed));

RooSimultaneous simPdf("simPdf", "simultaneous pdf", sample);
simPdf.addPdf(*m_model, "mass");
simPdf.addPdf(*pt_model, "transversemomentum");
  
RooFitResult *r = simPdf.fitTo(*unbinned_combData_set, Minimizer("Minuit2"), Range("mregion1,mregion2"), Save(), SumW2Error(true));

Thanks in advance for any help,
Michele

Hello,

The ranges defined as in the code seem not to overlap. Strange you are getting that error. Maybe @jonas can investigate this in more detail. Probably we would need access to your Workspace and input data file to reproduce the problem

Best regards

Lorenzo

Dear Lorenzo,

Thanks a lot for answering.
Indeed, I found it a bit weird myself. When I try to perform the fit only on the mass component, this problem doesn’t arise for some reason, so I would say it is somewhat related to using the RooSimultaneous. I tried to debug it a bit, but I found it beyond my RooFit knowledge.

Kind Regards,
Michele

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

Hi @michelepennisi,

sorry for the late reply! I’m answering anyway in case it still helps someone.

The problem is that you are not defining the ranges mregion1 and mregion2 also for pt. Hence, they are implicitly created to be both the full range for pt, meaning they overlap fully. You can fix this by defining non-overlapping dummy ranges also for pt (e.g. one of them is the full range, the other is empty):

  pt->setRange("mregion1", pt->getMin(), pt->getMax());
  pt->setRange("mregion2", pt->getMin(), pt->getMin());

Another workaround for ranged fits with the RooSimultaneous in this case could be using the SplitRange() command argument, mentioned in the docs for RooAbsPdf::createNLL(). You can see an example in this unit test. But I think in this case it’s more complicated than the simple workaround above.

I agree that the configuration of multi-ranged simultaneous fits is confusing. I’ll note this in the ideas for RooFit GitHub issue, so we can improve this if someone finds the time.

Cheers,
Jonas

Hi Jonas,
thanks a lot for answering. After many attempts, I’ve arrived at a similar conclusion, separating the range in pt (for example 0-30 split in 0-10 and 10-30), and trying different dummy ranges to be sure the results remain consistent.

Anyway, the fact that you’ve suggested a similar conclusion is super comforting.

Thanks a lot.
Cheers,
Michele