Max value of Y for a histogram

Hi,

I have Drawn two histograms in the same canvas, now I need to draw a vertical line at the Maximum value of Y for both histograms. How can I do this?

thanks,

Hi @Tahany,
TLine is what you are looking for.

Stefano

Thanks @Dilicus ,

But what if I don’t know the exact values of x and y at the max! since the relation between entries at the y-axis and e-loss at the x-axis.

// assuming "h" is the pointer to your 1D histogram
Int_t b_max = h->GetMaximumBin();
Double_t x_max = h->GetBinCenter(b_max);
Double_t y_max = h->GetBinContent(b_max);
std::cout << "b = " << b_max << " x = " << x_max << " y = " << y_max << std::endl;

sorry @Wile_E_Coyote, But it still returns nothing! where might be the issue?

void tahany(){
   auto hist = new TH1D("test", "", 100, -4, 4);
   hist->FillRandom("gaus", 100000);
   hist->Draw();

   Int_t b_max = hist->GetMaximumBin();
   Double_t x_max = hist->GetBinCenter(b_max);
   Double_t y_max = hist->GetBinContent(b_max);

   auto l = new TLine(x_max,hist->GetMinimum(),x_max,y_max);
   l->Draw();
}

It works very well. Thanks a lot @couet for your effort.

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