#include#include void getMaximumExample() { // create a 1D histogram with 10 bins and fill it with values TH1D* histogram = new TH1D("histogram", "My Histogram", 10, 0, 10); for (int i = 1; i <= 10; i++) { histogram->Fill(i); } // retrieve the maximum value and its bin number double maxVal = histogram->GetMaximum(); int maxBin = histogram->GetMaximumBin(); std::cout << "Maximum value: " << maxVal << std::endl; std::cout << "Bin number: " << maxBin << std::endl; // clean up delete histogram; }
#includeIn this example, we again create a 1D histogram with 10 bins and fill it with values from 1 to 10. However, we then use the GetMaximum function with a specific range of 2 to 8 to retrieve the maximum value and its bin number within that range. This example also uses the ROOT framework/library.#include void getMaximumExample() { // create a 1D histogram with 10 bins and fill it with values TH1D* histogram = new TH1D("histogram", "My Histogram", 10, 0, 10); for (int i = 1; i <= 10; i++) { histogram->Fill(i); } // retrieve the maximum value and its bin number for a specific range double maxVal = histogram->GetMaximum(2.0, 8.0); int maxBin = histogram->GetMaximumBin(2.0, 8.0); std::cout << "Maximum value (in range 2-8): " << maxVal << std::endl; std::cout << "Bin number (in range 2-8): " << maxBin << std::endl; // clean up delete histogram; }