Hi ROOTers,
I’m curious why the TTree::Draw() method defaults to TH1F rather than TH1D. If the weights in the TTree span more than about 5 or 6 orders of magnitude, the float precision of TH1F leads to roundoff errors, leading to inaccurate computation of bin contents. It makes sense that the user should be careful when explicitly calling a TH1* constructor to check whether float precision is sufficient or not, but when the histogram is generated rather implicitly by some other code (here TTree::Draw()), I would think the default behaviour should be to use the safer TH1D. (Section 12.20 of the User’s Guide could also be a little more explicit about the fact that a TH1F is generated by default.)
Anyway, in case anyone else has this problem in the future, one can explicitly construct a TH1D, then pass it to TTree::Draw() as follows:
TH1D *h = new TH1D("h","h",nbins,energy_min,energy_max);
h->Sumw2();
tree->Draw("energy>>h","weight");