Hi,
When I use TH1::GetSumOfWeights(), I would expect for it to return the sum over all bins of the error^2 for that bin (ie the weight for the bin). Instead of that, it seems to be returning the integral, which is only correct if I haven’t done any weighting to the histogram.
When I run the following macro:
TFile infile("simuhist.root");
TH1F* mInvm = (TH1F*)infile.Get("mInvm");
float integral=0,sumweight=0;
for(int i = 1; i <= mInvm->GetNbinsX(); i++){
integral+=mInvm->GetBinContent(i);
sumweight+=mInvm->GetBinError(i)*mInvm->GetBinError(i);
}
cout<<integral<<" "<<mInvm->Integral()<<" "<<sumweight<<" "<<mInvm->GetSumOfWeights()<<endl;
I get:
2.02611e-05 2.02611e-05 6.55266e-13 2.02611e-05
When I go to the source file, sure enough, it’s calculating the Integral:
Double_t TH1::GetSumOfWeights() const
{
// -*-*-*-*-*-*Return the sum of weights excluding under/overflows*-*-*-*-*
// ===================================================
Int_t bin,binx,biny,binz;
Double_t sum =0;
for(binz=1; binz<=fZaxis.GetNbins(); binz++) {
for(biny=1; biny<=fYaxis.GetNbins(); biny++) {
for(binx=1; binx<=fXaxis.GetNbins(); binx++) {
bin = GetBin(binx,biny,binz);
sum += GetBinContent(bin);
}
}
}
return sum;
}
I would expect it to look like:
Double_t TH1::GetSumOfWeights() const
{
// -*-*-*-*-*-*Return the sum of weights excluding under/overflows*-*-*-*-*
// ===================================================
Int_t bin,binx,biny,binz;
Double_t sum =0;
for(binz=1; binz<=fZaxis.GetNbins(); binz++) {
for(biny=1; biny<=fYaxis.GetNbins(); biny++) {
for(binx=1; binx<=fXaxis.GetNbins(); binx++) {
bin = GetBin(binx,biny,binz);
sum += GetBinError(bin) * GetBinError(bin);
}
}
}
return sum;
}
If I’m misunderstanding what it should be doing, it would be nice to have a function that does what I was expecting, that is, returning the error on the integral of the histogram.