TH2D *histogram = new TH2D("h1","Example Histogram;X Axis;Y Axis",10,0,10,10,0,10); // Create a histogram with 10 bins for both X and Y axis histogram->Fill(5,5,10); // Fill the (5,5) bin with a value of 10 double binContent = histogram->GetBinContent(5,5); // Retrieve the content of the (5,5) bin cout << binContent << endl; // Output the content of the (5,5) bin
TH2D *histogram = new TH2D("h2","Example Histogram;X Axis;Y Axis",5,0,5,5,0,5); // Create a histogram with 5 bins for both X and Y axis for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ histogram->SetBinContent(i+1,j+1,(i*j)); } } // Fill each bin with the product of the row and column index int totalEntries = histogram->GetEntries(); // Retrieve the total number of entries in the histogram cout << totalEntries << endl; // Output the total number of entries in the histogramThis code creates a 5x5 histogram and fills each bin with the product of the row and column index. It then retrieves the total number of entries in the histogram and outputs it to the console. Both of these examples use the GetBinContent method to retrieve the content of specific bins in the histogram. The ROOT package library is used to create and manipulate the histograms.