ROOT Version: 6.18.04
Platform: centos7
Dear experts,
I am trying to fill histograms from a TTree, and I encounter an unsettling issue: it seems that the sum of weights of the histograms depend on the binning…
In my code, I compare the sum of weights for one histogram with 4 bins, one with 40 bins and the sum of weights computed “by hand”. It is as follows (the input file can be found there https://cernbox.cern.ch/index.php/s/abCWpBwGftN8L9F):
TFile *f = new TFile("simpletree.root", "r");
TTree *tree = (TTree*)f->Get("em");
TTreeFormula *CorrKK = new TTreeFormula("CorrKK", "CorrKK", tree);
TTreeFormula *weight = new TTreeFormula("weight", "weight", tree);
TH1F* h4 = new TH1F("","",4,-1,1);
TH1F* h40 = new TH1F("","",40,-1,1);
int i = 0;
double sumw = 0;
for(int i=0; i<tree->GetEntries(); i++){
tree->GetEntry(i);
sumw += weight->EvalInstance();
h4->Fill(CorrKK->EvalInstance(), weight->EvalInstance());
h40->Fill(CorrKK->EvalInstance(), weight->EvalInstance());
}
cout<<h4->GetSumOfWeights()<<endl;
cout<<h40->GetSumOfWeights()<<endl;
cout<<sumw<<endl;
This gives me the following output:
79460.7
79456.2
79456.4
The sum of weights computed by hand is different from those of both histograms, which are also different from one another.
Would anyone have a clue on how to explain (and solve) this behaviour?