TH1::GetEntries() after TH1::Sumw2() problem

Hello friends,
recently I ran some code like below and find something I dont understand:

    TH1F* h1 = new TH1F("h1", "h1", 100, -5., 5.);
    TH1F* h2 = new TH1F("h2", "h2", 100, -5., 5.);

    TF1* gaus1 = new TF1("gaus1", "exp(-(x-1.)*(x-1.)/2)");
    TCanvas* c1 = new TCanvas("c1", "c1");
    h1->FillRandom("gaus", 1000);
    h2->FillRandom("pol1", 10000);
    h2->Add(h1, -1.5);
    int a = h2->GetEntries();
    int b = h2->Integral();
    TCanvas* c2 = new TCanvas("c2", "c2");
    cout << a << "============" << b << endl;

The output is: “5897============8500”; if I comment out the Sumw2() lines, a exactly equals b(8500). So I am just wondering how does “TH1::GetEntries()” work after I call “Sumw2()”? Why it differs from “Integral()”. Thanks.


When TH1::Add is executed with a negative coefficient (histogram subtraction), it will internally execute TH1::ResetStats, which in turn will use TH1::GetEffectiveEntries for weighted histograms.

This makes sense. Thank you.