SetShowProjection highlights the wrong position with logarithmic axis

Hi all,

small reproducible:

import ROOT

h = ROOT.RDataFrame(100000)\
         .Define("x", "gRandom->Uniform(0., 5.)")\
         .Define("y", "gRandom->Uniform(0., 5.)")\
         .Histo2D(("h", "title;x;y", 100, 0.001, 5, 100, 0., 5), "x", "y")

c = ROOT.TCanvas()
h.Draw("colz")
h.SetStats(0)
c.SetLogx()
c.Update()
input("wait")

right-click on the histogram and SetShowProjectionY

Expected:

Highlighted bin should be the one, where mouse is hovering (the same bin which is being plotted on c1_n2 canvas)

Output:

Hovering the mouse over the left-most bin highlights the wrong bin starting at value one.

Changing axis back to the linear scale (even with the UI) does proper highlighting of the selected bin.

ROOT Version: 6.26/06

I went to C++:

void foxwise() {
   auto h = ROOT::RDataFrame(100000)
            .Define("x", "gRandom->Uniform(0., 5.)")
            .Define("y", "gRandom->Uniform(0., 5.)")
            .Histo2D(("h", "title;x;y", 100, 0.001, 5, 100, 0., 5), "x", "y");
   auto c = new TCanvas();
   h->Draw("colz");
   h->SetStats(0);
   c->SetLogx();
}

I get:

foxwise.C:5:14: error: no matching member function for call to 'Histo2D'
            .Histo2D(("h", "title;x;y", 100, 0.001, 5, 100, 0., 5), "x", "y");
            ~^~~~~~~

@couet

It compiles for me using {} brackets for the Histogram model inside Histo2D, instead of () in python.

void foxwise() {
   auto h = ROOT::RDataFrame(100000)
            .Define("x", "gRandom->Uniform(0., 5.)")
            .Define("y", "gRandom->Uniform(0., 5.)")
            .Histo2D({"h", "title;x;y", 100, 0.001, 5, 100, 0., 5}, "x", "y");
   auto c = new TCanvas();
   h->Draw("colz");
   h->SetStats(0);
   c->SetLogx();
}

But I get blank canvas. Which I am not sure how to deal with…

@couet Here is the working reproducible in C++, w/o RDataFrame

void foxwise() {
   auto h = new TH2F("h", "title;x;y", 100, 0.001, 5, 100, 0., 5);
   for(int i=0; i < 100000; i++){
      double x = gRandom->Uniform(0., 5.);
      double y = gRandom->Uniform(0., 5.);
      h->Fill(x, y);
   }

   auto c = new TCanvas();
   h->Draw("colz");
   h->SetStats(0);
   c->SetLogx();
}
// right-click on the histogram and SetShowProjectionY afterwards

@eguiraud , do you have an idea, why RDataFrame version above, shows a blank canvas in the end?
Or it is just for me?

It’s a common lifetime issue: the histogram goes out of scope at the end of the function. See e.g. I draw a canvas with no picture - #3 by eguiraud . Possible solutions are calling DrawClone instead of Draw or returning the histogram from the function to keep it alive in the outer scope.

1 Like

I can run your example now.
Seems to me that ProjectionY takes into account the fact there is a log scale along X. The mouse moves are correctly reflected in the new window: the 1D histogram changes at the border of log bins. It is hard to tell if the histogram is correct or not thought.

Yes, ProjectionY works properly. It is only the highlighting is wrong.
If you switch to the linear scale, highlighted bin will indicate the bin where the mouse is. Just for easier visual tracking of the plotted bin in the second window.
With the logarithmic axis, the bin where the mouse is is NOT highlighted. Highlighted are some random bins on the right.

So it’s really a visual convenience bug, not a calculation one

Actually for me there is not bin highlighting at all, neither in linear or log scale. I move the cursor over the COL plot and I see the 1D histogram changing.

Huh? Interesting…

I see … I do not have the red highlight bars … (on Mac …)

1 Like

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