TH1D *hist = new TH1D("hist", "Histogram", 100, 0, 10); // Fill the histogram with some data hist->FillRandom("gaus", 10000); // Get the bin number with the highest bin content int maxBin = hist->GetMaximumBin(); // Get the maximum value in the histogram double maxValue = hist->GetBinContent(maxBin); cout << "Maximum value: " << maxValue << " at bin number " << maxBin << endl;
TH1D *hist = new TH1D("hist", "Histogram", 100, 0, 10); // Fill the histogram with some data hist->FillRandom("gaus", 10000); // Draw the histogram hist->Draw(); // Get the bin number with the highest bin content int maxBin = hist->GetMaximumBin(); // Get the x-axis value at the maximum bin double maxValue = hist->GetXaxis()->GetBinCenter(maxBin); // Draw a vertical line at the maximum bin TLine *line = new TLine(maxValue, 0, maxValue, hist->GetMaximum()); line->SetLineColor(kRed); line->SetLineWidth(2); line->Draw();In this example, we create a histogram and fill it with some random data. We then draw the histogram using the Draw function. We use the GetMaximumBin function to get the bin number with the highest bin content, and the GetXaxis function to get the x-axis of the histogram. We use the GetBinCenter function to get the x-axis value at the maximum bin. We then create a TLine object at the maximum bin and draw it on the histogram with a red color and a width of 2. The package/library used in these examples is ROOT, which is a C++ framework for data processing, analysis, and production in high-energy physics.