TH1D *histogram = new TH1D("histogram", "Histogram Title", 100, 0, 10); histogram->Fill(2.5, 3.0); histogram->Fill(4.2, 1.5); histogram->Sumw2();
TH1D *histogram = new TH1D("histogram", "Histogram Title", 100, 0, 10); histogram->Fill(2.5, 3.0); histogram->Fill(4.2, 1.5); histogram->Fill(5.0, 0.5); histogram->Fill(6.5, 2.0); histogram->Fill(8.5, 1.3); histogram->Sumw2(); double error = histogram->GetBinError(3);In this example, we create a new histogram with the name "histogram" and title "Histogram Title" with 100 bins ranging from 0 to 10. We then fill the histogram with five data points, and call the Sumw2() method to calculate the sum of squared weights. Finally, we use the GetBinError() method to get the statistical error in the third bin of the histogram. The package library used in these examples is ROOT.