Finding error of a TH1F plot

Dear All,

I have a distribution and I am trying to find the error associated with this histogram. I used h_pt ->Sumw2() before filling then I have a loop but I am getting zero for the error value.

Sample code:

double err_pt = 0;
for (ibins = 1; ibins <= h_pt->GetNbinsX();ibins++)
err_pt = pow(h_pt->GetBinError(ibins),2);
cout << err_pt << endl;

This is the distribution


maybe you need a + here

err_pt+ = pow(h_pt->GetBinError(ibins),2);

otherwise you print the squared error of the last bin that is 0.


Thank you for your response, however I tried that and got the following error:

error: expected primary-expression before ‘=’ token
err_pt+ = pow(h_pt->GetBinError(ibins),2);

err_pt += ...

Thank you Wile,

Still didn’t work. I did it another way.