TMarker in TH2D

Dear all,
I’ve been trying to highlight the minimum in a TH2D using a marker. The code right now looks something like this:

  TH2D* h1 = NULL;//Then read from a file

  TCanvas *c1 = new TCanvas("c1","",200,10,800,600);

  h1->Draw("col z");

  TMarker *marker = new TMarker(-6,0,29);
  // marker->SetMarkerColor(2);
  // marker->SetMarkerSize(20);
  marker->Draw("");

The problem is that I cannot see the marker. I’ve tried playing with the size of the marker, the type, and the position. The coordinates I took from this post, as the problem looked very similar to what I want to do. But maybe I’m placing it outside of the canvas? I don’t really understand the coordinate system and I have some trouble finding documentation on it. Maybe someone has an idea what’s going wrong?

Cheers


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.26/04
_Platform: CentOS 7
_Compiler: linuxx8664gcc


Welcome to the ROOT Forum!
I’m sure @couet can help you

What are the min and max values of h1 on both axis?
can you post the plot?
or even better a small macro showing the problem?

Both axes range from 1 to 2. I can’t share the original plot here, since it contains results from an ongoing analysis, so I broke the script down to a minimal example that can reproduce the problem: macro.C (1.7 KB)

The coordinates in the TMarker constructor are in the units of the histogram’s axes, so in your case you have to use values between 1 and 2.

2 Likes

Thank you! That was it.

This method is a dummy … weird, to be checked.

{
   auto xyg = new TF2("xyg","xygaus",1,2,1,2);
   xyg->SetParameters(1,1.5,0.25,1.5,0.25);

   auto h1 = new TH2D("h1","", 30, 1, 2, 30, 1, 2);
   h1->GetXaxis()->SetTitle("variableX");
   h1->GetYaxis()->SetTitle("variableY");
   h1->FillRandom("xyg");

   gStyle->SetOptStat(0);
   auto c = new TCanvas("c","",200,10,800,600);
   c->SetRightMargin(0.15);

   h1->GetZaxis()->SetTitle("-#DeltalogL");
   h1->GetXaxis()->CenterTitle();
   h1->GetYaxis()->CenterTitle();
   h1->GetZaxis()->CenterTitle();

   int xbin = h1->GetXaxis()->GetNbins();
   int ybin = h1->GetYaxis()->GetNbins();
   double min = h1->GetMinimum();

   if (min!=0) {
      for (int i=1; i<xbin+1; i++) {
         for (int j=1; j<ybin+1; j++) {
            h1->SetBinContent(i, j, h1->GetBinContent(i, j) - min);
         }
      }
   }

   h1->Draw("colz");

   auto marker = new TMarker(1.5,1.5,29);
   marker->SetMarkerColor(kRed);
   marker->SetMarkerSize(3);
   marker->Draw();
}

Indeed, it shouldn’t work, I didn’t test or check the code of PaintMarkerNDC. I edited my post to remove that :slight_smile: and clarify what the actual solution was.

1 Like

Yes, but that needs to be revisited…