TH1F *h = new TH1F("h", "Histogram", 10, 0, 10); // fill histogram with some data h->Fill(1); h->Fill(2); h->Fill(3); Double_t integral = h->Integral(); // calculate integral over full range cout << "Integral of histogram: " << integral << endl;
TH1F *h = new TH1F("h", "Histogram", 10, 0, 10); // fill histogram with some data h->Fill(1); h->Fill(2); h->Fill(3); Double_t integral = h->Integral(1, 3); // calculate integral over range 1 to 3 cout << "Integral of histogram from bin 1 to bin 3: " << integral << endl;The package library used for this example is ROOT. In conclusion, TH1F Integral function in C++ is a useful tool for calculating the integral of a histogram over a specified range or the full range of the histogram. It is a part of the ROOT framework.