Programming Language: C++ (Cpp)

Class/Type: TH1D

Method/Function: Sumw2

Examples at hotexamples.com: 30

TH1D Sumw2 is a method used in the ROOT package library for calculating the sum of squared weights of a histogram. It is useful when calculating statistical uncertainties in histograms.

**Example 1:**

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 two data points: (2.5, 3.0) and (4.2, 1.5). Finally, we call the Sumw2() method to calculate the sum of squared weights.

**Example 2:**

TH1D *histogram = new TH1D("histogram", "Histogram Title", 100, 0, 10); histogram->Fill(2.5, 3.0); histogram->Fill(4.2, 1.5); histogram->Sumw2();

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 two data points: (2.5, 3.0) and (4.2, 1.5). Finally, we call the Sumw2() method to calculate the sum of squared weights.

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.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods