Small wish for TProfile::GetObjectInfo()

Dear experts,

sometimes it would be very helpful to see the number of entries per bin and its error of a profile in the small info bar below he canvas. Also, the integral as given by THistPainer::GetObjectInfo() is not really needed here.

Let me suggest the following code:

char* TProfile::GetObjectInfo(Int_t px, Int_t py) const {
   //   Redefines TObject::GetObjectInfo.
   //   Displays the profile info (bin number, contents, eroor, entries per bin
   //   corresponding to cursor position px,py
   //
   if (!gPad) return (char*)"";
   static char info[64]
   Double_t x  = gPad->PadtoX(gPad->AbsPixeltoX(px));
   Double_t y  = gPad->PadtoY(gPad->AbsPixeltoY(py));
   Int_t binx   = GetXaxis()->FindFixBin(x);
   sprintf(info,"(x=%g, y=%g, binx=%d, binc=%g, bine=%g, binn=%d)", x, y, binx, GetBinContent(binx), GetBinError(binx), GetBinEntries(binx));
   return info;
}

For 2d profiles this could be done in a very similar way. What do you think?

Cheers,
Oliver

Hi Oliver,

Very good suggestion. I have implemented it in the CVS version.
Probably the same fix should also be done for TProfile2D

Rene

Hello René, many thanks.

Right. What about this? (sorry, didn’t test it; just cut&paste from the web page)

char* TProfile2D::GetObjectInfo(Int_t px, Int_t py) const {
   //   Redefines TObject::GetObjectInfo.
   //   Displays the profile info (bin number, contents, error, entries per bin
   //   corresponding to cursor position px,py
   //
   if (!gPad) return (char*)"";
   static char info[64];
   Double_t x  = gPad->PadtoX(gPad->AbsPixeltoX(px));
   Double_t y  = gPad->PadtoY(gPad->AbsPixeltoY(py)); 
   const char *drawOption = GetDrawOption();
   Double_t xmin, xmax, uxmin,uxmax;
   Double_t ymin, ymax, uymin,uymax;
   Double_t x1 = gPad->PadtoX(gPad->AbsPixeltoX(px+1));

   if (gPad->GetView() || strncmp(drawOption,"cont",4) == 0
                          || strncmp(drawOption,"CONT",4) == 0) {
         uxmin=gPad->GetUxmin();
         uxmax=gPad->GetUxmax();
         xmin = fXaxis->GetBinLowEdge(fXaxis->GetFirst());
         xmax = fXaxis->GetBinUpEdge(fXaxis->GetLast());
         x = xmin +(xmax-xmin)*(x-uxmin)/(uxmax-uxmin);
         uymin=gPad->GetUymin();
         uymax=gPad->GetUymax();
         ymin = fYaxis->GetBinLowEdge(fYaxis->GetFirst());
         ymax = fYaxis->GetBinUpEdge(fYaxis->GetLast());
         y = ymin +(ymax-ymin)*(y-uymin)/(uymax-uymin);
      }

   Int_t binx,biny,binmin,binx1;
   if (gPad->IsVertical()) {
      binx   = fXaxis->FindFixBin(x);
   } else {
      x1 = gPad->PadtoY(gPad->AbsPixeltoY(py+1));
      binx   = fXaxis->FindFixBin(y);
   }
   binmin = fXaxis->GetFirst();
   binx1  = fXaxis->FindFixBin(x1);
   biny = fYaxis->FindFixBin(y);

   sprintf(info,"(x=%g, y=%g, binx=%d, biny=%d, binc=%g, bine=%g, binn=%d)", x, y, binx, biny, GetBinContent(binx, biny), GetBinError(binx, biny), GetBinEntries(GetBin(binx, biny)));
   return info;
} 

Cheers,
Oliver