Log-scale messes up RooPlot (RooProdPdf)

Hi everybody,

I have some trouble with a RooPlot lately. What I try to do is using a histogram as input pdfs and then fit the pdfs to the same or some other histogram with Roofit. Afterwards I would like to plot the data, the model components and the model with errors. On the linear scale this works perfectly and everything looks nice. However, as soon as I switch to a log-scale weird things start to happen. Sometimes model components are drawn outside of the plotting area:

If I also plot the model with “VisualizeErrors” it gets even worse:

In the first case, clicking on some of the weird components (in the canvas) immediately removes the weird parts. However, this is not ideal for me as I would like to produce many plots directly and not cure and save every single plot by hand. In the second case (Model with error) not even clicking resolves the issue. I also tried to invoke canvas->Modified() and canvas->Update() without success. Could you please help me?
I am using Root 6.18/02 on ubuntu 16.04.

The plot is created as:

      TCanvas *c03 = new TCanvas("c03", "c03", 80, 0, 1440, 1200);
      RooPlot *xframe02 = f90.frame(Title("RooFit fit"));
      hdata_neutron.plotOn(xframe02, Name("Data"));
      model.plotOn(xframe02, VisualizeError(*fit_result_neutron, 1), Name("Model with errors"));
      hdata_neutron.plotOn(xframe02);
      // model.paramOn(xframe02, Layout(0.55));
      model.plotOn(xframe02, Name("ER gauss"), Components(pdf_parmetrized_histo_bkg), LineColor(kRed));
      model.plotOn(xframe02, Name("NR template"), Components(pdf_parametrized_histo_sig), LineColor(kGreen));
      xframe02->SetTitle("");
      xframe02->SetMinimum(1e-1);
      xframe02->SetMaximum(1e6);
      xframe02->Draw();
      c03->SetLogy();
      c03->SetGridx();
      c03->SetGridy();
      c03->Modified();
      c03->Update();
      TLegend *leg03 = new TLegend(0.50, 0.64, 0.93, 0.93);
      leg03->AddEntry("Data", "Neutron data", "LEP");
      leg03->AddEntry("ER gauss", "ER gaussian template", "F");
      leg03->AddEntry("NR template", "NR leftover template", "F");
      // leg03->AddEntry("Model with errors", "Model with errors", "F");
      leg03->SetTextSize(0.035);
      leg03->Draw();
      c03->SetLeftMargin(0.13);
      if (SavePlots) {c03->SaveAs((OutputPath + "Combined_ER_and_NR_pdf_fit_in_neutron_data_Bin_" + std::to_string(bin_nr) + "." + PlotFileType).c_str()); }

Some of the entries of the components are manually set to zero. At first I thought maybe this causes an issue on the log-scale. But setting it to 0.00001 instead still leads to the same problem. So I am a bit clueless and any help would be well appreciated :slight_smile:

Yes that’s weird.
Can you provide a script we can run reproducing the problem ?

Yes, I did my best to provide a minimal working example. Running “root -l DummyTest.C” while having the file “DummyData.root” in the same folder should reproduce the problem. Best

DummyTest.C (9.1 KB)
DummyData.root (6.1 KB)

I do not see this weird effect with the latest ROOT version.

Hmm interesting. While you do not have the green lines going out of the plot, you do also habe this weird line going through the labels of the y-axis though as I do. So the problem is reduced but not resolved?
Also I use root v 6.18/02, which is not very old I think.

Can you try with a more recent version ?
This might have been fixed since 6.18.

1 Like

Here is what I get with the master on Windows

1 Like

Oh wow, yes it worked!! I updated to ROOT v 6.24/02 and indeed all components are plotted nicely. Thanks a lot and I am glad that the update did the trick.

PS: I think the black line through the y-labels that @couet had are reminiscent of the call to “SetLeftMargin()”. Somehow the “old” left margin remained… I don’t know if this is useful. But anyway in the newest version this seems to be resolved :slight_smile:

2 Likes

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