Errors in weighted TProfiles

Hello,
Can you please clarify if the calculation of e(j) in TProfile uses e(j)=s(j)/sqrt(GetBinEffectiveEntries(j)) instead of s(j)/sqrt(Wj)?

This is a simple macro to check the formulas from the official TProfile documentation. Here, I define a TProfile named Profile_Histogram and in bin 2 fill 3 with weight 0.5 and 6 with weight 1.0. Therefore, the corresponding values should be

E(j)=3 * 3 * 0.5+6 * 6 * 1=40.5

W(j)=0.5+1=1.5= Profile_Histogram->GetBinEntries(2)

h(j)=(3 * 0.5+6 * 1)/1.5=5= Profile_Histogram->GetBinContent(2)

s(j)=sqrt(40.5/1.5-25)=sqrt(2)=1.41421

e(j)=s(j)/W(j)

So e(j)*sqrt(W(j)) should be 1.41421 but it is not.

Instead Profile_Histogram->GetBinError(2)*sqrt(GetBinEffectiveEntries(2))=1.41421

#include <stdio.h>
void Checkingroot(){
    TProfile *Profile_Histogram=new TProfile("Profile_Histogram","Profile_Histogram",10,0,10);
    Profile_Histogram->Sumw2();
    for(int i=0;i<1;i++){
        Profile_Histogram->Fill(1.1,3,0.5);
        Profile_Histogram->Fill(1.1,6,1);
        
        
    }
    
    for(int bin=2;bin<3;bin++){
        cout<<"Profile_Histogram->GetBinContent("<<bin<<")="<<Profile_Histogram->GetBinContent(bin)<<endl;
        cout<<"Profile_Histogram->GetBinEntries("<<bin<<")="<<Profile_Histogram->GetBinEntries(bin)<<endl;

        cout<<"Profile_Histogram->GetBinEffectiveEntries("<<bin<<")="<<Profile_Histogram->GetBinEffectiveEntries(bin)<<endl;

        cout<<"Profile_Histogram->GetBinError("<<bin<<")="<<Profile_Histogram->GetBinError(bin)<<endl;

        cout<<"Profile_Histogram->GetBinError("<<bin<<")*sqrt(GetBinEntries("<<bin<<"))="<<Profile_Histogram->GetBinError(bin)*sqrt(Profile_Histogram->GetBinEntries(bin))<<endl;
 
        cout<<"Profile_Histogram->GetBinError("<<bin<<")*sqrt(GetBinEffectiveEntries("<<bin<<"))="<<Profile_Histogram->GetBinError(bin)*sqrt(Profile_Histogram->GetBinEffectiveEntries(bin))<<endl;

        cout<<"Profile_Histogram->GetBinContent("<<bin<<")*GetBinEntries("<<bin<<")="<<Profile_Histogram->GetBinContent(bin)*Profile_Histogram->GetBinEntries(bin)<<endl;

        cout<<"Profile_Histogram->GetBinContent("<<bin<<")*GetBinEffectiveEntries("<<bin<<")="<<Profile_Histogram->GetBinContent(bin)*Profile_Histogram->GetBinEffectiveEntries(bin)<<endl;
 
    }
    
    Profile_Histogram->Draw();
    
    
}

_ROOT Version:6.26/06
_Platform:MacOs macosxarm64

I would request to update the webpage as many analysis use the documentation to understand/verify their codes.

Thanks,
Aditya


TProfile *Profile_Histogram = new TProfile("Profile_Histogram", "Profile_Histogram", 10, 0., 10., "s");

Hi,

In case of a TProfile filled with weights different than 1, the number of effective entries is used for the bin error calculation. It is true the documentation is not correct for this case and we should fix it.
I have open an issue for this: [doc] TProfile bin error documentation is not correct · Issue #12592 · root-project/root · GitHub

Thank you for reporting this,

Lorenzo

1 Like

Hi Lorenzo,
Thanks for the quick action to fix it. It will help a lot of users!
Aditya

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.